]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Subscription_queue.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[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     /* Static get */
18     function staticGet($k,$v=null)
19     { return Memcached_DataObject::staticGet('Subscription_queue',$k,$v); }
20
21     /* Pkey get */
22     function pkeyGet($k)
23     { return Memcached_DataObject::pkeyGet('Subscription_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 subscription requests awaiting moderation.',
32             'fields' => array(
33                 'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
34                 'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile being subscribed to'),
35                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
36             ),
37             'primary key' => array('subscriber', 'subscribed'),
38             'indexes' => array(
39                 'subscription_queue_subscriber_created_idx' => array('subscriber', 'created'),
40                 'subscription_queue_subscribed_created_idx' => array('subscribed', 'created'),
41             ),
42             'foreign keys' => array(
43                 'subscription_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')),
44                 'subscription_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')),
45             )
46         );
47     }
48
49     public static function saveNew(Profile $subscriber, Profile $subscribed)
50     {
51         $rq = new Subscription_queue();
52         $rq->subscriber = $subscriber->id;
53         $rq->subscribed = $subscribed->id;
54         $rq->created = common_sql_now();
55         $rq->insert();
56         return $rq;
57     }
58
59     function exists($subscriber, $other)
60     {
61         $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->id,
62                                                  'subscribed' => $other->id));
63         return (empty($sub)) ? false : true;
64     }
65
66     /**
67      * Complete a pending subscription, as we've got approval of some sort.
68      *
69      * @return Subscription
70      */
71     public function complete()
72     {
73         $subscriber = Profile::staticGet('id', $this->subscriber);
74         $subscribed = Profile::staticGet('id', $this->subscribed);
75         $sub = Subscription::start($subscriber, $subscribed, Subscription::FORCE);
76         if ($sub) {
77             $this->delete();
78         }
79         return $sub;
80     }
81
82     /**
83      * Cancel an outstanding subscription request to the other profile.
84      */
85     public function abort()
86     {
87         $subscriber = Profile::staticGet('id', $this->subscriber);
88         $subscribed = Profile::staticGet('id', $this->subscribed);
89         if (Event::handle('StartCancelSubscription', array($subscriber, $subscribed))) {
90             $this->delete();
91             Event::handle('EndCancelSubscription', array($subscriber, $subscribed));
92         }
93     }
94
95     /**
96      * Send notifications via email etc to group administrators about
97      * this exciting new pending moderation queue item!
98      */
99     public function notify()
100     {
101         $other = Profile::staticGet('id', $this->subscriber);
102         $listenee = User::staticGet('id', $this->subscribed);
103         mail_subscribe_pending_notify_profile($listenee, $other);
104     }
105 }