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
19 { return Memcached_DataObject::pkeyGet('Subscription_queue',$k); }
21 /* the code above is auto generated do not remove the tag below */
24 public static function schemaDef()
27 'description' => 'Holder for subscription requests awaiting moderation.',
29 'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
30 'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile being subscribed to'),
31 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
33 'primary key' => array('subscriber', 'subscribed'),
35 'subscription_queue_subscriber_created_idx' => array('subscriber', 'created'),
36 'subscription_queue_subscribed_created_idx' => array('subscribed', 'created'),
38 'foreign keys' => array(
39 'subscription_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')),
40 'subscription_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')),
45 public static function saveNew(Profile $subscriber, Profile $subscribed)
47 $rq = new Subscription_queue();
48 $rq->subscriber = $subscriber->id;
49 $rq->subscribed = $subscribed->id;
50 $rq->created = common_sql_now();
55 function exists($subscriber, $other)
57 $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->id,
58 'subscribed' => $other->id));
59 return (empty($sub)) ? false : true;
63 * Complete a pending subscription, as we've got approval of some sort.
65 * @return Subscription
67 public function complete()
69 $subscriber = Profile::staticGet('id', $this->subscriber);
70 $subscribed = Profile::staticGet('id', $this->subscribed);
71 $sub = Subscription::start($subscriber, $subscribed, Subscription::FORCE);
79 * Cancel an outstanding subscription request to the other profile.
81 public function abort()
83 $subscriber = Profile::staticGet('id', $this->subscriber);
84 $subscribed = Profile::staticGet('id', $this->subscribed);
85 if (Event::handle('StartCancelSubscription', array($subscriber, $subscribed))) {
87 Event::handle('EndCancelSubscription', array($subscriber, $subscribed));
92 * Send notifications via email etc to group administrators about
93 * this exciting new pending moderation queue item!
95 public function notify()
97 $other = Profile::staticGet('id', $this->subscriber);
98 $listenee = User::staticGet('id', $this->subscribed);
99 mail_subscribe_pending_notify_profile($listenee, $other);