diff options
author | Evan Prodromou <evan@controlyourself.ca> | 2009-06-14 23:48:24 -0700 |
---|---|---|
committer | Evan Prodromou <evan@controlyourself.ca> | 2009-06-14 23:48:24 -0700 |
commit | 4dad3191f65512b04894377541c4a041221ed9a2 (patch) | |
tree | b5714e21f0a2a04a1af7f1252fff923dbf411aed /classes/User_group.php | |
parent | 2f3c4f8812d389df40cf62b8967cf3e359ad5663 (diff) | |
parent | 1b6b00a6d05ad646a9137a872af8d8fdeeaf260f (diff) |
Merge branch 'groupalias' into 0.8.x
Diffstat (limited to 'classes/User_group.php')
-rw-r--r-- | classes/User_group.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/classes/User_group.php b/classes/User_group.php index 9f9977755..1a24124bb 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -165,4 +165,78 @@ class User_group extends Memcached_DataObject { return ($this->fullname) ? $this->fullname : $this->nickname; } + + function getAliases() + { + $aliases = array(); + + // XXX: cache this + + $alias = new Group_alias(); + + $alias->group_id = $this->id; + + if ($alias->find()) { + while ($alias->fetch()) { + $aliases[] = $alias->alias; + } + } + + $alias->free(); + + return $aliases; + } + + function setAliases($newaliases) { + + $newaliases = array_unique($newaliases); + + $oldaliases = $this->getAliases(); + + # Delete stuff that's old that not in new + + $to_delete = array_diff($oldaliases, $newaliases); + + # Insert stuff that's in new and not in old + + $to_insert = array_diff($newaliases, $oldaliases); + + $alias = new Group_alias(); + + $alias->group_id = $this->id; + + foreach ($to_delete as $delalias) { + $alias->alias = $delalias; + $result = $alias->delete(); + if (!$result) { + common_log_db_error($alias, 'DELETE', __FILE__); + return false; + } + } + + foreach ($to_insert as $insalias) { + $alias->alias = $insalias; + $result = $alias->insert(); + if (!$result) { + common_log_db_error($alias, 'INSERT', __FILE__); + return false; + } + } + + return true; + } + + static function getForNickname($nickname) + { + $nickname = common_canonical_nickname($nickname); + $group = User_group::staticGet('nickname', $nickname); + if (!empty($group)) { + return $group; + } + $alias = Group_alias::staticGet('alias', $nickname); + if (!empty($alias)) { + return User_group::staticGet('id', $alias->group_id); + } + return null; + } } |