1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50:
51: class Mage_Api_Model_Roles extends Mage_Core_Model_Abstract
52: {
53: 54: 55: 56: 57:
58: protected $_filters;
59:
60:
61: protected function _construct()
62: {
63: $this->_init('api/roles');
64: }
65:
66: public function update()
67: {
68: $this->getResource()->update($this);
69: return $this;
70: }
71:
72: public function getUsersCollection()
73: {
74: return Mage::getResourceModel('api/roles_user_collection');
75: }
76:
77: public function getResourcesTree()
78: {
79: return $this->_buildResourcesArray(null, null, null, null, true);
80: }
81:
82: public function getResourcesList()
83: {
84: return $this->_buildResourcesArray();
85: }
86:
87: public function getResourcesList2D()
88: {
89: return $this->_buildResourcesArray(null, null, null, true);
90: }
91:
92: public function getRoleUsers()
93: {
94: return $this->getResource()->getRoleUsers($this);
95: }
96:
97: protected function _buildResourcesArray(
98: Varien_Simplexml_Element $resource = null, $parentName = null, $level = 0, $represent2Darray = null,
99: $rawNodes = false, $module = 'adminhtml'
100: ) {
101: static $result;
102:
103: if (is_null($resource)) {
104: $resource = Mage::getSingleton('api/config')->getNode('acl/resources');
105: $resourceName = null;
106: $level = -1;
107: } else {
108: $resourceName = $parentName;
109: if ($resource->getName()!='title' && $resource->getName()!='sort_order'
110: && $resource->getName() != 'children'
111: ) {
112: $resourceName = (is_null($parentName) ? '' : $parentName.'/').$resource->getName();
113:
114:
115: if ($resource->getAttribute('module')) {
116: $module = (string)$resource->getAttribute('module');
117: }
118:
119: if ($rawNodes) {
120: $resource->addAttribute("aclpath", $resourceName);
121: }
122:
123: $resource->title = Mage::helper($module)->__((string)$resource->title);
124:
125: if ( is_null($represent2Darray) ) {
126: $result[$resourceName]['name'] = (string)$resource->title;
127: $result[$resourceName]['level'] = $level;
128: } else {
129: $result[] = $resourceName;
130: }
131: }
132: }
133:
134: $children = $resource->children();
135: if (empty($children)) {
136: if ($rawNodes) {
137: return $resource;
138: } else {
139: return $result;
140: }
141: }
142: foreach ($children as $child) {
143: $this->_buildResourcesArray($child, $resourceName, $level+1, $represent2Darray, $rawNodes, $module);
144: }
145: if ($rawNodes) {
146: return $resource;
147: } else {
148: return $result;
149: }
150: }
151:
152: 153: 154: 155: 156:
157: protected function _beforeSave()
158: {
159: $this->filter();
160: parent::_beforeSave();
161: return $this;
162: }
163:
164: 165: 166: 167: 168:
169: public function filter()
170: {
171: $data = $this->getData();
172: if (!$this->_filters || !$data) {
173: return $this;
174: }
175:
176: $filter = Mage::getModel('core/input_filter');
177: $filter->setFilters($this->_filters);
178: $this->setData($filter->filter($data));
179: return $this;
180: }
181: }
182: