Ejemplo n.º 1
0
 /**
  * Add items into collection object
  *
  * @param Varien_Simplexml_Element $stagingItem
  * @return Enterprise_Staging_Model_Resource_Staging_Item_Xml_Collection
  */
 public function addStagingItemToCollection($stagingItem)
 {
     $extendInfo = $this->getExtendInfo();
     $_code = (string) $stagingItem->getName();
     $item = Mage::getModel('enterprise_staging/staging_item')->loadFromXmlStagingItem($stagingItem);
     $disabled = false;
     $checked = true;
     $availabilityText = "";
     //process extend information
     if (!empty($extendInfo) && is_array($extendInfo) && isset($extendInfo[$_code])) {
         $item->addData($extendInfo[$_code]);
         if ($extendInfo[$_code]["disabled"] == true) {
             $disabled = true;
             $checked = false;
             $availabilityText = $extendInfo[$_code]["reason"];
         } else {
             $availabilityText = Mage::helper('enterprise_staging')->__('available');
         }
     }
     $item->setData('id', $_code);
     $item->setData('code', $_code);
     $item->setData('checked', $checked);
     $item->setData('disabled', $disabled);
     $item->setData('availability_text', $availabilityText);
     $this->addItem($item);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Create config field during runtime.
  *
  * @param Varien_Simplexml_Element $section
  * @return N98_CheckoutFilters_Model_Adminhtml_Config_Observer
  */
 public function createConfigFields($section)
 {
     /**
      * Check if we are in sales tab and sub-tab payment or shipping.
      * Then we create SimpleXMLElements for form init.
      */
     if ($section->tab == 'sales') {
         if (in_array($section->label, array('Payment Methods', 'Shipping Methods'))) {
             foreach ($section->groups as $group) {
                 foreach ($group as $subGroup) {
                     if (isset($subGroup->fields)) {
                         $this->_addCustomergroupFieldToConfigGroup($subGroup);
                     }
                 }
             }
         }
         // Add fields only for payment methods
         if (in_array($section->label, array('Payment Methods'))) {
             foreach ($section->groups as $group) {
                 foreach ($group as $subGroup) {
                     if (isset($subGroup->fields)) {
                         $this->_addMinYearFieldToConfigGroup($subGroup);
                     }
                 }
             }
         }
     }
     /**
      * Paypal uses a special config tab
      */
     if ($section->tab == 'sales' && $section->getName() == 'paypal') {
         if (isset($section->groups->express)) {
             $this->_addCustomergroupFieldToConfigGroup($section->groups->express);
             $this->_addMinYearFieldToConfigGroup($section->groups->express);
         }
         if (isset($section->groups->wps)) {
             $this->_addCustomergroupFieldToConfigGroup($section->groups->wps);
             $this->_addMinYearFieldToConfigGroup($section->groups->wps);
         }
         if (isset($section->groups->wpp)) {
             $this->_addCustomergroupFieldToConfigGroup($section->groups->wpp);
             $this->_addMinYearFieldToConfigGroup($section->groups->wpp);
         }
     }
     /**
      * Ebizmarts_Sagepay uses a special config tab
      */
     if ('sales' == $section->tab && 'sagepaysuite' == $section->getName()) {
         $my_groups = array('sagepayserver', 'sagepayserver_moto', 'sagepaydirectpro_moto', 'sagepaydirectpro', 'sagepayform', 'sagepaypaypal', 'sagepayrepeat');
         foreach ($my_groups as $group) {
             $this_group = $section->groups->{$group};
             $this->_addCustomergroupFieldToConfigGroup($this_group);
             $this->_addMinYearFieldToConfigGroup($this_group);
         }
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Extends one node
  *
  * @param Varien_Simplexml_Element $source
  * @param boolean                  $overwrite
  *
  * @return Varien_Simplexml_Element
  * @access public
  */
 public function extendChild($source, $overwrite = false)
 {
     // this will be our new target node
     $targetChild = null;
     // name of the source node
     $sourceName = $source->getName();
     // here we have children of our source node
     $sourceChildren = $source->children();
     if (!$source->hasChildren()) {
         // handle string node
         if (isset($this->{$sourceName})) {
             // if target already has children return without regard
             if ($this->{$sourceName}->children()) {
                 return $this;
             }
             if ($overwrite) {
                 if (Mage::registry('conflict_datastore_enabled')) {
                     $factory = new Bronto_Verify_Model_Path_Locator_Factory();
                     $locator = $factory->getLocator();
                     $dataStore = Mage::registry('conflict_datastore');
                     $dataStore->addRewrite((string) $this->{$sourceName}, (string) $source, Mage::registry('conflict_datastore_config_file'), $locator->getPath($source));
                 }
                 unset($this->{$sourceName});
             } else {
                 return $this;
             }
         }
         $targetChild = $this->addChild($sourceName, $source->xmlentities());
         $targetChild->setParent($this);
         foreach ($source->attributes() as $key => $value) {
             $targetChild->addAttribute($key, $this->xmlentities($value));
         }
         return $this;
     }
     if (isset($this->{$sourceName})) {
         $targetChild = $this->{$sourceName};
     }
     if (is_null($targetChild)) {
         // if child target is not found create new and descend
         $targetChild = $this->addChild($sourceName);
         $targetChild->setParent($this);
         foreach ($source->attributes() as $key => $value) {
             $targetChild->addAttribute($key, $this->xmlentities($value));
         }
     }
     // finally add our source node children to resulting new target node
     foreach ($sourceChildren as $childNode) {
         $targetChild->extendChild($childNode, $overwrite);
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Sanitize nodes which names match the specified one
  *
  * Recursively goes through all underlying nodes
  *
  * @param Varien_Simplexml_Element $node
  * @param string $nodeName
  */
 protected static function _sanitizeLayout(Varien_Simplexml_Element $node, $nodeName)
 {
     if ($node->getName() == $nodeName) {
         switch ($nodeName) {
             case 'block':
                 self::_sanitizeBlock($node);
                 break;
             case 'reference':
                 self::_sanitizeReference($node);
                 break;
         }
     }
     foreach ($node->children() as $child) {
         self::_sanitizeLayout($child, $nodeName);
     }
 }
Ejemplo n.º 5
0
 /**
  * Load widget XML config and merge with theme widget config
  *
  * @return Varien_Simplexml_Element|null
  */
 public function getWidgetConfig()
 {
     if ($this->_widgetConfigXml === null) {
         $this->_widgetConfigXml = Mage::getSingleton('widget/widget')->getXmlElementByType($this->getType());
         if ($this->_widgetConfigXml) {
             $configFile = Mage::getSingleton('core/design_package')->getBaseDir(array('_area' => $this->getArea(), '_package' => $this->getPackage(), '_theme' => $this->getTheme(), '_type' => 'etc')) . DS . 'widget.xml';
             if (is_readable($configFile)) {
                 $themeWidgetsConfig = new Varien_Simplexml_Config();
                 $themeWidgetsConfig->loadFile($configFile);
                 if ($themeWidgetTypeConfig = $themeWidgetsConfig->getNode($this->_widgetConfigXml->getName())) {
                     $this->_widgetConfigXml->extend($themeWidgetTypeConfig);
                 }
             }
         }
     }
     return $this->_widgetConfigXml;
 }
Ejemplo n.º 6
0
 /**
  * Load widget XML config and merge with theme widget config
  *
  * @return Varien_Simplexml_Element|null
  */
 public function getWidgetConfig()
 {
     if ($this->_widgetConfigXml === null) {
         $this->_widgetConfigXml = Mage::getSingleton('Mage_Widget_Model_Widget')->getXmlElementByType($this->getType());
         if ($this->_widgetConfigXml) {
             $configFile = Mage::getDesign()->getFilename('widget.xml', array('_area' => $this->getArea(), '_package' => $this->getPackage(), '_theme' => $this->getTheme(), '_module' => Mage::getConfig()->determineOmittedNamespace(preg_replace('/^(.+?)\\/.+$/', '\\1', $this->getType()), true)));
             if (is_readable($configFile)) {
                 $themeWidgetsConfig = new Varien_Simplexml_Config();
                 $themeWidgetsConfig->loadFile($configFile);
                 if ($themeWidgetTypeConfig = $themeWidgetsConfig->getNode($this->_widgetConfigXml->getName())) {
                     $this->_widgetConfigXml->extend($themeWidgetTypeConfig);
                 }
             }
         }
     }
     return $this->_widgetConfigXml;
 }
Ejemplo n.º 7
0
 public function updateMenu(Varien_Simplexml_Element $node)
 {
     $entityTypesCollection = $this->_getEntityTypesCollection();
     if ($entityTypesCollection->getSize()) {
         $children = $node->addChild('children');
         $index = 0;
         foreach ($entityTypesCollection as $entityType) {
             $index += 10;
             $menuItem = $children->addChild(sprintf('goodahead_etm_entity_type_%d', $entityType->getId()));
             $menuItem->addChild('title', strlen($entityType->getEntityTypeName()) ? $entityType->getEntityTypeName() : $entityType->getEntityTypeCode());
             $menuItem->addChild('sort_order', $index);
             $menuItem->addChild('action', sprintf((string) $node->base_link, $entityType->getId()));
         }
     } else {
         $nodeName = $node->getName();
         unset($node->getParent()->{$nodeName});
     }
 }
Ejemplo n.º 8
0
 /**
  * @param Mana_Db_Model_Entity_Indexer $indexer provides access to process record and indexer setup
  * @param Varien_Simplexml_Element $target setup in config.xml
  * @param Varien_Simplexml_Element $scope setup in m_db.xml
  * @param array $options on which records to run
  * @return void
  */
 public function flattenScope($indexer, $target, $scope, $options)
 {
     /** @noinspection PhpUndefinedFieldInspection */
     $targetEntity = (string) $target->entity . '/' . $scope->getName();
     if (isset($options['entity_filters']) && !isset($options['entity_filters'][$targetEntity])) {
         return;
     }
     $options = array_merge(array('provide_field_details_in_exceptions' => true), $options);
     if (isset($options['entity_filters']) && !isset($options['entity_filter_formula'])) {
         $options['entity_filter_formula'] = '{{= ' . $options['entity_filters'][$targetEntity] . '}}';
     }
     $db = $this->_getWriteAdapter();
     /* @var $res Mage_Core_Model_Resource */
     $res = Mage::getSingleton('core/resource');
     /* @var $dbHelper Mana_Db_Helper_Data */
     $dbHelper = Mage::helper('mana_db');
     /* @var $formulaHelper Mana_Db_Helper_Formula */
     $formulaHelper = Mage::helper('mana_db/formula');
     // get basic select from all source tables, properly joined (based on m_db.xml)
     /** @noinspection PhpUndefinedFieldInspection */
     $entity = (string) $scope->flattens;
     //$db->query($formulaHelper->delete($entity, $targetEntity));
     // get formula hashes and formula texts
     $formulaGroups = $formulaHelper->getFormulaGroups($targetEntity, $options);
     // for each formula hash => formula text
     foreach ($formulaGroups as $formulas) {
         $formulas = $formulas ? json_decode($formulas, true) : array();
         // filter basic select by formula hash
         $context = $formulaHelper->select($targetEntity, $formulas, $options);
         // convert SELECT into UPDATE which acts as INSERT on DUPLICATE unique keys
         $sql = $context->getSelect()->insertFromSelect($res->getTableName($dbHelper->getScopedName($targetEntity)), $context->getFields());
         // run the statement
         try {
             $db->query($sql);
         } catch (Exception $e) {
             /* @var $logger Mana_Core_Helper_Logger */
             $logger = Mage::helper('mana_core/logger');
             $logger->logDbIndexerFailure($sql);
             throw $e;
         }
     }
 }
Ejemplo n.º 9
0
 protected function _getBaseClass(Varien_Simplexml_Element $config)
 {
     $model = null;
     if ($config->class) {
         $model = (string) $config->class;
     } elseif ($config->model) {
         $model = (string) $config->model;
     } else {
         /**
          * Backwards compatibility for pre-MMDB extensions. MMDB introduced since Magebto 1.6.0.0
          * In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So <deprecatedNode> is left
          * to keep name of previously used nodes, that still may be used by non-updated extensions.
          */
         $deprecatedNodes = $config->xpath('../*[deprecatedNode="' . (string) $config->getName() . '"]');
         if ($deprecatedNodes && $deprecatedNodes[0]->class) {
             $model = (string) $deprecatedNodes[0]->class;
         }
     }
     if (is_null($model)) {
         return false;
     }
     return $this->_getModelClassName($model, $config);
 }
Ejemplo n.º 10
0
 /**
  * Handler for reports
  *
  * @param Varien_Simplexml_Element $config
  * @param Enterprise_Logging_Model_Event $eventModel
  * @return Enterprise_Logging_Model_Event|false
  */
 public function postDispatchReport($config, $eventModel, $processor)
 {
     $fullActionNameParts = explode('_report_', $config->getName(), 2);
     if (empty($fullActionNameParts[1])) {
         return false;
     }
     $request = Mage::app()->getRequest();
     $filter = $request->getParam('filter');
     //Filtering request data
     $data = array_intersect_key($request->getParams(), array('report_from' => null, 'report_to' => null, 'report_period' => null, 'store' => null, 'website' => null, 'group' => null));
     //Need when in request data there are was no period info
     if ($filter) {
         $filterData = Mage::app()->getHelper('adminhtml')->prepareFilterString($filter);
         $data = array_merge($data, (array) $filterData);
     }
     //Add log entry details
     if ($data) {
         $change = Mage::getModel('enterprise_logging/event_changes');
         $processor->addEventChanges($change->setSourceName('params')->setOriginalData(array())->setResultData($data));
     }
     return $eventModel->setInfo($fullActionNameParts[1]);
 }
Ejemplo n.º 11
0
 /**
  * Load layout update attributes
  *
  * @param Varien_Simplexml_Element $layoutUpdate
  * @return array
  */
 protected static function _getAttributes(Varien_Simplexml_Element $layoutUpdate)
 {
     $attributes = array('type' => $layoutUpdate->getAttribute('type') ?: self::DEFAULT_TYPE, 'action_name' => $layoutUpdate->getName());
     return $attributes;
 }
Ejemplo n.º 12
0
 /**
  * Extends one node
  *
  * @param Varien_Simplexml_Element $source
  * @param boolean $overwrite
  * @return Varien_Simplexml_Element
  */
 public function extendChild($source, $overwrite = false)
 {
     // this will be our new target node
     $targetChild = null;
     // name of the source node
     $sourceName = $source->getName();
     // here we have children of our source node
     $sourceChildren = $source->children();
     if (!$source->hasChildren()) {
         // handle string node
         if (isset($this->{$sourceName})) {
             // if target already has children return without regard
             if ($this->{$sourceName}->hasChildren()) {
                 return $this;
             }
             if ($overwrite) {
                 unset($this->{$sourceName});
             } else {
                 return $this;
             }
         }
         $targetChild = $this->addChild($sourceName, $source->xmlentities());
         $targetChild->setParent($this);
         foreach ($source->attributes() as $key => $value) {
             $targetChild->addAttribute($key, $this->xmlentities($value));
         }
         return $this;
     }
     if (isset($this->{$sourceName})) {
         $targetChild = $this->{$sourceName};
     }
     if (is_null($targetChild)) {
         // if child target is not found create new and descend
         $targetChild = $this->addChild($sourceName);
         $targetChild->setParent($this);
         foreach ($source->attributes() as $key => $value) {
             $targetChild->addAttribute($key, $this->xmlentities($value));
         }
     }
     // finally add our source node children to resulting new target node
     foreach ($sourceChildren as $childKey => $childNode) {
         $targetChild->extendChild($childNode, $overwrite);
     }
     return $this;
 }
Ejemplo n.º 13
0
 /**
  * Appends $source to current node
  *
  * @param Varien_Simplexml_Element $source
  * @return Varien_Simplexml_Element
  */
 public function appendChild($n, $source)
 {
     if ($source->children()) {
         /**
          * @see http://bugs.php.net/bug.php?id=41867 , fixed in 5.2.4
          */
         if (version_compare(phpversion(), '5.2.4', '<') === true) {
             $name = $source->children()->getName();
         } else {
             $name = $source->getName();
         }
         $child = $n->addChild($name);
     } else {
         $child = $n->addChild($source->getName(), $this->xmlentities($source));
     }
     $attributes = $source->attributes();
     foreach ($attributes as $key => $value) {
         $child->addAttribute($key, $this->xmlentities($value));
     }
     foreach ($source->children() as $sourceChild) {
         $this->appendChild($child, $sourceChild);
     }
     return $n;
 }
Ejemplo n.º 14
0
 /**
  * Init fieldset fields
  *
  * @param Varien_Data_Form_Element_Fieldset $fieldset
  * @param Varien_Simplexml_Element $group
  * @param Varien_Simplexml_Element $section
  * @param string $fieldPrefix
  * @param string $labelPrefix
  * @return Mage_Adminhtml_Block_System_Config_Form
  */
 public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labelPrefix = '')
 {
     if (!$this->_configDataObject) {
         $this->_initObjects();
     }
     // Extends for config data
     $configDataAdditionalGroups = array();
     foreach ($group->fields as $elements) {
         // sort either by sort_order or by child node values bypassing the sort_order
         $elements = $this->_sortElements($group, $fieldset, (array) $elements);
         foreach ($elements as $element) {
             if (!$this->_canShowField($element)) {
                 continue;
             }
             /**
              * Look for custom defined field path
              */
             $path = (string) $element->config_path;
             if (empty($path)) {
                 $path = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $element->getName();
             } elseif (strrpos($path, '/') > 0) {
                 // Extend config data with new section group
                 $groupPath = substr($path, 0, strrpos($path, '/'));
                 if (!isset($configDataAdditionalGroups[$groupPath])) {
                     $this->_configData = $this->_configDataObject->extendConfig($groupPath, false, $this->_configData);
                     $configDataAdditionalGroups[$groupPath] = true;
                 }
             }
             $this->_initElement($element, $fieldset, $group, $section, $path, $fieldPrefix, $labelPrefix);
         }
     }
     return $this;
 }
Ejemplo n.º 15
0
 /**
  * @param Varien_Simplexml_Element $target
  */
 public function propagateName($target)
 {
     $target->name = $target->getName();
 }
Ejemplo n.º 16
0
 /**
  * Enter description here ...
  * @param Varien_Simplexml_Element $config
  * @param array | null $fields
  * @param string | null $module
  */
 protected function _translateConfigRecursively($config, $fields = null, $module = null)
 {
     if ($fields && in_array($config->getName(), $fields)) {
         $name = $config->getName();
         $parent = $config->getParent();
         $value = (string) $config;
         $moduleName = $module ? $module : $this->_getModuleName();
         $parent->{$name} = Mage::app()->getTranslator()->translate(array(new Mage_Core_Model_Translate_Expr($value, $moduleName)));
     }
     $fields = isset($config['translate']) ? explode(',', (string) $config['translate']) : null;
     $module = isset($config['module']) ? (string) $config['module'] : null;
     foreach ($config->children() as $key => $value) {
         $this->_translateConfigRecursively($value, $fields, $module);
     }
 }
Ejemplo n.º 17
0
 /**
  * Get tree node
  *
  * @param Varien_Simplexml_Element|array $node
  * @param int $level
  * @return array
  */
 protected function _getTreeNode($node, $level = 0)
 {
     $item = array();
     $isResource = false;
     $isGroup = false;
     $name = null;
     if ($level != 0) {
         $name = $node->getName();
         if (!(int) $node->resource) {
             if (self::NAME_RESOURCE_GROUPS != $name) {
                 $isGroup = true;
                 $item['id'] = self::NAME_GROUP . self::ID_SEPARATOR . $name;
             }
             $item['text'] = (string) $node->title;
         } else {
             $isResource = true;
             $item['id'] = self::NAME_RESOURCE . self::ID_SEPARATOR . $name;
             $item['text'] = $this->__('%s', (string) $node->title);
         }
         $item['checked'] = false;
         $item['sort_order'] = isset($node->sort_order) ? (string) $node->sort_order : 0;
     }
     if (isset($node->children)) {
         $children = $node->children->children();
     } else {
         $children = $node->children();
     }
     if (empty($children)) {
         /**
          * Node doesn't have any child nodes
          * and it should be skipped
          */
         return $item;
     }
     $item[self::NAME_CHILDREN] = array();
     if ($isResource) {
         if (self::TYPE_ATTRIBUTE == $this->_type) {
             if (!$this->_addOperations($item, $node, $name)) {
                 return null;
             }
         } elseif (self::TYPE_PRIVILEGE == $this->_type) {
             if (!$this->_addPrivileges($item, $node, $name)) {
                 return null;
             }
         }
     }
     /** @var $child Varien_Simplexml_Element */
     foreach ($children as $child) {
         if ($child->getName() != 'title' && $child->getName() != 'sort_order') {
             if (!(string) $child->title) {
                 continue;
             }
             if ($level != 0) {
                 $subNode = $this->_getTreeNode($child, $level + 1);
                 if (!$subNode) {
                     continue;
                 }
                 //if sub-node check then check current node
                 if (!empty($subNode['checked'])) {
                     $item['checked'] = true;
                 }
                 $item[self::NAME_CHILDREN][] = $subNode;
             } else {
                 $item = $this->_getTreeNode($child, $level + 1);
             }
         }
     }
     if (!empty($item[self::NAME_CHILDREN])) {
         usort($item[self::NAME_CHILDREN], array($this, '_sortTree'));
     } elseif ($isGroup) {
         //skip empty group
         return null;
     }
     return $item;
 }
Ejemplo n.º 18
0
 /**
  * Init fieldset fields
  *
  * @param Varien_Data_Form_Element_Fieldset $fieldset
  * @param Varien_Simplexml_Element $group
  * @param Varien_Simplexml_Element $section
  * @param string $fieldPrefix
  * @param string $labelPrefix
  * @return Mage_Adminhtml_Block_System_Config_Form
  */
 public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labelPrefix = '')
 {
     if (!$this->_configDataObject) {
         $this->_initObjects();
     }
     // Extends for config data
     $configDataAdditionalGroups = array();
     foreach ($group->fields as $elements) {
         $elements = (array) $elements;
         // sort either by sort_order or by child node values bypassing the sort_order
         if ($group->sort_fields && $group->sort_fields->by) {
             $fieldset->setSortElementsByAttribute((string) $group->sort_fields->by, $group->sort_fields->direction_desc ? SORT_DESC : SORT_ASC);
         } else {
             usort($elements, array($this, '_sortForm'));
         }
         foreach ($elements as $element) {
             if (!$this->_canShowField($element)) {
                 continue;
             }
             if ((string) $element->getAttribute('type') == 'group') {
                 $this->_initGroup($fieldset->getForm(), $element, $section, $fieldset);
                 continue;
             }
             /**
              * Look for custom defined field path
              */
             $path = (string) $element->config_path;
             if (empty($path)) {
                 $path = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $element->getName();
             } elseif (strrpos($path, '/') > 0) {
                 // Extend config data with new section group
                 $groupPath = substr($path, 0, strrpos($path, '/'));
                 if (!isset($configDataAdditionalGroups[$groupPath])) {
                     $this->_configData = $this->_configDataObject->extendConfig($groupPath, false, $this->_configData);
                     $configDataAdditionalGroups[$groupPath] = true;
                 }
             }
             $data = $this->_configDataObject->getConfigDataValue($path, $inherit, $this->_configData);
             if ($element->frontend_model) {
                 $fieldRenderer = Mage::getBlockSingleton((string) $element->frontend_model);
             } else {
                 $fieldRenderer = $this->_defaultFieldRenderer;
             }
             $fieldRenderer->setForm($this);
             $fieldRenderer->setConfigData($this->_configData);
             $helperName = $this->_configFields->getAttributeModule($section, $group, $element);
             $fieldType = (string) $element->frontend_type ? (string) $element->frontend_type : 'text';
             $name = 'groups[' . $group->getName() . '][fields][' . $fieldPrefix . $element->getName() . '][value]';
             $label = Mage::helper($helperName)->__($labelPrefix) . ' ' . Mage::helper($helperName)->__((string) $element->label);
             $hint = (string) $element->hint ? Mage::helper($helperName)->__((string) $element->hint) : '';
             if ($element->backend_model) {
                 $model = Mage::getModel((string) $element->backend_model);
                 if (!$model instanceof Mage_Core_Model_Config_Data) {
                     Mage::throwException('Invalid config field backend model: ' . (string) $element->backend_model);
                 }
                 $model->setPath($path)->setValue($data)->setWebsite($this->getWebsiteCode())->setStore($this->getStoreCode())->afterLoad();
                 $data = $model->getValue();
             }
             $comment = $this->_prepareFieldComment($element, $helperName, $data);
             $tooltip = $this->_prepareFieldTooltip($element, $helperName);
             $id = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $element->getName();
             if ($element->depends) {
                 foreach ($element->depends->children() as $dependent) {
                     /* @var $dependent Mage_Core_Model_Config_Element */
                     if (isset($dependent->fieldset)) {
                         $dependentFieldGroupName = (string) $dependent->fieldset;
                         if (!isset($this->_fieldsets[$dependentFieldGroupName])) {
                             $dependentFieldGroupName = $group->getName();
                         }
                     } else {
                         $dependentFieldGroupName = $group->getName();
                     }
                     $dependentFieldNameValue = $dependent->getName();
                     $dependentFieldGroup = $dependentFieldGroupName == $group->getName() ? $group : $this->_fieldsets[$dependentFieldGroupName]->getGroup();
                     $dependentId = $section->getName() . '_' . $dependentFieldGroupName . '_' . $fieldPrefix . $dependentFieldNameValue;
                     $shouldBeAddedDependence = true;
                     $dependentValue = (string) (isset($dependent->value) ? $dependent->value : $dependent);
                     if (isset($dependent['separator'])) {
                         $dependentValue = explode((string) $dependent['separator'], $dependentValue);
                     }
                     $dependentFieldName = $fieldPrefix . $dependent->getName();
                     $dependentField = $dependentFieldGroup->fields->{$dependentFieldName};
                     /*
                      * If dependent field can't be shown in current scope and real dependent config value
                      * is not equal to preferred one, then hide dependence fields by adding dependence
                      * based on not shown field (not rendered field)
                      */
                     if (!$this->_canShowField($dependentField)) {
                         $dependentFullPath = $section->getName() . '/' . $dependentFieldGroupName . '/' . $fieldPrefix . $dependent->getName();
                         $dependentValueInStore = Mage::getStoreConfig($dependentFullPath, $this->getStoreCode());
                         if (is_array($dependentValue)) {
                             $shouldBeAddedDependence = !in_array($dependentValueInStore, $dependentValue);
                         } else {
                             $shouldBeAddedDependence = $dependentValue != $dependentValueInStore;
                         }
                     }
                     if ($shouldBeAddedDependence) {
                         $this->_getDependence()->addFieldMap($id, $id)->addFieldMap($dependentId, $dependentId)->addFieldDependence($id, $dependentId, $dependentValue);
                     }
                 }
             }
             $sharedClass = '';
             if ($element->shared && $element->config_path) {
                 $sharedClass = ' shared shared-' . str_replace('/', '-', $element->config_path);
             }
             $requiresClass = '';
             if ($element->requires) {
                 $requiresClass = ' requires';
                 foreach (explode(',', $element->requires) as $groupName) {
                     $requiresClass .= ' requires-' . $section->getName() . '_' . $groupName;
                 }
             }
             $field = $fieldset->addField($id, $fieldType, array('name' => $name, 'label' => $label, 'comment' => $comment, 'tooltip' => $tooltip, 'hint' => $hint, 'value' => $data, 'inherit' => $inherit, 'class' => $element->frontend_class . $sharedClass . $requiresClass, 'field_config' => $element, 'scope' => $this->getScope(), 'scope_id' => $this->getScopeId(), 'scope_label' => $this->getScopeLabel($element), 'can_use_default_value' => $this->canUseDefaultValue((int) $element->show_in_default), 'can_use_website_value' => $this->canUseWebsiteValue((int) $element->show_in_website)));
             $this->_prepareFieldOriginalData($field, $element);
             if (isset($element->validate)) {
                 $field->addClass($element->validate);
             }
             if (isset($element->frontend_type) && 'multiselect' === (string) $element->frontend_type && isset($element->can_be_empty)) {
                 $field->setCanBeEmpty(true);
             }
             $field->setRenderer($fieldRenderer);
             if ($element->source_model) {
                 // determine callback for the source model
                 $factoryName = (string) $element->source_model;
                 $method = false;
                 if (preg_match('/^([^:]+?)::([^:]+?)$/', $factoryName, $matches)) {
                     array_shift($matches);
                     list($factoryName, $method) = array_values($matches);
                 }
                 $sourceModel = Mage::getSingleton($factoryName);
                 if ($sourceModel instanceof Varien_Object) {
                     $sourceModel->setPath($path);
                 }
                 if ($method) {
                     if ($fieldType == 'multiselect') {
                         $optionArray = $sourceModel->{$method}();
                     } else {
                         $optionArray = array();
                         foreach ($sourceModel->{$method}() as $value => $label) {
                             $optionArray[] = array('label' => $label, 'value' => $value);
                         }
                     }
                 } else {
                     $optionArray = $sourceModel->toOptionArray($fieldType == 'multiselect');
                 }
                 $field->setValues($optionArray);
             }
         }
     }
     return $this;
 }
Ejemplo n.º 19
0
 /**
  * Init fieldset fields
  *
  * @param Varien_Data_Form_Element_Fieldset $fieldset
  * @param Varien_Simplexml_Element $group
  * @param Varien_Simplexml_Element $section
  * @param string $fieldPrefix
  * @param string $labelPrefix
  * @return Mage_Adminhtml_Block_System_Config_Form
  */
 public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labelPrefix = '')
 {
     foreach ($group->fields as $elements) {
         $elements = (array) $elements;
         // sort either by sort_order or by child node values bypassing the sort_order
         if ($group->sort_fields && $group->sort_fields->by) {
             $fieldset->setSortElementsByAttribute((string) $group->sort_fields->by, $group->sort_fields->direction_desc ? SORT_DESC : SORT_ASC);
         } else {
             usort($elements, array($this, '_sortForm'));
         }
         foreach ($elements as $e) {
             if (!$this->_canShowField($e)) {
                 continue;
             }
             $path = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $e->getName();
             $id = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $e->getName();
             if (isset($this->_configData[$path])) {
                 $data = $this->_configData[$path];
                 $inherit = false;
             } else {
                 $data = $this->_configRoot->descend($path);
                 $inherit = true;
             }
             if ($e->frontend_model) {
                 $fieldRenderer = Mage::getBlockSingleton((string) $e->frontend_model);
             } else {
                 $fieldRenderer = $this->_defaultFieldRenderer;
             }
             $fieldRenderer->setForm($this);
             $fieldRenderer->setConfigData($this->_configData);
             $helperName = $this->_configFields->getAttributeModule($section, $group, $e);
             $fieldType = (string) $e->frontend_type ? (string) $e->frontend_type : 'text';
             $name = 'groups[' . $group->getName() . '][fields][' . $fieldPrefix . $e->getName() . '][value]';
             $label = Mage::helper($helperName)->__($labelPrefix) . ' ' . Mage::helper($helperName)->__((string) $e->label);
             $comment = (string) $e->comment ? Mage::helper($helperName)->__((string) $e->comment) : '';
             if ($e->backend_model) {
                 $model = Mage::getModel((string) $e->backend_model);
                 if (!$model instanceof Mage_Core_Model_Config_Data) {
                     Mage::throwException('Invalid config field backend model: ' . (string) $e->backend_model);
                 }
                 $model->setPath($path)->setValue($data)->afterLoad();
                 $data = $model->getValue();
             }
             $field = $fieldset->addField($id, $fieldType, array('name' => $name, 'label' => $label, 'comment' => $comment, 'value' => $data, 'inherit' => $inherit, 'class' => $e->frontend_class, 'field_config' => $e, 'scope' => $this->getScope(), 'scope_id' => $this->getScopeId(), 'can_use_default_value' => $this->canUseDefaultValue((int) $e->show_in_default), 'can_use_website_value' => $this->canUseWebsiteValue((int) $e->show_in_website)));
             if (isset($e->validate)) {
                 $field->addClass($e->validate);
             }
             if (isset($e->frontend_type) && 'multiselect' === (string) $e->frontend_type && isset($e->can_be_empty)) {
                 $field->setCanBeEmpty(true);
             }
             $field->setRenderer($fieldRenderer);
             if ($e->source_model) {
                 $sourceModel = Mage::getSingleton((string) $e->source_model);
                 if ($sourceModel instanceof Varien_Object) {
                     $sourceModel->setPath($path);
                 }
                 $field->setValues($sourceModel->toOptionArray($fieldType == 'multiselect'));
             }
         }
     }
     return $this;
 }
Ejemplo n.º 20
0
 /**
  * Return element by tag name, and checking attributes with namespaces
  *
  * @param Varien_Simplexml_Element $source
  * @param string $namespace
  * @return null|Varien_Simplexml_Element
  */
 public function getElementByName($source, $elmNamespace = '')
 {
     $sourceName = $source->getName();
     $extendElmAttributes = $this->getAttributes($source);
     foreach ($this->children($elmNamespace) as $k => $child) {
         if ($child->getName() == $sourceName) {
             $elm = true;
             foreach ($extendElmAttributes as $namespace => $attributes) {
                 /**
                  * if count of attributes of extend element is 0 in $namespace,
                  * and current element has attributes in $namespace - different elements
                  */
                 //                    if (!count($attributes) && count($this->getAttributes($child, $namespace))) {
                 //                        foreach ($this->getAttributes($child, $namespace) as $attribute) {
                 //                            $elm = false;
                 //                            break;
                 //                        }
                 //                    }
                 foreach ($attributes as $key => $value) {
                     if (is_null($child->getAttribute($key, $namespace)) || $child->getAttribute($key, $namespace) != $value) {
                         $elm = false;
                     }
                 }
             }
             /**
              * if count of namespaces attributes of element to extend is 0,
              * but current element has namespaces attributes - different elements
              */
             if (!count($extendElmAttributes) && count($this->getAttributes($child))) {
                 $elm = false;
             }
             if ($elm) {
                 return $child;
             }
         }
     }
     return null;
 }
Ejemplo n.º 21
0
 /**
  * Get attributes from XML layout update
  *
  * @param Varien_Simplexml_Element $layoutUpdate
  * @return array
  */
 protected function _getAttributes(Varien_Simplexml_Element $layoutUpdate)
 {
     $attributes = array();
     $attributes['type'] = $layoutUpdate->getAttribute('type') ?: 'layout';
     $attributes['action_name'] = $layoutUpdate->getName();
     foreach ($layoutUpdate->attributes() as $attributeName => $attributeValue) {
         $attributes[$attributeName] = (string) $attributeValue;
     }
     return $attributes;
 }