Mage_Admin_Model_Mysql4_Acl Class Reference

List of all members.

Public Member Functions

 __construct ()
 loadAcl ()
 loadRoles (Mage_Admin_Model_Acl $acl, array $rolesArr)
 loadRules (Mage_Admin_Model_Acl $acl, array $rulesArr)

Public Attributes

const ACL_ALL_RULES = 'all'

Protected Attributes

 $_read
 $_write


Detailed Description

Definition at line 35 of file Acl.php.


Constructor & Destructor Documentation

__construct (  ) 

Initialize resource connections

Definition at line 57 of file Acl.php.

00058     {
00059         $this->_read = Mage::getSingleton('core/resource')->getConnection('admin_read');
00060         $this->_write = Mage::getSingleton('core/resource')->getConnection('admin_write');
00061     }


Member Function Documentation

loadAcl (  ) 

Load ACL for the user

Parameters:
integer $userId
Returns:
Mage_Admin_Model_Acl

Definition at line 69 of file Acl.php.

00070     {
00071         $acl = Mage::getModel('admin/acl');
00072 
00073         Mage::getSingleton('admin/config')->loadAclResources($acl);
00074 
00075         $roleTable = Mage::getSingleton('core/resource')->getTableName('admin/role');
00076         $rolesArr = $this->_read->fetchAll("select * from $roleTable order by tree_level");
00077         $this->loadRoles($acl, $rolesArr);
00078 
00079         $ruleTable = Mage::getSingleton('core/resource')->getTableName('admin/rule');
00080         $assertTable = Mage::getSingleton('core/resource')->getTableName('admin/assert');
00081         $rulesArr = $this->_read->fetchAll("select r.*, a.assert_type, a.assert_data
00082             from $ruleTable r left join $assertTable a on a.assert_id=r.assert_id");
00083         $this->loadRules($acl, $rulesArr);
00084 
00085         return $acl;
00086     }

loadRoles ( Mage_Admin_Model_Acl acl,
array rolesArr 
)

Load roles

Parameters:
Mage_Admin_Model_Acl $acl
array $rolesArr
Returns:
Mage_Admin_Model_Mysql4_Acl

Definition at line 95 of file Acl.php.

00096     {
00097         foreach ($rolesArr as $role) {
00098             $parent = $role['parent_id']>0 ? Mage_Admin_Model_Acl::ROLE_TYPE_GROUP.$role['parent_id'] : null;
00099             switch ($role['role_type']) {
00100                 case Mage_Admin_Model_Acl::ROLE_TYPE_GROUP:
00101                     $roleId = $role['role_type'].$role['role_id'];
00102                     $acl->addRole(Mage::getModel('admin/acl_role_group', $roleId), $parent);
00103                     break;
00104 
00105                 case Mage_Admin_Model_Acl::ROLE_TYPE_USER:
00106                     $roleId = $role['role_type'].$role['user_id'];
00107                     if (!$acl->hasRole($roleId)) {
00108                         $acl->addRole(Mage::getModel('admin/acl_role_user', $roleId), $parent);
00109                     } else {
00110                         $acl->addRoleParent($roleId, $parent);
00111                     }
00112                     break;
00113             }
00114         }
00115 
00116         return $this;
00117     }

loadRules ( Mage_Admin_Model_Acl acl,
array rulesArr 
)

Load rules

Parameters:
Mage_Admin_Model_Acl $acl
array $rulesArr
Returns:
Mage_Admin_Model_Mysql4_Acl

Definition at line 126 of file Acl.php.

00127     {
00128         foreach ($rulesArr as $rule) {
00129             $role = $rule['role_type'].$rule['role_id'];
00130             $resource = $rule['resource_id'];
00131             $privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null;
00132 
00133             $assert = null;
00134             if (0!=$rule['assert_id']) {
00135                 $assertClass = Mage::getSingleton('admin/config')->getAclAssert($rule['assert_type'])->getClassName();
00136                 $assert = new $assertClass(unserialize($rule['assert_data']));
00137             }
00138             try {
00139                 if ( $rule['permission'] == 'allow' ) {
00140                     if ($resource === self::ACL_ALL_RULES) {
00141                         $acl->allow($role, null, $privileges, $assert);
00142                     }
00143                     $acl->allow($role, $resource, $privileges, $assert);
00144                 } else if ( $rule['permission'] == 'deny' ) {
00145                     $acl->deny($role, $resource, $privileges, $assert);
00146                 }
00147             } catch (Exception $e) {
00148                 //$m = $e->getMessage();
00149                 //if ( eregi("^Resource '(.*)' not found", $m) ) {
00150                     // Deleting non existent resource rule from rules table
00151                     //$cond = $this->_write->quoteInto('resource_id = ?', $resource);
00152                     //$this->_write->delete(Mage::getSingleton('core/resource')->getTableName('admin/rule'), $cond);
00153                 //} else {
00154                     //TODO: We need to log such exceptions to somewhere like a system/errors.log
00155                 //}
00156             }
00157             /*
00158             switch ($rule['permission']) {
00159                 case Mage_Admin_Model_Acl::RULE_PERM_ALLOW:
00160                     $acl->allow($role, $resource, $privileges, $assert);
00161                     break;
00162 
00163                 case Mage_Admin_Model_Acl::RULE_PERM_DENY:
00164                     $acl->deny($role, $resource, $privileges, $assert);
00165                     break;
00166             }
00167             */
00168         }
00169         return $this;
00170     }


Member Data Documentation

$_read [protected]

Definition at line 44 of file Acl.php.

$_write [protected]

Definition at line 51 of file Acl.php.

const ACL_ALL_RULES = 'all'

Definition at line 37 of file Acl.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:22:41 2009 for Magento by  doxygen 1.5.8