Scalr\Model\Entity\Account\User::getAclRolesByEnvironment PHP Method

getAclRolesByEnvironment() public method

Gets roles by specified identifier of the Environment
public getAclRolesByEnvironment ( integer $envId, boolean $ignoreCache = false ) : Scalr\Acl\Role\AccountRoleSuperposition
$envId integer The identifier of the Environment
$ignoreCache boolean optional Whether it should ignore cache
return Scalr\Acl\Role\AccountRoleSuperposition Returns the list of the roles of account level by specified environment
    public function getAclRolesByEnvironment($envId, $ignoreCache = false)
    {
        $cid = 'roles.env';
        if (!isset($this->_cache[$cid][$envId]) || $ignoreCache) {
            $this->_cache[$cid][$envId] = \Scalr::getContainer()->acl->getUserRolesByEnvironment($this->id, $envId, $this->accountId);
        }
        return $this->_cache[$cid][$envId];
    }

Usage Example

Example #1
0
File: Farm.php Project: scalr/scalr
 /**
  * @param   User            $user           The User Entity
  * @param   Environment     $environment    optional The Environment Entity
  * @param   string|bool     $modify         optional ACL Permission Identifier or boolean flag whether it should check modify
  *                                          permissions or not.
  * @return  bool
  */
 public function hasAccessPermissions($user, $environment = null, $modify = null)
 {
     $access = $environment && $this->envId == $environment->id;
     if (is_bool($modify)) {
         $modify = $modify ? Acl::PERM_FARMS_UPDATE : null;
     }
     if ($access) {
         $superposition = $user->getAclRolesByEnvironment($environment->id);
         $access = $superposition->isAllowed(Acl::RESOURCE_FARMS, $modify);
         if (!$access && $this->hasUserTeamOwnership($user)) {
             $access = $superposition->isAllowed(Acl::RESOURCE_TEAM_FARMS, $modify);
         }
         if (!$access && $this->ownerId && $user->id == $this->ownerId) {
             $access = $superposition->isAllowed(Acl::RESOURCE_OWN_FARMS, $modify);
         }
     }
     return $access;
 }