示例#1
0
 public function removePermission(TBGRolePermission $permission)
 {
     $this->_populatePermissions();
     $permission_id = $permission->getID();
     unset($this->_permissions[$permission_id]);
     TBGPermissionsTable::getTable()->deleteRolePermission($this->getID(), $permission->getPermission(), $permission->getTargetID());
     $permission->delete();
 }
 public function addRolePermission($role_id, TBGRolePermission $rolepermission)
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::ROLE_ID, $role_id);
     $existing_identifiables = array('users' => array(), 'teams' => array());
     if ($res = $this->doSelect($crit)) {
         while ($row = $res->getNextRow()) {
             $key = $row->get(self::UID) ? self::UID : self::TID;
             $existing_identifiables[$key][$row->get($key)] = array('id' => $row->get($key), 'target_id' => $row->get(self::TARGET_ID));
         }
         foreach ($existing_identifiables as $key => $identifiables) {
             foreach ($identifiables as $identifiable) {
                 $crit = $this->getCriteria();
                 $crit->addInsert(self::SCOPE, TBGContext::getScope()->getID());
                 $crit->addInsert(self::PERMISSION_TYPE, $rolepermission->getPermission());
                 $crit->addInsert(self::TARGET_ID, $identifiable['target_id']);
                 $crit->addInsert($key, $identifiable['id']);
                 $crit->addInsert(self::ALLOWED, true);
                 $crit->addInsert(self::MODULE, $rolepermission->getModule());
                 $crit->addInsert(self::ROLE_ID, $role_id);
                 $res = $this->doInsert($crit);
             }
         }
     }
 }