3 * Table Definition for group_member
6 class Group_member extends Memcached_DataObject
9 /* the code below is auto generated do not remove the above tag */
11 public $__table = 'group_member'; // table name
12 public $group_id; // int(4) primary_key not_null
13 public $profile_id; // int(4) primary_key not_null
14 public $is_admin; // tinyint(1)
15 public $created; // datetime() not_null
16 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
19 function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Group_member',$k,$v); }
21 /* the code above is auto generated do not remove the tag below */
26 return Memcached_DataObject::pkeyGet('Group_member', $kv);
29 static function join($group_id, $profile_id)
31 $member = new Group_member();
33 $member->group_id = $group_id;
34 $member->profile_id = $profile_id;
35 $member->created = common_sql_now();
37 $result = $member->insert();
40 common_log_db_error($member, 'INSERT', __FILE__);
41 // TRANS: Exception thrown when joining a group fails.
42 throw new Exception(_("Group join failed."));
48 static function leave($group_id, $profile_id)
50 $member = Group_member::pkeyGet(array('group_id' => $group_id,
51 'profile_id' => $profile_id));
54 // TRANS: Exception thrown when trying to leave a group the user is not a member of.
55 throw new Exception(_("Not part of group."));
58 $result = $member->delete();
61 common_log_db_error($member, 'INSERT', __FILE__);
62 // TRANS: Exception thrown when trying to leave a group fails.
63 throw new Exception(_("Group leave failed."));
71 $member = Profile::staticGet('id', $this->profile_id);
74 // TRANS: Exception thrown providing an invalid profile ID.
75 // TRANS: %s is the invalid profile ID.
76 throw new Exception(sprintf(_("Profile ID %s is invalid."),$this->profile_id));
84 $group = User_group::staticGet('id', $this->group_id);
87 // TRANS: Exception thrown providing an invalid group ID.
88 // TRANS: %s is the invalid group ID.
89 throw new Exception(sprintf(_("Group ID %s is invalid."),$this->group_id));
97 $member = $this->getMember();
98 $group = $this->getGroup();
100 $act = new Activity();
102 $act->id = TagURI::mint('join:%d:%d:%s',
105 common_date_iso8601($this->created));
107 $act->actor = ActivityObject::fromProfile($member);
108 $act->verb = ActivityVerb::JOIN;
109 $act->objects[] = ActivityObject::fromGroup($group);
111 $act->time = strtotime($this->created);
112 // TRANS: Activity title.
113 $act->title = _("Join");
115 // TRANS: Success message for subscribe to group attempt through OStatus.
116 // TRANS: %1$s is the member name, %2$s is the subscribed group's name.
117 $act->content = sprintf(_('%1$s has joined group %2$s.'),
118 $member->getBestName(),
119 $group->getBestName());