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_Mysql4_Rules extends Mage_Core_Model_Mysql4_Abstract
00028 {
00029 protected function _construct() {
00030 $this->_init('api/rule', 'rule_id');
00031 }
00032
00033 public function saveRel(Mage_Api_Model_Rules $rule) {
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 }
00067 }