Scalr\Acl\Acl::getUserRolesByTeam PHP Method

getUserRolesByTeam() public method

Gets account roles superposition by specified ID of team
public getUserRolesByTeam ( $user, integer $teamId, integer $accountId ) : Scalr\Acl\Role\AccountRoleSuperposition
$teamId integer The ID of the team
$accountId integer The ID of the client's account
return Scalr\Acl\Role\AccountRoleSuperposition Returns the list of the roles of account level by specified team
    public function getUserRolesByTeam($user, $teamId, $accountId)
    {
        $ret = new Role\AccountRoleSuperposition(array());
        if ($user instanceof \Scalr_Account_User) {
            $userId = $user->getId();
            $ret->setUser($user);
        } else {
            $userId = $user;
            $ret->setUser($userId);
        }
        $res = $this->db->Execute("\n            SELECT ar.*\n            FROM `acl_account_roles` ar\n            JOIN `account_team_user_acls` ua ON ua.`account_role_id` = ar.`account_role_id`\n            JOIN `account_team_users` atu ON atu.`id` = ua.`account_team_user_id`\n            WHERE atu.`user_id` = ? AND atu.`team_id` = ? AND ar.`account_id` = ?\n            GROUP BY ar.`account_role_id`\n        ", array($userId, $teamId, $accountId));
        while ($rec = $res->FetchRow()) {
            $role = $this->getAccountRoleByRow($rec);
            $role->setTeamRole(false);
            $ret[$role->getRoleId()] = $role;
        }
        if (!$ret->count()) {
            //User has no roles assigned to this team so we need to use default ACL role for the team
            $res = $this->db->Execute("\n                SELECT ar.*\n                FROM `acl_account_roles` ar\n                JOIN `account_teams` at ON at.account_role_id = ar.account_role_id\n                JOIN `account_team_users` atu ON at.`id` = atu.`team_id`\n                WHERE at.id = ? AND atu.user_id = ? AND at.account_id = ?\n            ", array($teamId, $userId, $accountId));
            while ($rec = $res->FetchRow()) {
                $role = $this->getAccountRoleByRow($rec);
                $role->setTeamRole(true);
                $ret[$role->getRoleId()] = $role;
            }
        }
        return $ret;
    }