1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Categories tree with checkboxes
29: *
30: * @author Magento Core Team <core@magentocommerce.com>
31: */
32: class Mage_Adminhtml_Block_Catalog_Category_Checkboxes_Tree extends Mage_Adminhtml_Block_Catalog_Category_Tree
33: {
34: protected $_selectedIds = array();
35:
36: protected function _prepareLayout()
37: {
38: $this->setTemplate('catalog/category/checkboxes/tree.phtml');
39: }
40:
41: public function getCategoryIds()
42: {
43: return $this->_selectedIds;
44: }
45:
46: public function setCategoryIds($ids)
47: {
48: if (empty($ids)) {
49: $ids = array();
50: }
51: elseif (!is_array($ids)) {
52: $ids = array((int)$ids);
53: }
54: $this->_selectedIds = $ids;
55: return $this;
56: }
57:
58: protected function _getNodeJson($node, $level = 1)
59: {
60: $item = array();
61: $item['text']= $this->htmlEscape($node->getName());
62:
63: if ($this->_withProductCount) {
64: $item['text'].= ' ('.$node->getProductCount().')';
65: }
66: $item['id'] = $node->getId();
67: $item['path'] = $node->getData('path');
68: $item['cls'] = 'folder ' . ($node->getIsActive() ? 'active-category' : 'no-active-category');
69: $item['allowDrop'] = false;
70: $item['allowDrag'] = false;
71:
72: if ($node->hasChildren()) {
73: $item['children'] = array();
74: foreach ($node->getChildren() as $child) {
75: $item['children'][] = $this->_getNodeJson($child, $level + 1);
76: }
77: }
78:
79: if (empty($item['children']) && (int)$node->getChildrenCount() > 0) {
80: $item['children'] = array();
81: }
82:
83: if (!empty($item['children'])) {
84: $item['expanded'] = true;
85: }
86:
87: if (in_array($node->getId(), $this->getCategoryIds())) {
88: $item['checked'] = true;
89: }
90:
91: return $item;
92: }
93:
94: public function getRoot($parentNodeCategory=null, $recursionLevel=3)
95: {
96: return $this->getRootByIds($this->getCategoryIds());
97: }
98: }
99: