]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Subscription_queue.php
Get group attentions back into the "all" feed
[quix0rs-gnu-social.git] / classes / Subscription_queue.php
1 <?php
2 /**
3  * Table Definition for subscription_queue
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Subscription_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 = 'subscription_queue';       // table name
13     public $subscriber;
14     public $subscribed;
15     public $created;
16
17     /* the code above is auto generated do not remove the tag below */
18     ###END_AUTOCODE
19
20     public static function schemaDef()
21     {
22         return array(
23             'description' => 'Holder for subscription requests awaiting moderation.',
24             'fields' => array(
25                 'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
26                 'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile being subscribed to'),
27                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
28             ),
29             'primary key' => array('subscriber', 'subscribed'),
30             'indexes' => array(
31                 'subscription_queue_subscriber_created_idx' => array('subscriber', 'created'),
32                 'subscription_queue_subscribed_created_idx' => array('subscribed', 'created'),
33             ),
34             'foreign keys' => array(
35                 'subscription_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')),
36                 'subscription_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')),
37             )
38         );
39     }
40
41     public static function saveNew(Profile $subscriber, Profile $subscribed)
42     {
43         $rq = new Subscription_queue();
44         $rq->subscriber = $subscriber->id;
45         $rq->subscribed = $subscribed->id;
46         $rq->created = common_sql_now();
47         $rq->insert();
48         return $rq;
49     }
50
51     function exists($subscriber, $other)
52     {
53         $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->id,
54                                                  'subscribed' => $other->id));
55         return (empty($sub)) ? false : true;
56     }
57
58     /**
59      * Complete a pending subscription, as we've got approval of some sort.
60      *
61      * @return Subscription
62      */
63     public function complete()
64     {
65         $subscriber = Profile::getKV('id', $this->subscriber);
66         $subscribed = Profile::getKV('id', $this->subscribed);
67         $sub = Subscription::start($subscriber, $subscribed, Subscription::FORCE);
68         if ($sub) {
69             $this->delete();
70         }
71         return $sub;
72     }
73
74     /**
75      * Cancel an outstanding subscription request to the other profile.
76      */
77     public function abort()
78     {
79         $subscriber = Profile::getKV('id', $this->subscriber);
80         $subscribed = Profile::getKV('id', $this->subscribed);
81         if (Event::handle('StartCancelSubscription', array($subscriber, $subscribed))) {
82             $this->delete();
83             Event::handle('EndCancelSubscription', array($subscriber, $subscribed));
84         }
85     }
86
87     /**
88      * Send notifications via email etc to group administrators about
89      * this exciting new pending moderation queue item!
90      */
91     public function notify()
92     {
93         $other = Profile::getKV('id', $this->subscriber);
94         $listenee = User::getKV('id', $this->subscribed);
95         mail_subscribe_pending_notify_profile($listenee, $other);
96     }
97 }