Source for file component.php

Documentation is available at component.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_config
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2012 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.  * Model for component configuration
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_config
  17.  * @since       3.2
  18.  */
  19. {
  20.     /**
  21.      * Method to auto-populate the model state.
  22.      *
  23.      * Note. Calling getState in this method will result in recursion.
  24.      *
  25.      * @return    void 
  26.      *
  27.      * @since    3.2
  28.      */
  29.     protected function populateState()
  30.     {
  31.         $input JFactory::getApplication()->input;
  32.  
  33.         // Set the component (option) we are dealing with.
  34.         $component $input->get('component');
  35.         $state $this->loadState();
  36.         $state->set('component.option'$component);
  37.  
  38.         // Set an alternative path for the configuration file.
  39.         if ($path $input->getString('path'))
  40.         {
  41.             $path JPath::clean(JPATH_SITE '/' $path);
  42.             JPath::check($path);
  43.             $state->set('component.path'$path);
  44.         }
  45.  
  46.         $this->setState($state);
  47.     }
  48.  
  49.     /**
  50.      * Method to get a form object.
  51.      *
  52.      * @param   array    $data      Data for the form.
  53.      * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
  54.      *
  55.      * @return  mixed  A JForm object on success, false on failure
  56.      *
  57.      * @since    3.2
  58.      */
  59.     public function getForm($data array()$loadData true)
  60.     {
  61.         $state $this->getState();
  62.  
  63.         if ($path $state->get('component.path'))
  64.         {
  65.             // Add the search path for the admin component config.xml file.
  66.             JForm::addFormPath($path);
  67.         }
  68.         else
  69.         {
  70.             // Add the search path for the admin component config.xml file.
  71.             JForm::addFormPath(JPATH_ADMINISTRATOR '/components/' $state->get('component.option'));
  72.         }
  73.  
  74.         // Get the form.
  75.         $form $this->loadForm(
  76.             'com_config.component',
  77.             'config',
  78.             array('control' => 'jform''load_data' => $loadData),
  79.             false,
  80.             '/config'
  81.         );
  82.  
  83.         if (empty($form))
  84.         {
  85.  
  86.             return false;
  87.         }
  88.  
  89.         return $form;
  90.     }
  91.  
  92.     /**
  93.      * Get the component information.
  94.      *
  95.      * @return    object 
  96.      *
  97.      * @since    3.2
  98.      */
  99.     public function getComponent()
  100.     {
  101.         $state $this->getState();
  102.         $option $state->get('component.option');
  103.  
  104.         // Load common and local language files.
  105.         $lang JFactory::getLanguage();
  106.             $lang->load($optionJPATH_BASEnullfalsetrue)
  107.         ||    $lang->load($optionJPATH_BASE "/components/$option"nullfalsetrue);
  108.  
  109.         $result JComponentHelper::getComponent($option);
  110.  
  111.         return $result;
  112.     }
  113.  
  114.     /**
  115.      * Method to save the configuration data.
  116.      *
  117.      * @param   array  $data  An array containing all global config data.
  118.      *
  119.      * @return  boolean  True on success, false on failure.
  120.      *
  121.      * @since    3.2
  122.      * @throws  RuntimeException
  123.      */
  124.     public function save($data)
  125.     {
  126.         $table    JTable::getInstance('extension');
  127.  
  128.         // Save the rules.
  129.         if (isset($data['params']&& isset($data['params']['rules']))
  130.         {
  131.             $rules new JAccessRules($data['params']['rules']);
  132.             $asset JTable::getInstance('asset');
  133.  
  134.             if (!$asset->loadByName($data['option']))
  135.             {
  136.                 $root JTable::getInstance('asset');
  137.                 $root->loadByName('root.1');
  138.                 $asset->name $data['option'];
  139.                 $asset->title $data['option'];
  140.                 $asset->setLocation($root->id'last-child');
  141.             }
  142.  
  143.             $asset->rules = (string) $rules;
  144.  
  145.             if (!$asset->check(|| !$asset->store())
  146.             {
  147.                 throw new RuntimeException($table->getError());
  148.             }
  149.  
  150.             // We don't need this anymore
  151.             unset($data['option']);
  152.             unset($data['params']['rules']);
  153.         }
  154.  
  155.         // Load the previous Data
  156.         if (!$table->load($data['id']))
  157.         {
  158.             throw new RuntimeException($table->getError());
  159.         }
  160.  
  161.         unset($data['id']);
  162.  
  163.         // Bind the data.
  164.         if (!$table->bind($data))
  165.         {
  166.             throw new RuntimeException($table->getError());
  167.         }
  168.  
  169.         // Check the data.
  170.         if (!$table->check())
  171.         {
  172.             throw new RuntimeException($table->getError());
  173.         }
  174.  
  175.         // Store the data.
  176.         if (!$table->store())
  177.         {
  178.             throw new RuntimeException($table->getError());
  179.         }
  180.  
  181.         // Clean the component cache.
  182.         $this->cleanCache('_system');
  183.  
  184.         return true;
  185.     }
  186. }

Documentation generated on Tue, 19 Nov 2013 14:56:15 +0100 by phpDocumentor 1.4.3