3 * Table Definition for subscription_queue
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Subscription_queue extends Managed_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'subscription_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 subscription requests awaiting moderation.',
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'),
29 'primary key' => array('subscriber', 'subscribed'),
31 'subscription_queue_subscriber_created_idx' => array('subscriber', 'created'),
32 'subscription_queue_subscribed_created_idx' => array('subscribed', 'created'),
34 'foreign keys' => array(
35 'subscription_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')),
36 'subscription_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')),
41 public static function saveNew(Profile $subscriber, Profile $subscribed)
43 $rq = new Subscription_queue();
44 $rq->subscriber = $subscriber->id;
45 $rq->subscribed = $subscribed->id;
46 $rq->created = common_sql_now();
51 function exists($subscriber, $other)
53 $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->id,
54 'subscribed' => $other->id));
55 return (empty($sub)) ? false : true;
59 * Complete a pending subscription, as we've got approval of some sort.
61 * @return Subscription
63 public function complete()
65 $subscriber = Profile::getKV('id', $this->subscriber);
66 $subscribed = Profile::getKV('id', $this->subscribed);
67 $sub = Subscription::start($subscriber, $subscribed, Subscription::FORCE);
75 * Cancel an outstanding subscription request to the other profile.
77 public function abort()
79 $subscriber = Profile::getKV('id', $this->subscriber);
80 $subscribed = Profile::getKV('id', $this->subscribed);
81 if (Event::handle('StartCancelSubscription', array($subscriber, $subscribed))) {
83 Event::handle('EndCancelSubscription', array($subscriber, $subscribed));
88 * Send notifications via email etc to group administrators about
89 * this exciting new pending moderation queue item!
91 public function notify()
93 $other = Profile::getKV('id', $this->subscriber);
94 $listenee = User::getKV('id', $this->subscribed);
95 mail_subscribe_pending_notify_profile($listenee, $other);