summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-06-14 23:37:24 -0700
committerEvan Prodromou <evan@controlyourself.ca>2009-06-14 23:37:24 -0700
commitecbd7718d57fc427d2aeac885d8be0321b3cf1fe (patch)
treef7cdd06b431c78c9a8bdbe3b3355c0ef67ba49b3 /classes
parent09c765f5bbc5a96415b82fe6a7d550d590d90747 (diff)
Code for adding and saving group aliases
Added code to add and save group aliases. Like tags, aliases are free-texted in to the group admin page. configurable max number of aliases, default is three.
Diffstat (limited to 'classes')
-rw-r--r--classes/User_group.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/classes/User_group.php b/classes/User_group.php
index 9f9977755..0fcfee8c6 100644
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -165,4 +165,64 @@ 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;
+ }
}