Work in progress: can create & cancel sub requests

This commit is contained in:
Brion Vibber 2011-03-28 16:12:51 -07:00
parent df5def8ce4
commit a70e68e09c
5 changed files with 36 additions and 8 deletions

View File

@ -414,6 +414,17 @@ class Profile extends Memcached_DataObject
return Subscription::exists($this, $other); return Subscription::exists($this, $other);
} }
/**
* Check if a pending subscription request is outstanding for this...
*
* @param Profile $other
* @return boolean
*/
function hasPendingSubscription($other)
{
return Subscription_queue::exists($this, $other);
}
/** /**
* Are these two profiles subscribed to each other? * Are these two profiles subscribed to each other?
* *

View File

@ -36,19 +36,19 @@ class Subscription_queue extends Managed_DataObject
), ),
'primary key' => array('subscriber', 'subscribed'), 'primary key' => array('subscriber', 'subscribed'),
'indexes' => array( 'indexes' => array(
'group_join_queue_profile_id_created_idx' => array('subscriber', 'created'), 'subscription_queue_subscriber_created_idx' => array('subscriber', 'created'),
'group_join_queue_group_id_created_idx' => array('subscribed', 'created'), 'subscription_queue_subscribed_created_idx' => array('subscribed', 'created'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'group_join_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')), 'subscription_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')),
'group_join_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')), 'subscription_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')),
) )
); );
} }
public static function saveNew(Profile $subscriber, Profile $other) public static function saveNew(Profile $subscriber, Profile $subscribed)
{ {
$rq = new Group_join_queue(); $rq = new Subscription_queue();
$rq->subscriber = $subscriber->id; $rq->subscriber = $subscriber->id;
$rq->subscribed = $subscribed->id; $rq->subscribed = $subscribed->id;
$rq->created = common_sql_now(); $rq->created = common_sql_now();
@ -56,6 +56,13 @@ class Subscription_queue extends Managed_DataObject
return $rq; return $rq;
} }
function exists($subscriber, $other)
{
$sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->id,
'subscribed' => $other->id));
return (empty($sub)) ? false : true;
}
/** /**
* Complete a pending subscription, as we've got approval of some sort. * Complete a pending subscription, as we've got approval of some sort.
* *
@ -93,6 +100,6 @@ class Subscription_queue extends Managed_DataObject
{ {
$subscriber = Profile::staticGet('id', $this->subscriber); $subscriber = Profile::staticGet('id', $this->subscriber);
$subscribed = Profile::staticGet('id', $this->subscribed); $subscribed = Profile::staticGet('id', $this->subscribed);
mail_notify_subscription_pending($subscribed, $subscriber); //mail_notify_subscription_pending($subscribed, $subscriber);
} }
} }

View File

@ -90,6 +90,12 @@ class User extends Memcached_DataObject
return $profile->isSubscribed($other); return $profile->isSubscribed($other);
} }
function hasPendingSubscription($other)
{
$profile = $this->getProfile();
return $profile->hasPendingSubscription($other);
}
// 'update' won't write key columns, so we have to do it ourselves. // 'update' won't write key columns, so we have to do it ourselves.
function updateKeys(&$orig) function updateKeys(&$orig)

View File

@ -144,6 +144,9 @@ class AccountProfileBlock extends ProfileBlock
if ($cur->isSubscribed($this->profile)) { if ($cur->isSubscribed($this->profile)) {
$usf = new UnsubscribeForm($this->out, $this->profile); $usf = new UnsubscribeForm($this->out, $this->profile);
$usf->show(); $usf->show();
} else if ($cur->hasPendingSubscription($this->profile)) {
$sf = new CancelSubscriptionForm($this->out, $this->profile);
$sf->show();
} else { } else {
$sf = new SubscribeForm($this->out, $this->profile); $sf = new SubscribeForm($this->out, $this->profile);
$sf->show(); $sf->show();

View File

@ -199,7 +199,8 @@ class Router
// main stuff is repetitive // main stuff is repetitive
$main = array('login', 'logout', 'register', 'subscribe', $main = array('login', 'logout', 'register', 'subscribe',
'unsubscribe', 'confirmaddress', 'recoverpassword', 'unsubscribe', 'cancelsubscription',
'confirmaddress', 'recoverpassword',
'invite', 'favor', 'disfavor', 'sup', 'invite', 'favor', 'disfavor', 'sup',
'block', 'unblock', 'subedit', 'block', 'unblock', 'subedit',
'groupblock', 'groupunblock', 'groupblock', 'groupunblock',