Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Admin_Helper_Data
  • Mage_Admin_Model_Acl
  • Mage_Admin_Model_Acl_Assert_Ip
  • Mage_Admin_Model_Acl_Assert_Time
  • Mage_Admin_Model_Acl_Resource
  • Mage_Admin_Model_Acl_Role
  • Mage_Admin_Model_Acl_Role_Generic
  • Mage_Admin_Model_Acl_Role_Group
  • Mage_Admin_Model_Acl_Role_Registry
  • Mage_Admin_Model_Acl_Role_User
  • Mage_Admin_Model_Config
  • Mage_Admin_Model_Mysql4_Acl
  • Mage_Admin_Model_Mysql4_Acl_Role
  • Mage_Admin_Model_Mysql4_Acl_Role_Collection
  • Mage_Admin_Model_Mysql4_Permissions_Collection
  • Mage_Admin_Model_Mysql4_Role
  • Mage_Admin_Model_Mysql4_Role_Collection
  • Mage_Admin_Model_Mysql4_Roles
  • Mage_Admin_Model_Mysql4_Roles_Collection
  • Mage_Admin_Model_Mysql4_Roles_User_Collection
  • Mage_Admin_Model_Mysql4_Rules
  • Mage_Admin_Model_Mysql4_Rules_Collection
  • Mage_Admin_Model_Mysql4_User
  • Mage_Admin_Model_Mysql4_User_Collection
  • Mage_Admin_Model_Observer
  • Mage_Admin_Model_Resource_Acl
  • Mage_Admin_Model_Resource_Acl_Role_Collection
  • Mage_Admin_Model_Resource_Permissions_Collection
  • Mage_Admin_Model_Resource_Role
  • Mage_Admin_Model_Resource_Role_Collection
  • Mage_Admin_Model_Resource_Roles
  • Mage_Admin_Model_Resource_Roles_Collection
  • Mage_Admin_Model_Resource_Roles_User_Collection
  • Mage_Admin_Model_Resource_Rules
  • Mage_Admin_Model_Resource_Rules_Collection
  • Mage_Admin_Model_Resource_User
  • Mage_Admin_Model_Resource_User_Collection
  • Mage_Admin_Model_Role
  • Mage_Admin_Model_Roles
  • Mage_Admin_Model_Rules
  • Mage_Admin_Model_Session
  • Mage_Admin_Model_User
  • Overview
  • Package
  • Class
  • Tree
  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_Admin
 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: /**
 29:  * Admin roles resource model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Admin
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Admin_Model_Resource_Roles extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Users table
 39:      *
 40:      * @var string
 41:      */
 42:     protected $_usersTable;
 43: 
 44:     /**
 45:      * Rule table
 46:      *
 47:      * @var string
 48:      */
 49:     protected $_ruleTable;
 50: 
 51:     /**
 52:      * Define main table
 53:      *
 54:      */
 55:     protected function _construct()
 56:     {
 57:         $this->_init('admin/role', 'role_id');
 58: 
 59:         $this->_usersTable = $this->getTable('admin/user');
 60:         $this->_ruleTable = $this->getTable('admin/rule');
 61:     }
 62: 
 63:     /**
 64:      * Process role before saving
 65:      *
 66:      * @param Mage_Core_Model_Abstract $role
 67:      * @return Mage_Admin_Model_Resource_Roles
 68:      */
 69:     protected function _beforeSave(Mage_Core_Model_Abstract $role)
 70:     {
 71:         if ($role->getId() == '') {
 72:             if ($role->getIdFieldName()) {
 73:                 $role->unsetData($role->getIdFieldName());
 74:             } else {
 75:                 $role->unsetData('id');
 76:             }
 77:         }
 78: 
 79:         if ($role->getPid() > 0) {
 80:             $select = $this->_getReadAdapter()->select()
 81:                 ->from($this->getMainTable(), array('tree_level'))
 82:                 ->where("{$this->getIdFieldName()} = :pid");
 83: 
 84:             $binds = array(
 85:                 'pid' => (int) $role->getPid(),
 86:             );
 87: 
 88:             $treeLevel = $this->_getReadAdapter()->fetchOne($select, $binds);
 89:         } else {
 90:             $treeLevel = 0;
 91:         }
 92:         $role->setTreeLevel($treeLevel + 1);
 93:         $role->setRoleName($role->getName());
 94:         return $this;
 95:     }
 96: 
 97:     /**
 98:      * Process role after saving
 99:      *
100:      * @param Mage_Core_Model_Abstract $role
101:      * @return Mage_Admin_Model_Resource_Roles
102:      */
103:     protected function _afterSave(Mage_Core_Model_Abstract $role)
104:     {
105:         $this->_updateRoleUsersAcl($role);
106:         Mage::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,
107:             array(Mage_Adminhtml_Block_Page_Menu::CACHE_TAGS));
108:         return $this;
109:     }
110: 
111:     /**
112:      * Process role after deleting
113:      *
114:      * @param Mage_Core_Model_Abstract $role
115:      * @return Mage_Admin_Model_Resource_Roles
116:      */
117:     protected function _afterDelete(Mage_Core_Model_Abstract $role)
118:     {
119:         $adapter = $this->_getWriteAdapter();
120: 
121:         $adapter->delete(
122:             $this->getMainTable(),
123:             array('parent_id = ?' => (int) $role->getId())
124:         );
125: 
126:         $adapter->delete(
127:             $this->_ruleTable,
128:             array('role_id = ?' => (int) $role->getId())
129:         );
130: 
131:         return $this;
132:     }
133: 
134:     /**
135:      * Get role users
136:      *
137:      * @param Mage_Admin_Model_Roles $role
138:      * @return array|false
139:      */
140:     public function getRoleUsers(Mage_Admin_Model_Roles $role)
141:     {
142:         $read = $this->_getReadAdapter();
143: 
144:         $binds = array(
145:             'role_id'   => $role->getId(),
146:             'role_type' => 'U'
147:         );
148: 
149:         $select = $read->select()
150:             ->from($this->getMainTable(), array('user_id'))
151:             ->where('parent_id = :role_id')
152:             ->where('role_type = :role_type')
153:             ->where('user_id > 0');
154: 
155:         return $read->fetchCol($select, $binds);
156:     }
157: 
158:     /**
159:      * Update role users ACL
160:      *
161:      * @param Mage_Admin_Model_Roles $role
162:      * @return bool
163:      */
164:     private function _updateRoleUsersAcl(Mage_Admin_Model_Roles $role)
165:     {
166:         $write  = $this->_getWriteAdapter();
167:         $users  = $this->getRoleUsers($role);
168:         $rowsCount = 0;
169: 
170:         if (sizeof($users) > 0) {
171:             $bind  = array('reload_acl_flag' => 1);
172:             $where = array('user_id IN(?)' => $users);
173:             $rowsCount = $write->update($this->_usersTable, $bind, $where);
174:         }
175: 
176:         return $rowsCount > 0;
177:     }
178: }
179: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0