3 * Table Definition for request_queue
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Group_join_queue extends Managed_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'group_join_queue'; // table name
17 /* the code above is auto generated do not remove the tag below */
20 public static function schemaDef()
23 'description' => 'Holder for group join requests awaiting moderation.',
25 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
26 'group_id' => array('type' => 'int', 'description' => 'remote or local group to join, if any'),
27 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
29 'primary key' => array('profile_id', 'group_id'),
31 'group_join_queue_profile_id_created_idx' => array('profile_id', 'created'),
32 'group_join_queue_group_id_created_idx' => array('group_id', 'created'),
34 'foreign keys' => array(
35 'group_join_queue_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
36 'group_join_queue_group_id_fkey' => array('user_group', array('group_id' => 'id')),
41 public static function saveNew(Profile $profile, User_group $group)
43 $rq = new Group_join_queue();
44 $rq->profile_id = $profile->id;
45 $rq->group_id = $group->id;
46 $rq->created = common_sql_now();
53 $member = Profile::getKV('id', $this->profile_id);
56 // TRANS: Exception thrown providing an invalid profile ID.
57 // TRANS: %s is the invalid profile ID.
58 throw new Exception(sprintf(_('Profile ID %s is invalid.'),$this->profile_id));
66 $group = User_group::getKV('id', $this->group_id);
69 // TRANS: Exception thrown providing an invalid group ID.
70 // TRANS: %s is the invalid group ID.
71 throw new Exception(sprintf(_('Group ID %s is invalid.'),$this->group_id));
78 * Abort the pending group join...
80 * @param User_group $group
84 $profile = $this->getMember();
85 $group = $this->getGroup();
87 if (Event::handle('StartCancelJoinGroup', array($profile, $group))) {
89 Event::handle('EndCancelJoinGroup', array($profile, $group));
95 * Complete a pending group join...
97 * @return Group_member object on success
102 $profile = $this->getMember();
103 $group = $this->getGroup();
104 if (Event::handle('StartJoinGroup', array($profile, $group))) {
105 $join = Group_member::join($group->id, $profile->id);
107 Event::handle('EndJoinGroup', array($profile, $group));
110 throw new Exception('Internal error: group join failed.');
117 * Send notifications via email etc to group administrators about
118 * this exciting new pending moderation queue item!
120 public function notify()
122 $joiner = Profile::getKV('id', $this->profile_id);
123 $group = User_group::getKV('id', $this->group_id);
124 mail_notify_group_join_pending($group, $joiner);