summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-01-13 02:16:13 -0800
committerEvan Prodromou <evan@status.net>2010-01-13 02:16:13 -0800
commit430bd69312a27f9f97bda78566a78c9f7eec1f14 (patch)
treee5f043e4356e8523b0978a9e35cb602af8dbf60b /classes
parent23599da91e9d4abbd6e73ef3f44c58f302a5231a (diff)
add events for subscribing to people and joining groups
Diffstat (limited to 'classes')
-rw-r--r--classes/Group_member.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/classes/Group_member.php b/classes/Group_member.php
index 069b2c7a1..7b1760f76 100644
--- a/classes/Group_member.php
+++ b/classes/Group_member.php
@@ -25,4 +25,41 @@ class Group_member extends Memcached_DataObject
{
return Memcached_DataObject::pkeyGet('Group_member', $kv);
}
+
+ static function join($group_id, $profile_id)
+ {
+ $member = new Group_member();
+
+ $member->group_id = $group_id;
+ $member->profile_id = $profile_id;
+ $member->created = common_sql_now();
+
+ $result = $member->insert();
+
+ if (!$result) {
+ common_log_db_error($member, 'INSERT', __FILE__);
+ throw new Exception(_("Group join failed."));
+ }
+
+ return true;
+ }
+
+ static function leave($group_id, $profile_id)
+ {
+ $member = Group_member::pkeyGet(array('group_id' => $group_id,
+ 'profile_id' => $profile_id));
+
+ if (empty($member)) {
+ throw new Exception(_("Not part of group."));
+ }
+
+ $result = $member->delete();
+
+ if (!$result) {
+ common_log_db_error($member, 'INSERT', __FILE__);
+ throw new Exception(_("Group leave failed."));
+ }
+
+ return true;
+ }
}