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_Catalog_Category_Abstract extends Mage_Adminhtml_Block_Template
00035 {
00036
00037 public function __construct()
00038 {
00039 parent::__construct();
00040 }
00041
00042 public function getCategory()
00043 {
00044 return Mage::registry('category');
00045 }
00046
00047 public function getCategoryId()
00048 {
00049 if ($this->getCategory()) {
00050 return $this->getCategory()->getId();
00051 }
00052 return Mage_Catalog_Model_Category::TREE_ROOT_ID;
00053 }
00054
00055 public function getCategoryName()
00056 {
00057 return $this->getCategory()->getName();
00058 }
00059
00060 public function getCategoryPath()
00061 {
00062 if ($this->getCategory()) {
00063 return $this->getCategory()->getPath();
00064 }
00065 return Mage_Catalog_Model_Category::TREE_ROOT_ID;
00066 }
00067
00068 public function hasStoreRootCategory()
00069 {
00070 $root = $this->getRoot();
00071 if ($root && $root->getId()) {
00072 return true;
00073 }
00074 return false;
00075 }
00076
00077 public function getStore()
00078 {
00079 $storeId = (int) $this->getRequest()->getParam('store');
00080 return Mage::app()->getStore($storeId);
00081 }
00082
00083 public function getRoot($parentNodeCategory=null, $recursionLevel=3)
00084 {
00085 if (!is_null($parentNodeCategory) && $parentNodeCategory->getId()) {
00086 return $this->getNode($parentNodeCategory, $recursionLevel);
00087 }
00088 $root = Mage::registry('root');
00089 if (is_null($root)) {
00090 $storeId = (int) $this->getRequest()->getParam('store');
00091
00092 if ($storeId) {
00093 $store = Mage::app()->getStore($storeId);
00094 $rootId = $store->getRootCategoryId();
00095 }
00096 else {
00097 $rootId = Mage_Catalog_Model_Category::TREE_ROOT_ID;
00098 }
00099
00100 $tree = Mage::getResourceSingleton('catalog/category_tree')
00101 ->load($rootId, $recursionLevel);
00102
00103 if ($this->getCategory()) {
00104 $tree->loadEnsuredNodes($this->getCategory(), $tree->getNodeById($rootId));
00105 }
00106
00107 $tree->addCollectionData($this->getCategoryCollection());
00108
00109 $root = $tree->getNodeById($rootId);
00110
00111 if ($root && $rootId != Mage_Catalog_Model_Category::TREE_ROOT_ID) {
00112 $root->setIsVisible(true);
00113 }
00114 elseif($root && $root->getId() == Mage_Catalog_Model_Category::TREE_ROOT_ID) {
00115 $root->setName(Mage::helper('catalog')->__('Root'));
00116 }
00117
00118 Mage::register('root', $root);
00119 }
00120
00121 return $root;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 public function getRootByIds($ids)
00134 {
00135 $root = Mage::registry('root');
00136 if (null === $root) {
00137 $tree = Mage::getResourceSingleton('catalog/category_tree')
00138 ->loadByIds($ids);
00139 $rootId = Mage_Catalog_Model_Category::TREE_ROOT_ID;
00140 $root = $tree->getNodeById($rootId);
00141 if ($root && $rootId != Mage_Catalog_Model_Category::TREE_ROOT_ID) {
00142 $root->setIsVisible(true);
00143 }
00144 elseif($root && $root->getId() == Mage_Catalog_Model_Category::TREE_ROOT_ID) {
00145 $root->setName(Mage::helper('catalog')->__('Root'));
00146 }
00147 Mage::register('root', $root);
00148 }
00149 return $root;
00150 }
00151
00152 public function getNode($parentNodeCategory, $recursionLevel=2)
00153 {
00154 $tree = Mage::getResourceModel('catalog/category_tree');
00155
00156 $nodeId = $parentNodeCategory->getId();
00157 $parentId = $parentNodeCategory->getParentId();
00158
00159 $node = $tree->loadNode($nodeId);
00160 $node->loadChildren($recursionLevel);
00161
00162 if ($node && $nodeId != Mage_Catalog_Model_Category::TREE_ROOT_ID) {
00163 $node->setIsVisible(true);
00164 } elseif($node && $node->getId() == Mage_Catalog_Model_Category::TREE_ROOT_ID) {
00165 $node->setName(Mage::helper('catalog')->__('Root'));
00166 }
00167
00168 $tree->addCollectionData($this->getCategoryCollection());
00169
00170 return $node;
00171 }
00172
00173 public function getSaveUrl(array $args = array())
00174 {
00175 $params = array('_current'=>true);
00176 $params = array_merge($params, $args);
00177 return $this->getUrl('*/*/save', $params);
00178 }
00179
00180 public function getEditUrl()
00181 {
00182 return $this->getUrl("*/catalog_category/edit", array('_current'=>true, 'store'=>null, '_query'=>false, 'id'=>null, 'parent'=>null));
00183 }
00184 }