]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Group_join_queue.php
L10n/i18n updated.
[quix0rs-gnu-social.git] / classes / Group_join_queue.php
1 <?php
2 /**
3  * Table Definition for request_queue
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Group_join_queue extends Managed_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'group_join_queue';       // table name
13     public $profile_id;
14     public $group_id;
15     public $created;
16
17     /* Static get */
18     function staticGet($k,$v=null)
19     { return Memcached_DataObject::staticGet('Group_join_queue',$k,$v); }
20
21     /* Pkey get */
22     function pkeyGet($k)
23     { return Memcached_DataObject::pkeyGet('Group_join_queue',$k); }
24
25     /* the code above is auto generated do not remove the tag below */
26     ###END_AUTOCODE
27
28     public static function schemaDef()
29     {
30         return array(
31             'description' => 'Holder for group join requests awaiting moderation.',
32             'fields' => array(
33                 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
34                 'group_id' => array('type' => 'int', 'description' => 'remote or local group to join, if any'),
35                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
36             ),
37             'primary key' => array('profile_id', 'group_id'),
38             'indexes' => array(
39                 'group_join_queue_profile_id_created_idx' => array('profile_id', 'created'),
40                 'group_join_queue_group_id_created_idx' => array('group_id', 'created'),
41             ),
42             'foreign keys' => array(
43                 'group_join_queue_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
44                 'group_join_queue_group_id_fkey' => array('user_group', array('group_id' => 'id')),
45             )
46         );
47     }
48
49     public static function saveNew(Profile $profile, User_group $group)
50     {
51         $rq = new Group_join_queue();
52         $rq->profile_id = $profile->id;
53         $rq->group_id = $group->id;
54         $rq->created = common_sql_now();
55         $rq->insert();
56         return $rq;
57     }
58
59     function getMember()
60     {
61         $member = Profile::staticGet('id', $this->profile_id);
62
63         if (empty($member)) {
64             // TRANS: Exception thrown providing an invalid profile ID.
65             // TRANS: %s is the invalid profile ID.
66             throw new Exception(sprintf(_('Profile ID %s is invalid.'),$this->profile_id));
67         }
68
69         return $member;
70     }
71
72     function getGroup()
73     {
74         $group  = User_group::staticGet('id', $this->group_id);
75
76         if (empty($group)) {
77             // TRANS: Exception thrown providing an invalid group ID.
78             // TRANS: %s is the invalid group ID.
79             throw new Exception(sprintf(_('Group ID %s is invalid.'),$this->group_id));
80         }
81
82         return $group;
83     }
84
85     /**
86      * Abort the pending group join...
87      *
88      * @param User_group $group
89      */
90     function abort()
91     {
92         $profile = $this->getMember();
93         $group = $this->getGroup();
94         if ($request) {
95             if (Event::handle('StartCancelJoinGroup', array($profile, $group))) {
96                 $this->delete();
97                 Event::handle('EndCancelJoinGroup', array($profile, $group));
98             }
99         }
100     }
101
102     /**
103      * Complete a pending group join...
104      *
105      * @return Group_member object on success
106      */
107     function complete(User_group $group)
108     {
109         $join = null;
110         $profile = $this->getMember();
111         $group = $this->getGroup();
112         if (Event::handle('StartJoinGroup', array($profile, $group))) {
113             $join = Group_member::join($group->id, $profile->id);
114             $this->delete();
115             Event::handle('EndJoinGroup', array($profile, $group));
116         }
117         if (!$join) {
118             throw new Exception('Internal error: group join failed.');
119         }
120         $join->notify();
121         return $join;
122     }
123
124     /**
125      * Send notifications via email etc to group administrators about
126      * this exciting new pending moderation queue item!
127      */
128     public function notify()
129     {
130         $joiner = Profile::staticGet('id', $this->profile_id);
131         $group = User_group::staticGet('id', $this->group_id);
132         mail_notify_group_join_pending($group, $joiner);
133     }
134 }