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 class Mage_Api_Model_Roles extends Mage_Core_Model_Abstract
00028 {
00029 protected function _construct()
00030 {
00031 $this->_init('api/roles');
00032 }
00033
00034 public function update()
00035 {
00036 $this->getResource()->update($this);
00037 return $this;
00038 }
00039
00040 public function getUsersCollection()
00041 {
00042 return Mage::getResourceModel('api/roles_user_collection');
00043 }
00044
00045 public function getResourcesTree()
00046 {
00047 return $this->_buildResourcesArray(null, null, null, null, true);
00048 }
00049
00050 public function getResourcesList()
00051 {
00052 return $this->_buildResourcesArray();
00053 }
00054
00055 public function getResourcesList2D()
00056 {
00057 return $this->_buildResourcesArray(null, null, null, true);
00058 }
00059
00060 public function getRoleUsers()
00061 {
00062 return $this->getResource()->getRoleUsers($this);
00063 }
00064
00065 protected function _buildResourcesArray(Varien_Simplexml_Element $resource=null, $parentName=null, $level=0, $represent2Darray=null, $rawNodes = false, $module = 'adminhtml')
00066 {
00067 static $result;
00068
00069 if (is_null($resource)) {
00070 $resource = Mage::getSingleton('api/config')->getNode('acl/resources');
00071 $resourceName = null;
00072 $level = -1;
00073 } else {
00074 $resourceName = $parentName;
00075 if ($resource->getName()!='title' && $resource->getName()!='sort_order' && $resource->getName() != 'children') {
00076 $resourceName = (is_null($parentName) ? '' : $parentName.'/').$resource->getName();
00077
00078
00079 if ($resource->getAttribute('module')) {
00080 $module = (string)$resource->getAttribute('module');
00081 }
00082
00083 if ($rawNodes) {
00084 $resource->addAttribute("aclpath", $resourceName);
00085 }
00086
00087 $resource->title = Mage::helper($module)->__((string)$resource->title);
00088
00089 if ( is_null($represent2Darray) ) {
00090 $result[$resourceName]['name'] = (string)$resource->title;
00091 $result[$resourceName]['level'] = $level;
00092 } else {
00093 $result[] = $resourceName;
00094 }
00095 }
00096 }
00097
00098 $children = $resource->children();
00099 if (empty($children)) {
00100 if ($rawNodes) {
00101 return $resource;
00102 } else {
00103 return $result;
00104 }
00105 }
00106 foreach ($children as $child) {
00107 $this->_buildResourcesArray($child, $resourceName, $level+1, $represent2Darray, $rawNodes, $module);
00108 }
00109 if ($rawNodes) {
00110 return $resource;
00111 } else {
00112 return $result;
00113 }
00114 }
00115
00116 }