Source for file language.php

Documentation is available at language.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_languages
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Languages Component Language Model
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_languages
  17.  * @since       1.5
  18.  */
  19. {
  20.     /**
  21.      * Override to get the table
  22.      *
  23.      * @return  JTable 
  24.      * @since   1.6
  25.      */
  26.     public function getTable($name ''$prefix ''$options array())
  27.     {
  28.         return JTable::getInstance('Language');
  29.     }
  30.  
  31.     /**
  32.      * Method to auto-populate the model state.
  33.      *
  34.      * Note. Calling getState in this method will result in recursion.
  35.      *
  36.      * @return  void 
  37.      * @since   1.6
  38.      */
  39.     protected function populateState()
  40.     {
  41.         $app    JFactory::getApplication('administrator');
  42.         $params JComponentHelper::getParams('com_languages');
  43.  
  44.         // Load the User state.
  45.         $langId $app->input->getInt('lang_id');
  46.         $this->setState('language.id'$langId);
  47.  
  48.         // Load the parameters.
  49.         $this->setState('params'$params);
  50.     }
  51.  
  52.     /**
  53.      * Method to get a member item.
  54.      *
  55.      * @param   integer    The id of the member to get.
  56.      *
  57.      * @return  mixed  User data object on success, false on failure.
  58.      * @since   1.0
  59.      */
  60.     public function getItem($langId null)
  61.     {
  62.         $langId    (!empty($langId)) $langId : (int) $this->getState('language.id');
  63.         $false  false;
  64.  
  65.         // Get a member row instance.
  66.         $table $this->getTable();
  67.  
  68.         // Attempt to load the row.
  69.         $return $table->load($langId);
  70.  
  71.         // Check for a table object error.
  72.         if ($return === false && $table->getError())
  73.         {
  74.             $this->setError($table->getError());
  75.             return $false;
  76.         }
  77.  
  78.         $properties $table->getProperties(1);
  79.         $value JArrayHelper::toObject($properties'JObject');
  80.  
  81.         return $value;
  82.     }
  83.  
  84.     /**
  85.      * Method to get the group form.
  86.      *
  87.      * @param   array  $data        Data for the form.
  88.      * @param   boolean    $loadData    True if the form is to load its own data (default case), false if not.
  89.      *
  90.      * @return  mixed  A JForm object on success, false on failure
  91.      * @since   1.6
  92.      */
  93.     public function getForm($data array()$loadData true)
  94.     {
  95.         // Get the form.
  96.         $form $this->loadForm('com_languages.language''language'array('control' => 'jform''load_data' => $loadData));
  97.         if (empty($form))
  98.         {
  99.             return false;
  100.         }
  101.  
  102.         return $form;
  103.     }
  104.  
  105.     /**
  106.      * Method to get the data that should be injected in the form.
  107.      *
  108.      * @return  mixed  The data for the form.
  109.      * @since   1.6
  110.      */
  111.     protected function loadFormData()
  112.     {
  113.         // Check the session for previously entered form data.
  114.         $data JFactory::getApplication()->getUserState('com_languages.edit.language.data'array());
  115.  
  116.         if (empty($data))
  117.         {
  118.             $data $this->getItem();
  119.         }
  120.  
  121.         $this->preprocessData('com_languages.language'$data);
  122.  
  123.         return $data;
  124.     }
  125.  
  126.     /**
  127.      * Method to save the form data.
  128.      *
  129.      * @param   array  The form data.
  130.      *
  131.      * @return  boolean  True on success.
  132.      * @since   1.6
  133.      */
  134.     public function save($data)
  135.     {
  136.         $langId    = (int) $this->getState('language.id');
  137.         $isNew    true;
  138.  
  139.         $dispatcher JEventDispatcher::getInstance();
  140.         JPluginHelper::importPlugin('extension');
  141.  
  142.         $table $this->getTable();
  143.  
  144.         // Load the row if saving an existing item.
  145.         if ($langId 0)
  146.         {
  147.             $table->load($langId);
  148.             $isNew false;
  149.         }
  150.  
  151.         // Bind the data
  152.         if (!$table->bind($data))
  153.         {
  154.             $this->setError($table->getError());
  155.             return false;
  156.         }
  157.  
  158.         // Check the data
  159.         if (!$table->check())
  160.         {
  161.             $this->setError($table->getError());
  162.             return false;
  163.         }
  164.  
  165.         // Trigger the onExtensionBeforeSave event.
  166.         $result $dispatcher->trigger('onExtensionBeforeSave'array('com_languages.language'&$table$isNew));
  167.  
  168.         // Check the event responses.
  169.         if (in_array(false$resulttrue))
  170.         {
  171.             $this->setError($table->getError());
  172.             return false;
  173.         }
  174.  
  175.         // Store the data
  176.         if (!$table->store())
  177.         {
  178.             $this->setError($table->getError());
  179.             return false;
  180.         }
  181.  
  182.         // Trigger the onExtensionAfterSave event.
  183.         $dispatcher->trigger('onExtensionAfterSave'array('com_languages.language'&$table$isNew));
  184.  
  185.         $this->setState('language.id'$table->lang_id);
  186.  
  187.         // Clean the cache.
  188.         $this->cleanCache();
  189.  
  190.         return true;
  191.     }
  192.  
  193.     /**
  194.      * Custom clean cache method
  195.      *
  196.      * @since   1.6
  197.      */
  198.     protected function cleanCache($group null$client_id 0)
  199.     {
  200.         parent::cleanCache('_system');
  201.         parent::cleanCache('com_languages');
  202.     }
  203. }

Documentation generated on Tue, 19 Nov 2013 15:06:30 +0100 by phpDocumentor 1.4.3