| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @subpackage com_config 5 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 9 // No direct access. 10 defined('_JEXEC') or die; 11 12 jimport('joomla.application.component.modelform'); 13 14 /** 15 * @package Joomla.Administrator 16 * @subpackage com_config 17 */ 18 class ConfigModelComponent extends JModelForm 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 * @since 1.6 27 */ 28 protected function populateState() 29 { 30 // Set the component (option) we are dealing with. 31 $component = JRequest::getCmd('component'); 32 $this->setState('component.option', $component); 33 34 // Set an alternative path for the configuration file. 35 if ($path = JRequest::getString('path')) { 36 $path = JPath::clean(JPATH_SITE . '/' . $path); 37 JPath::check($path); 38 $this->setState('component.path', $path); 39 } 40 } 41 42 /** 43 * Method to get a form object. 44 * 45 * @param array $data Data for the form. 46 * @param boolean $loadData True if the form is to load its own data (default case), false if not. 47 * 48 * @return mixed A JForm object on success, false on failure 49 * @since 1.6 50 */ 51 public function getForm($data = array(), $loadData = true) 52 { 53 if ($path = $this->getState('component.path')) { 54 // Add the search path for the admin component config.xml file. 55 JForm::addFormPath($path); 56 } 57 else { 58 // Add the search path for the admin component config.xml file. 59 JForm::addFormPath(JPATH_ADMINISTRATOR.'/components/'.$this->getState('component.option')); 60 } 61 62 // Get the form. 63 $form = $this->loadForm( 64 'com_config.component', 65 'config', 66 array('control' => 'jform', 'load_data' => $loadData), 67 false, 68 '/config' 69 ); 70 71 if (empty($form)) { 72 return false; 73 } 74 75 return $form; 76 } 77 78 /** 79 * Get the component information. 80 * 81 * @return object 82 * @since 1.6 83 */ 84 function getComponent() 85 { 86 // Initialise variables. 87 $option = $this->getState('component.option'); 88 89 // Load common and local language files. 90 $lang = JFactory::getLanguage(); 91 $lang->load($option, JPATH_BASE, null, false, false) 92 || $lang->load($option, JPATH_BASE . "/components/$option", null, false, false) 93 || $lang->load($option, JPATH_BASE, $lang->getDefault(), false, false) 94 || $lang->load($option, JPATH_BASE . "/components/$option", $lang->getDefault(), false, false); 95 96 $result = JComponentHelper::getComponent($option); 97 98 return $result; 99 } 100 101 /** 102 * Method to save the configuration data. 103 * 104 * @param array An array containing all global config data. 105 * 106 * @return bool True on success, false on failure. 107 * @since 1.6 108 */ 109 public function save($data) 110 { 111 $table = JTable::getInstance('extension'); 112 113 // Save the rules. 114 if (isset($data['params']) && isset($data['params']['rules'])) { 115 $rules = new JAccessRules($data['params']['rules']); 116 $asset = JTable::getInstance('asset'); 117 118 if (!$asset->loadByName($data['option'])) { 119 $root = JTable::getInstance('asset'); 120 $root->loadByName('root.1'); 121 $asset->name = $data['option']; 122 $asset->title = $data['option']; 123 $asset->setLocation($root->id, 'last-child'); 124 } 125 $asset->rules = (string) $rules; 126 127 if (!$asset->check() || !$asset->store()) { 128 $this->setError($asset->getError()); 129 return false; 130 } 131 132 // We don't need this anymore 133 unset($data['option']); 134 unset($data['params']['rules']); 135 } 136 137 // Load the previous Data 138 if (!$table->load($data['id'])) { 139 $this->setError($table->getError()); 140 return false; 141 } 142 143 unset($data['id']); 144 145 // Bind the data. 146 if (!$table->bind($data)) { 147 $this->setError($table->getError()); 148 return false; 149 } 150 151 // Check the data. 152 if (!$table->check()) { 153 $this->setError($table->getError()); 154 return false; 155 } 156 157 // Store the data. 158 if (!$table->store()) { 159 $this->setError($table->getError()); 160 return false; 161 } 162 163 // Clean the cache. 164 $this->cleanCache('_system', 0); 165 $this->cleanCache('_system', 1); 166 167 return true; 168 } 169 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |