示例#1
0
 /**
  * Get Node Json
  *
  * @param mixed $node
  * @param int $level
  * @return array
  */
 protected function _getNodeJson(DomElement $node, $level = 0)
 {
     $item = array();
     $selres = $this->getSelectedResources();
     if ($level != 0) {
         $item['text'] = Mage::helper('Mage_User_Helper_Data')->__((string) $node->getAttribute('title'));
         // @codingStandardsIgnoreStart
         $item['sortOrder'] = $node->hasAttribute('sortOrder') ? (string) $node->getAttribute('sortOrder') : 0;
         // @codingStandardsIgnoreEnd
         $item['id'] = (string) $node->getAttribute('id');
         if (in_array($item['id'], $selres)) {
             $item['checked'] = true;
         }
     }
     $children = $node->childNodes;
     if (!empty($children)) {
         $item['children'] = array();
         //$item['cls'] = 'fiche-node';
         foreach ($children as $child) {
             if ($child instanceof DOMElement) {
                 if (!(string) $child->getAttribute('title')) {
                     continue;
                 }
                 if ($level != 0) {
                     $item['children'][] = $this->_getNodeJson($child, $level + 1);
                 } else {
                     $item = $this->_getNodeJson($child, $level + 1);
                 }
             }
         }
         usort($item['children'], array($this, '_sortTree'));
     }
     return $item;
 }
 /**
  * Returns boolean on presence of given $attributeName on a link or embed element.
  *
  * If given $element is embed attribute value will be copied with a prefixed name.
  *
  * @param \DOMElement $element
  * @param string $attributeName
  *
  * @return bool
  */
 protected function elementHasAttribute(DomElement $element, $attributeName)
 {
     // First try to return for link
     if ($element->localName === 'link' && $element->hasAttribute($attributeName)) {
         return true;
     }
     // Second return for embed
     if ($element->hasAttribute(EmbedLinking::TEMP_PREFIX . $attributeName)) {
         return true;
     }
     return false;
 }