public function BuildBranch(Varien_Data_Tree_Node $node) { $buildString = '<li style="padding-left: 16px;">'; $buildString .= '<div class="tree-level-' . $node->getLevel() . '">'; if ($node->getChildrenCount() != 0) { $buildString .= '<div class="opener" id="opener' . $node->getId() . '" OnClick="OpenMe(this)"></div>'; } else { $buildString .= '<div class="child"></div>'; } $buildString .= ' <input type="checkbox" class="inputcb" id="inputcb' . $node->getId() . '" OnClick="Decide(this)" enabled="false"/> <div class="folder"></div> <a tabindex="1" href="#" hidefocus="on" id="linkItem"><span unselectable="on" id="extdd-' . $node->getLevel() . '">' . $node->getName() . '</a> '; $buildString .= '</div>'; if ($node->getChildrenCount() != 0) { $buildString .= '<ul id="ToOpen' . $node->getId() . '">'; foreach ($node->getChildren() as $child) { $buildString .= $this->BuildBranch($child); } $buildString .= '</ul>'; } $buildString .= '</li>'; return $buildString; }
/** * Get JSON of a tree node or an associative array * * @param Varien_Data_Tree_Node|array $node * @param int $level * @return string */ protected function _getNodeJson($node, $level = 1) { $item = array(); $item['text'] = $this->htmlEscape($node->getName()); if ($this->_withProductCount) { $item['text'] .= ' (' . $node->getProductCount() . ')'; } $item['id'] = $node->getId(); $item['path'] = $node->getData('path'); $item['cls'] = 'folder ' . ($node->getIsActive() ? 'active-category' : 'no-active-category'); $item['allowDrop'] = false; $item['allowDrag'] = false; if ($node->hasChildren()) { $item['children'] = array(); foreach ($node->getChildren() as $child) { $item['children'][] = $this->_getNodeJson($child, $level + 1); } } if (empty($item['children']) && (int) $node->getChildrenCount() > 0) { $item['children'] = array(); } if (!empty($item['children'])) { $item['expanded'] = true; } if (in_array($node->getId(), $this->getCategoryIds())) { $item['checked'] = true; } return $item; }
/** * Convert categories tree to array recursively * * @param Varien_Data_Tree_Node $node * @return array */ protected function _getNodesArray($node) { $result = array('id' => (int) $node->getId(), 'parent_id' => (int) $node->getParentId(), 'children_count' => (int) $node->getChildrenCount(), 'is_active' => (bool) $node->getIsActive(), 'name' => $node->getName(), 'level' => (int) $node->getLevel(), 'product_count' => (int) $node->getProductCount()); if (is_array($this->_allowedCategoryIds) && !in_array($result['id'], $this->_allowedCategoryIds)) { $result['disabled'] = true; } if ($node->hasChildren()) { $result['children'] = array(); foreach ($node->getChildren() as $childNode) { $result['children'][] = $this->_getNodesArray($childNode); } } $result['cls'] = ($result['is_active'] ? '' : 'no-') . 'active-category'; $result['expanded'] = !empty($result['children']); return $result; }