コード例 #1
0
ファイル: Permission.php プロジェクト: villos/tree_admin
 /**
  * Store user rights per account
  *
  * @param array $aPermissions  Array of permission IDs
  * @param integer $accountId  account ID
  * @param integer $userId  user ID
  * @param array $aAllowedPermissions  Array of allowed permissions - keys of array are permissions IDs
  * @return true on success else false
  */
 function storeUserAccountsPermissions($aPermissions, $accountId = null, $userId = null, $aAllowedPermissions = null)
 {
     if (empty($userId)) {
         $userId = OA_Permission::getUserId();
     }
     if (empty($accountId)) {
         $accountId = OA_Permission::getAccountId();
     }
     OA_Permission::deleteExistingPermissions($accountId, $userId, $aAllowedPermissions);
     // add new permissions
     foreach ($aPermissions as $permissionId) {
         if (!is_null($aAllowedPermissions) && !isset($aAllowedPermissions[$permissionId])) {
             // check if permission is on the list of allowed permissions
             continue;
         }
         $doAccount_user_permission_assoc = OA_Dal::factoryDO('account_user_permission_assoc');
         $doAccount_user_permission_assoc->account_id = $accountId;
         $doAccount_user_permission_assoc->user_id = $userId;
         $doAccount_user_permission_assoc->permission_id = $permissionId;
         $doAccount_user_permission_assoc->is_allowed = 1;
         if (!$doAccount_user_permission_assoc->insert()) {
             return false;
         }
     }
     return true;
 }