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

applyLdapGroups() public method

Special method for LDAP auth sync LDAP groups to Scalr groups
public applyLdapGroups ( $groups )
$groups
    public function applyLdapGroups($groups)
    {
        // get current teams
        $currentTeamIds = array();
        foreach ($this->getTeams() as $t) {
            $currentTeamIds[$t['id']] = $t['name'];
        }
        if (count($groups)) {
            // create all links between LDAP user and teams ( == LDAP group)
            $inputVars = $groups;
            $inputVars[] = $this->getAccountId();
            $teams = $this->db()->GetCol("\n                SELECT id\n                FROM account_teams\n                WHERE name IN(" . join(',', array_fill(0, count($groups), '?')) . ")\n                    AND account_id = ?", $inputVars);
            // team exists in DB, so we can save link
            foreach ($teams as $id) {
                $team = new Scalr_Account_Team();
                $team->loadById($id);
                if (!$team->isTeamUser($this->id)) {
                    $team->addUser($this->id);
                }
                unset($currentTeamIds[$id]);
            }
        }
        // remove old teams
        foreach ($currentTeamIds as $id => $name) {
            $team = new Scalr_Account_Team();
            $team->loadById($id);
            $team->removeUser($this->id);
        }
    }