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 class Mage_Adminhtml_Block_Catalog_Category_Checkboxes_Tree extends Mage_Adminhtml_Block_Catalog_Category_Tree
00033 {
00034 protected $_selectedIds = array();
00035
00036 protected function _prepareLayout()
00037 {
00038 $this->setTemplate('catalog/category/checkboxes/tree.phtml');
00039 }
00040
00041 public function getCategoryIds()
00042 {
00043 return $this->_selectedIds;
00044 }
00045
00046 public function setCategoryIds($ids)
00047 {
00048 if (empty($ids)) {
00049 $ids = array();
00050 }
00051 elseif (!is_array($ids)) {
00052 $ids = array((int)$ids);
00053 }
00054 $this->_selectedIds = $ids;
00055 return $this;
00056 }
00057
00058 protected function _getNodeJson($node, $level = 1)
00059 {
00060 $item = array();
00061 $item['text']= $this->htmlEscape($node->getName());
00062
00063 if ($this->_withProductCount) {
00064 $item['text'].= ' ('.$node->getProductCount().')';
00065 }
00066 $item['id'] = $node->getId();
00067 $item['path'] = $node->getData('path');
00068 $item['cls'] = 'folder ' . ($node->getIsActive() ? 'active-category' : 'no-active-category');
00069 $item['allowDrop'] = false;
00070 $item['allowDrag'] = false;
00071
00072 if ($node->hasChildren()) {
00073 $item['children'] = array();
00074 foreach ($node->getChildren() as $child) {
00075 $item['children'][] = $this->_getNodeJson($child, $level + 1);
00076 }
00077 }
00078
00079 if (empty($item['children']) && (int)$node->getChildrenCount() > 0) {
00080 $item['children'] = array();
00081 }
00082
00083 if (!empty($item['children'])) {
00084 $item['expanded'] = true;
00085 }
00086
00087 if (in_array($node->getId(), $this->getCategoryIds())) {
00088 $item['checked'] = true;
00089 }
00090
00091 return $item;
00092 }
00093
00094 public function getRoot($parentNodeCategory=null, $recursionLevel=3)
00095 {
00096 return $this->getRootByIds($this->getCategoryIds());
00097 }
00098 }