00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Block_Urlrewrite_Category_Tree extends Mage_Adminhtml_Block_Catalog_Category_Abstract
00035 {
00036
00037
00038
00039
00040 public function __construct()
00041 {
00042 parent::__construct();
00043 $this->setTemplate('urlrewrite/categories.phtml');
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 public function getTreeArray($parentId = null, $asJson = false, $recursionLevel = 3)
00055 {
00056 $result = array();
00057 if ($parentId) {
00058 $category = Mage::getModel('catalog/category')->load($parentId);
00059 if (!empty($category)) {
00060 $tree = $this->_getNodesArray($this->getNode($category, $recursionLevel));
00061 if (!empty($tree) && !empty($tree['children'])) {
00062 $result = $tree['children'];
00063 }
00064 }
00065 }
00066 else {
00067 $result = $this->_getNodesArray($this->getRoot(null, $recursionLevel));
00068 }
00069 if ($asJson) {
00070 return Zend_Json::encode($result);
00071 }
00072 return $result;
00073 }
00074
00075
00076
00077
00078
00079
00080 public function getCategoryCollection()
00081 {
00082 $collection = $this->_getData('category_collection');
00083 if (is_null($collection)) {
00084 $collection = Mage::getModel('catalog/category')->getCollection()
00085 ->addAttributeToSelect(array('name', 'is_active'))
00086 ->setLoadProductCount(true)
00087 ;
00088 $this->setData('category_collection', $collection);
00089 }
00090 return $collection;
00091 }
00092
00093
00094
00095
00096
00097
00098 protected function _getNodesArray($node)
00099 {
00100 $result = array(
00101 'id' => (int)$node->getId(),
00102 'parent_id' => (int)$node->getParentId(),
00103 'children_count' => (int)$node->getChildrenCount(),
00104 'is_active' => (bool)$node->getIsActive(),
00105 'name' => $node->getName(),
00106 'level' => (int)$node->getLevel(),
00107 'product_count' => (int)$node->getProductCount(),
00108 );
00109 if ($node->hasChildren()) {
00110 $result['children'] = array();
00111 foreach ($node->getChildren() as $childNode) {
00112 $result['children'][] = $this->_getNodesArray($childNode);
00113 }
00114 }
00115 $result['cls'] = ($result['is_active'] ? '' : 'no-') . 'active-category';
00116 $result['expanded'] = false;
00117 if (!empty($result['children'])) {
00118 $result['expanded'] = true;
00119 }
00120 return $result;
00121 }
00122
00123
00124
00125
00126
00127
00128 public function getLoadTreeUrl()
00129 {
00130 return Mage::helper('adminhtml')->getUrl('*/*/categoriesJson');
00131 }
00132 }