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