Mage_Adminhtml_Block_Catalog_Category_Tree Class Reference

Inheritance diagram for Mage_Adminhtml_Block_Catalog_Category_Tree:

Mage_Adminhtml_Block_Catalog_Category_Abstract Mage_Adminhtml_Block_Template Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object Mage_Adminhtml_Block_Catalog_Category_Checkboxes_Tree Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Categories

List of all members.

Public Member Functions

 __construct ()
 getCategoryCollection ()
 getAddRootButtonHtml ()
 getAddSubButtonHtml ()
 getExpandButtonHtml ()
 getCollapseButtonHtml ()
 getStoreSwitcherHtml ()
 getLoadTreeUrl ($expanded=null)
 getNodesUrl ()
 getSwitchTreeUrl ()
 getIsWasExpanded ()
 getMoveUrl ()
 getTree ($parenNodeCategory=null)
 getTreeJson ($parenNodeCategory=null)
 getRootIds ()
 getBreadcrumbsJavascript ($path, $javascriptVarName)
 buildNodeName ($node)
 isClearEdit ()
 canAddRootCategory ()
 canAddSubCategory ()

Protected Member Functions

 _prepareLayout ()
 _getDefaultStoreId ()
 _getNodeJson ($node, $level=0)
 _isCategoryMoveable ($node)
 _isParentSelectedCategory ($node)

Protected Attributes

 $_withProductCount


Detailed Description

Definition at line 35 of file Tree.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes

Reimplemented from Mage_Adminhtml_Block_Catalog_Category_Abstract.

Reimplemented in Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Categories.

Definition at line 40 of file Tree.php.

00041     {
00042         parent::__construct();
00043         $this->setTemplate('catalog/category/tree.phtml');
00044         $this->setUseAjax(true);
00045         $this->_withProductCount = true;
00046     }


Member Function Documentation

_getDefaultStoreId (  )  [protected]

Definition at line 87 of file Tree.php.

00088     {
00089         return Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID;
00090     }

_getNodeJson ( node,
level = 0 
) [protected]

Get JSON of a tree node or an associative array

Parameters:
Varien_Data_Tree_Node|array $node
int $level
Returns:
string

Reimplemented in Mage_Adminhtml_Block_Catalog_Category_Checkboxes_Tree, and Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Categories.

Definition at line 226 of file Tree.php.

00227     {
00228         // create a node from data array
00229         if (is_array($node)) {
00230             $node = new Varien_Data_Tree_Node($node, 'entity_id', new Varien_Data_Tree);
00231         }
00232 
00233         $item = array();
00234         $item['text'] = $this->buildNodeName($node);
00235 
00236         //$rootForStores = Mage::getModel('core/store')->getCollection()->loadByCategoryIds(array($node->getEntityId()));
00237         $rootForStores = in_array($node->getEntityId(), $this->getRootIds());
00238 
00239         $item['id']  = $node->getId();
00240         $item['store']  = (int) $this->getStore()->getId();
00241         $item['path'] = $node->getData('path');
00242 
00243         $item['cls'] = 'folder ' . ($node->getIsActive() ? 'active-category' : 'no-active-category');
00244         //$item['allowDrop'] = ($level<3) ? true : false;
00245         $allowMove = $this->_isCategoryMoveable($node);
00246         $item['allowDrop'] = $allowMove;
00247         // disallow drag if it's first level and category is root of a store
00248         $item['allowDrag'] = $allowMove && (($node->getLevel()==1 && $rootForStores) ? false : true);
00249 
00250         if ((int)$node->getChildrenCount()>0) {
00251             $item['children'] = array();
00252         }
00253 
00254         $isParent = $this->_isParentSelectedCategory($node);
00255 
00256         if ($node->hasChildren()) {
00257             $item['children'] = array();
00258             if (!($this->getUseAjax() && $node->getLevel() > 1 && !$isParent)) {
00259                 foreach ($node->getChildren() as $child) {
00260                     $item['children'][] = $this->_getNodeJson($child, $level+1);
00261                 }
00262             }
00263         }
00264 
00265         if ($isParent || $node->getLevel() < 2) {
00266             $item['expanded'] = true;
00267         }
00268 
00269         return $item;
00270     }

_isCategoryMoveable ( node  )  [protected]

Definition at line 287 of file Tree.php.

00288     {
00289         $options = new Varien_Object(array(
00290             'is_moveable' => true,
00291             'category' => $node
00292         ));
00293 
00294         Mage::dispatchEvent('adminhtml_catalog_category_tree_is_moveable',
00295             array('options'=>$options)
00296         );
00297 
00298         return $options->getIsMoveable();
00299     }

_isParentSelectedCategory ( node  )  [protected]

Reimplemented in Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Categories.

Definition at line 301 of file Tree.php.

00302     {
00303         if ($node && $this->getCategory()) {
00304             $pathIds = $this->getCategory()->getPathIds();
00305             if (in_array($node->getId(), $pathIds)) {
00306                 return true;
00307             }
00308         }
00309 
00310         return false;
00311     }

_prepareLayout (  )  [protected]

Preparing global layout

You can redefine this method in child classes for changin layout

Returns:
Mage_Core_Block_Abstract

Reimplemented from Mage_Core_Block_Abstract.

Reimplemented in Mage_Adminhtml_Block_Catalog_Category_Checkboxes_Tree.

Definition at line 48 of file Tree.php.

00049     {
00050         $addUrl = $this->getUrl("*/*/add", array(
00051             '_current'=>true,
00052             'id'=>null,
00053             '_query' => false
00054         ));
00055 
00056         if ($this->canAddSubCategory()) {
00057             $this->setChild('add_sub_button',
00058                 $this->getLayout()->createBlock('adminhtml/widget_button')
00059                     ->setData(array(
00060                         'label'     => Mage::helper('catalog')->__('Add Subcategory'),
00061                         'onclick'   => "addNew('".$addUrl."', false)",
00062                         'class'     => 'add'
00063                     ))
00064             );
00065         }
00066 
00067         if ($this->canAddRootCategory()) {
00068             $this->setChild('add_root_button',
00069                 $this->getLayout()->createBlock('adminhtml/widget_button')
00070                     ->setData(array(
00071                         'label'     => Mage::helper('catalog')->__('Add Root Category'),
00072                         'onclick'   => "addNew('".$addUrl."', true)",
00073                         'class'     => 'add',
00074                         'id'        => 'add_root_category_button'
00075                     ))
00076             );
00077         }
00078 
00079         $this->setChild('store_switcher',
00080             $this->getLayout()->createBlock('adminhtml/store_switcher')
00081                 ->setSwitchUrl($this->getUrl('*/*/*', array('_current'=>true, '_query'=>false, 'store'=>null)))
00082                 ->setTemplate('store/switcher/enhanced.phtml')
00083         );
00084         return parent::_prepareLayout();
00085     }

buildNodeName ( node  ) 

Get category name

Parameters:
Varien_Object $node
Returns:
string

Definition at line 278 of file Tree.php.

00279     {
00280         $result = $this->htmlEscape($node->getName());
00281         if ($this->_withProductCount) {
00282              $result .= ' (' . $node->getProductCount() . ')';
00283         }
00284         return $result;
00285     }

canAddRootCategory (  ) 

Check availability of adding root category

Returns:
boolean

Definition at line 328 of file Tree.php.

00329     {
00330         $options = new Varien_Object(array('is_allow'=>true));
00331         Mage::dispatchEvent(
00332             'adminhtml_catalog_category_tree_can_add_root_category',
00333             array(
00334                 'category' => $this->getCategory(),
00335                 'options'   => $options,
00336                 'store'    => $this->getStore()->getId()
00337             )
00338         );
00339 
00340         return $options->getIsAllow();
00341     }

canAddSubCategory (  ) 

Check availability of adding sub category

Returns:
boolean

Definition at line 348 of file Tree.php.

00349     {
00350         $options = new Varien_Object(array('is_allow'=>true));
00351         Mage::dispatchEvent(
00352             'adminhtml_catalog_category_tree_can_add_sub_category',
00353             array(
00354                 'category' => $this->getCategory(),
00355                 'options'   => $options,
00356                 'store'    => $this->getStore()->getId()
00357             )
00358         );
00359 
00360         return $options->getIsAllow();
00361     }

getAddRootButtonHtml (  ) 

Definition at line 111 of file Tree.php.

00112     {
00113         return $this->getChildHtml('add_root_button');
00114     }

getAddSubButtonHtml (  ) 

Definition at line 116 of file Tree.php.

00117     {
00118         return $this->getChildHtml('add_sub_button');
00119     }

getBreadcrumbsJavascript ( path,
javascriptVarName 
)

Get JSON of array of categories, that are breadcrumbs for specified category path

Parameters:
string $path
string $javascriptVarName
Returns:
string

Definition at line 201 of file Tree.php.

00202     {
00203         if (empty($path)) {
00204             return '';
00205         }
00206         $categories = Mage::getResourceSingleton('catalog/category_tree')->loadBreadcrumbsArray($path);
00207         if (empty($categories)) {
00208             return '';
00209         }
00210         foreach ($categories as $key => $category) {
00211             $categories[$key] = $this->_getNodeJson($category);
00212         }
00213         return
00214             '<script type="text/javascript">'
00215             . $javascriptVarName . ' = ' . Zend_Json::encode($categories) . ';'
00216             . '</script>';
00217     }

getCategoryCollection (  ) 

Definition at line 92 of file Tree.php.

00093     {
00094         $storeId = $this->getRequest()->getParam('store', $this->_getDefaultStoreId());
00095         $collection = $this->getData('category_collection');
00096         if (is_null($collection)) {
00097             $collection = Mage::getModel('catalog/category')->getCollection();
00098 
00099             /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
00100             $collection->addAttributeToSelect('name')
00101                 ->addAttributeToSelect('is_active')
00102                 ->setProductStoreId($storeId)
00103                 ->setLoadProductCount($this->_withProductCount)
00104                 ->setStoreId($storeId);
00105 
00106             $this->setData('category_collection', $collection);
00107         }
00108         return $collection;
00109     }

getCollapseButtonHtml (  ) 

Definition at line 126 of file Tree.php.

00127     {
00128         return $this->getChildHtml('collapse_button');
00129     }

getExpandButtonHtml (  ) 

Definition at line 121 of file Tree.php.

00122     {
00123         return $this->getChildHtml('expand_button');
00124     }

getIsWasExpanded (  ) 

Definition at line 157 of file Tree.php.

00158     {
00159         return Mage::getSingleton('admin/session')->getIsTreeWasExpanded();
00160     }

getLoadTreeUrl ( expanded = null  ) 

Reimplemented in Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Categories.

Definition at line 136 of file Tree.php.

00137     {
00138         $params = array('_current'=>true, 'id'=>null,'store'=>null);
00139         if (
00140             (is_null($expanded) && Mage::getSingleton('admin/session')->getIsTreeWasExpanded())
00141             || $expanded == true) {
00142             $params['expand_all'] = true;
00143         }
00144         return $this->getUrl('*/*/categoriesJson', $params);
00145     }

getMoveUrl (  ) 

Definition at line 162 of file Tree.php.

00163     {
00164         return $this->getUrl('*/catalog_category/move', array('store'=>$this->getRequest()->getParam('store')));
00165     }

getNodesUrl (  ) 

Definition at line 147 of file Tree.php.

00148     {
00149         return $this->getUrl('*/catalog_category/jsonTree');
00150     }

getRootIds (  ) 

Definition at line 181 of file Tree.php.

00182     {
00183         $ids = $this->getData('root_ids');
00184         if (is_null($ids)) {
00185             $ids = array();
00186             foreach (Mage::app()->getStores() as $store) {
00187                 $ids[] = $store->getRootCategoryId();
00188             }
00189             $this->setData('root_ids', $ids);
00190         }
00191         return $ids;
00192     }

getStoreSwitcherHtml (  ) 

Definition at line 131 of file Tree.php.

00132     {
00133         return $this->getChildHtml('store_switcher');
00134     }

getSwitchTreeUrl (  ) 

Definition at line 152 of file Tree.php.

00153     {
00154         return $this->getUrl("*/catalog_category/tree", array('_current'=>true, 'store'=>null, '_query'=>false, 'id'=>null, 'parent'=>null));
00155     }

getTree ( parenNodeCategory = null  ) 

Definition at line 167 of file Tree.php.

00168     {
00169         $rootArray = $this->_getNodeJson($this->getRoot($parenNodeCategory));
00170         $tree = isset($rootArray['children']) ? $rootArray['children'] : array();
00171         return $tree;
00172     }

getTreeJson ( parenNodeCategory = null  ) 

Definition at line 174 of file Tree.php.

00175     {
00176         $rootArray = $this->_getNodeJson($this->getRoot($parenNodeCategory));
00177         $json = Zend_Json::encode(isset($rootArray['children']) ? $rootArray['children'] : array());
00178         return $json;
00179     }

isClearEdit (  ) 

Check if page loaded by outside link to category edit

Returns:
boolean

Definition at line 318 of file Tree.php.

00319     {
00320         return (bool) $this->getRequest()->getParam('clear');
00321     }


Member Data Documentation

$_withProductCount [protected]

Definition at line 38 of file Tree.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:22:43 2009 for Magento by  doxygen 1.5.8