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_Api2
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: * Block for rendering resources list tab
29: *
30: * @category Mage
31: * @package Mage_Api2
32: * @author Magento Core Team <core@magentocommerce.com>
33: * @method Mage_Api2_Model_Acl_Global_Role getRole()
34: * @method Mage_Api2_Block_Adminhtml_Roles_Tab_Resources setRole(Mage_Api2_Model_Acl_Global_Role $role)
35: */
36: class Mage_Api2_Block_Adminhtml_Roles_Tab_Resources extends Mage_Adminhtml_Block_Widget_Form
37: implements Mage_Adminhtml_Block_Widget_Tab_Interface
38: {
39: /**
40: * Role model
41: *
42: * @var Mage_Api2_Model_Acl_Global_Role
43: */
44: protected $_role;
45:
46: /**
47: * Tree model
48: *
49: * @var Mage_Api2_Model_Acl_Global_Rule_Tree
50: */
51: protected $_treeModel = false;
52:
53: /**
54: * Constructor
55: */
56: public function __construct()
57: {
58: parent::__construct();
59:
60: $this->setId('api2_role_section_resources')
61: ->setData('default_dir', Varien_Db_Select::SQL_ASC)
62: ->setData('default_sort', 'sort_order')
63: ->setData('title', Mage::helper('api2')->__('Api Rules Information'))
64: ->setData('use_ajax', true);
65:
66: $this->_treeModel = Mage::getModel(
67: 'api2/acl_global_rule_tree', array('type' => Mage_Api2_Model_Acl_Global_Rule_Tree::TYPE_PRIVILEGE)
68: );
69: }
70:
71: /**
72: * Get Json Representation of Resource Tree
73: *
74: * @return string
75: */
76: public function getResTreeJson()
77: {
78: $this->_prepareTreeModel();
79: /** @var $helper Mage_Core_Helper_Data */
80: $helper = Mage::helper('core');
81: return $helper->jsonEncode($this->_treeModel->getTreeResources());
82: }
83:
84: /**
85: * Prepare tree model
86: *
87: * @return Mage_Api2_Block_Adminhtml_Roles_Tab_Resources
88: */
89: public function _prepareTreeModel()
90: {
91: $role = $this->getRole();
92: if ($role) {
93: $permissionModel = $role->getPermissionModel();
94: $permissionModel->setFilterValue($role);
95: $this->_treeModel->setResourcesPermissions($permissionModel->getResourcesPermissions());
96: } else {
97: $role = Mage::getModel('api2/acl_global_role');
98: }
99: $this->_treeModel->setRole($role);
100: return $this;
101: }
102:
103: /**
104: * Check if everything is allowed
105: *
106: * @return boolean
107: */
108: public function getEverythingAllowed()
109: {
110: $this->_prepareTreeModel();
111: return $this->_treeModel->getEverythingAllowed();
112: }
113:
114: /**
115: * Get tab label
116: *
117: * @return string
118: */
119: public function getTabLabel()
120: {
121: return Mage::helper('api2')->__('Role API Resources');
122: }
123:
124: /**
125: * Get tab title
126: *
127: * @return string
128: */
129: public function getTabTitle()
130: {
131: return $this->getTabLabel();
132: }
133:
134: /**
135: * Whether tab is available
136: *
137: * @return bool
138: */
139: public function canShowTab()
140: {
141: return true;
142: }
143:
144: /**
145: * Whether tab is hidden
146: *
147: * @return bool
148: */
149: public function isHidden()
150: {
151: return false;
152: }
153: }
154: