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;
}