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)
$groups[] = $this->getAccountId();
$teams = $this->db->GetCol("\n SELECT id FROM account_teams\n WHERE name IN(" . join(',', array_fill(0, count($groups) - 1, '?')) . ") AND account_id = ?\n ", $groups);
//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);
}
}