Public Member Functions | |
save () | |
load () | |
Protected Member Functions | |
_validate () | |
_getScope () | |
_getConfig ($full=true) |
Definition at line 35 of file Data.php.
_getConfig | ( | $ | full = true |
) | [protected] |
Get config data where key = path
Definition at line 228 of file Data.php.
00229 { 00230 $configDataCollection = Mage::getModel('core/config_data') 00231 ->getCollection() 00232 ->addScopeFilter($this->getScope(), $this->getScopeId(), $this->getSection()); 00233 00234 $config = array(); 00235 foreach ($configDataCollection as $data) { 00236 if ($full) { 00237 $config[$data->getPath()] = array( 00238 'path' => $data->getPath(), 00239 'value' => $data->getValue(), 00240 'config_id' => $data->getConfigId() 00241 ); 00242 } 00243 else { 00244 $config[$data->getPath()] = $data->getValue(); 00245 } 00246 } 00247 return $config; 00248 }
_getScope | ( | ) | [protected] |
Get scope name and scopeId
Definition at line 207 of file Data.php.
00208 { 00209 if ($this->getStore()) { 00210 $scope = 'stores'; 00211 $scopeId = (int)Mage::getConfig()->getNode('stores/' . $this->getStore() . '/system/store/id'); 00212 } elseif ($this->getWebsite()) { 00213 $scope = 'websites'; 00214 $scopeId = (int)Mage::getConfig()->getNode('websites/' . $this->getWebsite() . '/system/website/id'); 00215 } else { 00216 $scope = 'default'; 00217 $scopeId = 0; 00218 } 00219 $this->setScope($scope); 00220 $this->setScopeId($scopeId); 00221 }
_validate | ( | ) | [protected] |
Validate isset required parametrs
Definition at line 187 of file Data.php.
00188 { 00189 if (is_null($this->getSection())) { 00190 $this->setSection(''); 00191 // Mage::throwException(Mage::helper('adminhtml')->__('Invalid section value')); 00192 } 00193 if (is_null($this->getWebsite())) { 00194 $this->setWebsite(''); 00195 // Mage::throwException(Mage::helper('adminhtml')->__('Invalid website value')); 00196 } 00197 if (is_null($this->getStore())) { 00198 $this->setStore(''); 00199 // Mage::throwException(Mage::helper('adminhtml')->__('Invalid store value')); 00200 } 00201 }
load | ( | ) |
Load config data for section
Definition at line 175 of file Data.php.
00176 { 00177 $this->_validate(); 00178 $this->_getScope(); 00179 00180 return $this->_getConfig(false); 00181 }
save | ( | ) |
Save config section Require set: section, website, store and groups
Map field names if they were cloned
Get field backend model
Delete config data if inherit
Definition at line 43 of file Data.php.
00044 { 00045 $this->_validate(); 00046 $this->_getScope(); 00047 00048 $section = $this->getSection(); 00049 $website = $this->getWebsite(); 00050 $store = $this->getStore(); 00051 $groups = $this->getGroups(); 00052 $scope = $this->getScope(); 00053 $scopeId = $this->getScopeId(); 00054 00055 if (empty($groups)) { 00056 return $this; 00057 } 00058 00059 $sections = Mage::getModel('adminhtml/config')->getSections(); 00060 /* @var $sections Mage_Core_Model_Config_Element */ 00061 00062 $oldConfig = $this->_getConfig(true); 00063 00064 $deleteTransaction = Mage::getModel('core/resource_transaction'); 00065 /* @var $deleteTransaction Mage_Core_Model_Resource_Transaction */ 00066 $saveTransaction = Mage::getModel('core/resource_transaction'); 00067 /* @var $saveTransaction Mage_Core_Model_Resource_Transaction */ 00068 00069 foreach ($groups as $group => $groupData) { 00070 00071 /** 00072 * Map field names if they were cloned 00073 */ 00074 $groupConfig = $sections->descend($section.'/groups/'.$group); 00075 00076 if ($clonedFields = !empty($groupConfig->clone_fields)) { 00077 if ($groupConfig->clone_model) { 00078 $cloneModel = Mage::getModel((string)$groupConfig->clone_model); 00079 } else { 00080 Mage::throwException('Config form fieldset clone model required to be able to clone fields'); 00081 } 00082 $mappedFields = array(); 00083 $fieldsConfig = $sections->descend($section.'/groups/'.$group.'/fields'); 00084 00085 if ($fieldsConfig->hasChildren()) { 00086 foreach ($fieldsConfig->children() as $field => $node) { 00087 foreach ($cloneModel->getPrefixes() as $prefix) { 00088 $mappedFields[$prefix['field'].(string)$field] = (string)$field; 00089 } 00090 } 00091 } 00092 } 00093 00094 foreach ($groupData['fields'] as $field => $fieldData) { 00095 00096 /** 00097 * Get field backend model 00098 */ 00099 $backendClass = $sections->descend($section.'/groups/'.$group.'/fields/'.$field.'/backend_model'); 00100 if (!$backendClass && $clonedFields && isset($mappedFields[$field])) { 00101 $backendClass = $sections->descend($section.'/groups/'.$group.'/fields/'.$mappedFields[$field].'/backend_model'); 00102 } 00103 if (!$backendClass) { 00104 $backendClass = 'core/config_data'; 00105 } 00106 00107 $dataObject = Mage::getModel($backendClass); 00108 if (!$dataObject instanceof Mage_Core_Model_Config_Data) { 00109 Mage::throwException('Invalid config field backend model: '.$backendClass); 00110 } 00111 /* @var $dataObject Mage_Core_Model_Config_Data */ 00112 00113 $fieldConfig = $sections->descend($section.'/groups/'.$group.'/fields/'.$field); 00114 if (!$fieldConfig && $clonedFields && isset($mappedFields[$field])) { 00115 $fieldConfig = $sections->descend($section.'/groups/'.$group.'/fields/'.$mappedFields[$field]); 00116 } 00117 00118 $dataObject 00119 ->setField($field) 00120 ->setGroups($groups) 00121 ->setGroupId($group) 00122 ->setStoreCode($store) 00123 ->setWebsiteCode($website) 00124 ->setScope($scope) 00125 ->setScopeId($scopeId) 00126 ->setFieldConfig($fieldConfig) 00127 ; 00128 00129 if (!isset($fieldData['value'])) { 00130 $fieldData['value'] = null; 00131 } 00132 00133 /*if (is_array($fieldData['value'])) { 00134 $fieldData['value'] = join(',', $fieldData['value']); 00135 }*/ 00136 00137 $path = $section.'/'.$group.'/'.$field; 00138 $inherit = !empty($fieldData['inherit']); 00139 00140 $dataObject->setPath($path) 00141 ->setValue($fieldData['value']); 00142 00143 if (isset($oldConfig[$path])) { 00144 $dataObject->setConfigId($oldConfig[$path]['config_id']); 00145 00146 /** 00147 * Delete config data if inherit 00148 */ 00149 if (!$inherit) { 00150 $saveTransaction->addObject($dataObject); 00151 } 00152 else { 00153 $deleteTransaction->addObject($dataObject); 00154 } 00155 } 00156 elseif (!$inherit) { 00157 $dataObject->unsConfigId(); 00158 $saveTransaction->addObject($dataObject); 00159 } 00160 } 00161 00162 } 00163 00164 $deleteTransaction->delete(); 00165 $saveTransaction->save(); 00166 00167 return $this; 00168 }