Public Member Functions | |
saveRel (Mage_Api_Model_Rules $rule) | |
Protected Member Functions | |
_construct () |
Definition at line 27 of file Rules.php.
_construct | ( | ) | [protected] |
Resource initialization
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 29 of file Rules.php.
00029 { 00030 $this->_init('api/rule', 'rule_id'); 00031 }
saveRel | ( | Mage_Api_Model_Rules $ | rule | ) |
Definition at line 33 of file Rules.php.
00033 { 00034 $this->_getWriteAdapter()->beginTransaction(); 00035 00036 try { 00037 $roleId = $rule->getRoleId(); 00038 $this->_getWriteAdapter()->delete($this->getMainTable(), "role_id = {$roleId}"); 00039 $masterResources = Mage::getModel('api/roles')->getResourcesList2D(); 00040 $masterAdmin = false; 00041 if ( $postedResources = $rule->getResources() ) { 00042 foreach ($masterResources as $index => $resName) { 00043 if ( !$masterAdmin ) { 00044 $permission = ( in_array($resName, $postedResources) )? 'allow' : 'deny'; 00045 $this->_getWriteAdapter()->insert($this->getMainTable(), array( 00046 'role_type' => 'G', 00047 'resource_id' => trim($resName, '/'), 00048 'privileges' => '', # FIXME !!! 00049 'assert_id' => 0, 00050 'role_id' => $roleId, 00051 'permission' => $permission 00052 )); 00053 } 00054 if ( $resName == 'all' && $permission == 'allow' ) { 00055 $masterAdmin = true; 00056 } 00057 } 00058 } 00059 00060 $this->_getWriteAdapter()->commit(); 00061 } catch (Mage_Core_Exception $e) { 00062 throw $e; 00063 } catch (Exception $e){ 00064 $this->_getWriteAdapter()->rollBack(); 00065 } 00066 }