Mage_Adminhtml_System_ConfigController Class Reference

Inheritance diagram for Mage_Adminhtml_System_ConfigController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 indexAction ()
 editAction ()
 saveAction ()
 stateAction ()
 exportTableratesAction ()

Protected Member Functions

 _construct ()
 _saveSection ()
 _saveAdvanced ()
 _isAllowed ()
 _isSectionAllowed ($section)
 _saveState ($configState=array())


Detailed Description

Definition at line 35 of file ConfigController.php.


Member Function Documentation

_construct (  )  [protected]

Enter description here...

Reimplemented from Mage_Core_Controller_Varien_Action.

Definition at line 42 of file ConfigController.php.

00043     {
00044         $this->setFlag('index', 'no-preDispatch', true);
00045         return parent::_construct();
00046     }

_isAllowed (  )  [protected]

Enter description here...

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 273 of file ConfigController.php.

00274     {
00275         return Mage::getSingleton('admin/session')->isAllowed('system/config');
00276     }

_isSectionAllowed ( section  )  [protected]

Check if specified section allowed in ACL

Will forward to deniedAction(), if not allowed.

Parameters:
string $section
Returns:
bool

Definition at line 286 of file ConfigController.php.

00287     {
00288         try {
00289             $session = Mage::getSingleton('admin/session');
00290             $resourceLookup = "admin/system/config/{$section}";
00291             $resourceId = $session->getData('acl')->get($resourceLookup)->getResourceId();
00292             if (!$session->isAllowed($resourceId)) {
00293                 throw new Exception('');
00294             }
00295             return true;
00296         }
00297         catch (Exception $e) {
00298             $this->_forward('denied');
00299             return false;
00300         }
00301     }

_saveAdvanced (  )  [protected]

Description goes here...

Definition at line 181 of file ConfigController.php.

00182     {
00183         Mage::app()->cleanCache(
00184             array(
00185                 'layout',
00186                 Mage_Core_Model_Layout_Update::LAYOUT_GENERAL_CACHE_TAG
00187             )
00188         );
00189     }

_saveSection (  )  [protected]

Custom save logic for section

Definition at line 170 of file ConfigController.php.

00171     {
00172         $method = '_save' . uc_words($this->getRequest()->getParam('section'), '');
00173         if (method_exists($this, $method)) {
00174             $this->$method();
00175         }
00176     }

_saveState ( configState = array()  )  [protected]

saving state of config field sets

Parameters:
array $configState
Returns:
bool

Definition at line 309 of file ConfigController.php.

00310     {
00311         $adminUser = Mage::getSingleton('admin/session')->getUser();
00312         if (is_array($configState)) {
00313             $extra = $adminUser->getExtra();
00314             if (!is_array($extra)) {
00315                 $extra = array();
00316             }
00317             if (!isset($extra['configState'])) {
00318                 $extra['configState'] = array();
00319             }
00320             foreach ($configState as $fieldset => $state) {
00321                 $extra['configState'][$fieldset] = $state;
00322             }
00323             $adminUser->saveExtra($extra);
00324         }
00325 
00326         return true;
00327     }

editAction (  ) 

Enter description here...

Definition at line 61 of file ConfigController.php.

00062     {
00063         $current = $this->getRequest()->getParam('section');
00064         $website = $this->getRequest()->getParam('website');
00065         $store   = $this->getRequest()->getParam('store');
00066 
00067         $configFields = Mage::getSingleton('adminhtml/config');
00068 
00069 
00070         $sections     = $configFields->getSections($current);
00071         $section      = $sections->$current;
00072         $hasChildren  = $configFields->hasChildren($section, $website, $store);
00073         if (!$hasChildren && $current) {
00074             $this->_redirect('*/*/', array('website'=>$website, 'store'=>$store));
00075         }
00076 
00077         $this->loadLayout();
00078 
00079         $this->_setActiveMenu('system/config');
00080 
00081        $this->_addBreadcrumb(Mage::helper('adminhtml')->__('System'), Mage::helper('adminhtml')->__('System'), $this->getUrl('*/system'));
00082 
00083         $this->getLayout()->getBlock('left')
00084             ->append($this->getLayout()->createBlock('adminhtml/system_config_tabs')->initTabs());
00085 
00086         if ($this->_isSectionAllowed($this->getRequest()->getParam('section'))) {
00087             $this->_addContent($this->getLayout()->createBlock('adminhtml/system_config_edit')->initForm());
00088 
00089             $this->_addJs($this->getLayout()->createBlock('adminhtml/template')->setTemplate('system/shipping/ups.phtml'));
00090             $this->_addJs($this->getLayout()->createBlock('adminhtml/template')->setTemplate('system/config/js.phtml'));
00091             $this->_addJs($this->getLayout()->createBlock('adminhtml/template')->setTemplate('system/shipping/applicable_country.phtml'));
00092 
00093             $this->renderLayout();
00094         }
00095     }

exportTableratesAction (  ) 

Enter description here...

Definition at line 213 of file ConfigController.php.

00214     {
00215         $websiteModel = Mage::app()->getWebsite($this->getRequest()->getParam('website'));
00216 
00217         if ($this->getRequest()->getParam('conditionName')) {
00218             $conditionName = $this->getRequest()->getParam('conditionName');
00219         } else {
00220             $conditionName = $websiteModel->getConfig('carriers/tablerate/condition_name');
00221         }
00222 
00223         $tableratesCollection = Mage::getResourceModel('shipping/carrier_tablerate_collection');
00224         /* @var $tableratesCollection Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection */
00225         $tableratesCollection->setConditionFilter($conditionName);
00226         $tableratesCollection->setWebsiteFilter($websiteModel->getId());
00227         $tableratesCollection->load();
00228 
00229         $csv = '';
00230 
00231         $conditionName = Mage::getModel('shipping/carrier_tablerate')->getCode('condition_name_short', $conditionName);
00232 
00233         $csvHeader = array('"'.Mage::helper('adminhtml')->__('Country').'"', '"'.Mage::helper('adminhtml')->__('Region/State').'"', '"'.Mage::helper('adminhtml')->__('Zip/Postal Code').'"', '"'.$conditionName.'"', '"'.Mage::helper('adminhtml')->__('Shipping Price').'"');
00234         $csv .= implode(',', $csvHeader)."\n";
00235 
00236         foreach ($tableratesCollection->getItems() as $item) {
00237             if ($item->getData('dest_country') == '') {
00238                 $country = '*';
00239             } else {
00240                 $country = $item->getData('dest_country');
00241             }
00242             if ($item->getData('dest_region') == '') {
00243                 $region = '*';
00244             } else {
00245                 $region = $item->getData('dest_region');
00246             }
00247             if ($item->getData('dest_zip') == '') {
00248                 $zip = '*';
00249             } else {
00250                 $zip = $item->getData('dest_zip');
00251             }
00252 
00253             $csvData = array($country, $region, $zip, $item->getData('condition_value'), $item->getData('price'));
00254             foreach ($csvData as $cell) {
00255                 $cell = '"'.str_replace('"', '""', $cell).'"';
00256             }
00257             $csv .= implode(',', $csvData)."\n";
00258         }
00259 
00260         header('Pragma: public');
00261         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
00262 
00263         header("Content-type: application/octet-stream");
00264         header("Content-disposition: attachment; filename=tablerates.csv");
00265         echo $csv;
00266         exit;
00267     }

indexAction (  ) 

Enter description here...

Definition at line 52 of file ConfigController.php.

00053     {
00054         $this->_forward('edit');
00055     }

saveAction (  ) 

Enter description here...

Carefully merge $_FILES and $_POST information None of '+=' or 'array_merge_recursive' can do this correct

Definition at line 101 of file ConfigController.php.

00102     {
00103         $session = Mage::getSingleton('adminhtml/session');
00104         /* @var $session Mage_Adminhtml_Model_Session */
00105 
00106         $groups = $this->getRequest()->getPost('groups');
00107 
00108 
00109         if (isset($_FILES['groups']['name']) && is_array($_FILES['groups']['name'])) {
00110             /**
00111              * Carefully merge $_FILES and $_POST information
00112              * None of '+=' or 'array_merge_recursive' can do this correct
00113              */
00114             foreach($_FILES['groups']['name'] as $groupName => $group) {
00115                 if (is_array($group)) {
00116                     foreach ($group['fields'] as $fieldName => $field) {
00117                         if (!empty($field['value'])) {
00118                             $groups[$groupName]['fields'][$fieldName] = array('value' => $field['value']);
00119                         }
00120                     }
00121                 }
00122             }
00123         }
00124 
00125         try {
00126             if (!$this->_isSectionAllowed($this->getRequest()->getParam('section'))) {
00127                 throw new Exception(Mage::helper('adminhtml')->__('This section is not allowed.'));
00128             }
00129 
00130             // custom save logic
00131             $this->_saveSection();
00132             $section = $this->getRequest()->getParam('section');
00133             $website = $this->getRequest()->getParam('website');
00134             $store   = $this->getRequest()->getParam('store');
00135             Mage::getModel('adminhtml/config_data')
00136                 ->setSection($section)
00137                 ->setWebsite($website)
00138                 ->setStore($store)
00139                 ->setGroups($groups)
00140                 ->save();
00141 
00142             // reinit configuration
00143             Mage::getConfig()->reinit();
00144             Mage::app()->reinitStores();
00145 
00146 
00147             // website and store codes can be used in event implementation, so set them as well
00148             Mage::dispatchEvent("admin_system_config_changed_section_{$section}",
00149                 array('website' => $website, 'store' => $store)
00150             );
00151             $session->addSuccess(Mage::helper('adminhtml')->__('Configuration successfully saved'));
00152         }
00153         catch (Mage_Core_Exception $e) {
00154             foreach(split("\n", $e->getMessage()) as $message) {
00155                 $session->addError($message);
00156             }
00157         }
00158         catch (Exception $e) {
00159             $session->addException($e, Mage::helper('adminhtml')->__('Error while saving this configuration: '.$e->getMessage()));
00160         }
00161 
00162         $this->_saveState($this->getRequest()->getPost('config_state'));
00163 
00164         $this->_redirect('*/*/edit', array('_current' => array('section', 'website', 'store')));
00165     }

stateAction (  ) 

action for ajax saving of fieldset state

Definition at line 195 of file ConfigController.php.

00196     {
00197         if ($this->getRequest()->getParam('isAjax') == 1
00198                     && $this->getRequest()->getParam('container') != ''
00199                         && $this->getRequest()->getParam('value') != '') {
00200 
00201             $configState = array(
00202                 $this->getRequest()->getParam('container') => $this->getRequest()->getParam('value')
00203             );
00204             $this->_saveState($configState);
00205             $this->getResponse()->setBody('success');
00206         }
00207     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:29 2009 for Magento by  doxygen 1.5.8