From 7285bbc93b5394a16731e498b62188ea847de38d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 11 Dec 2010 10:24:46 -0500 Subject: Subscription stream functions Made two new functions, Subscription::bySubscriber() and Subscription::bySubscribed(), to get streams of Subscription objects. Converted Profile::getSubscribers() and Profile::getSubscriptions() to use these functions. --- classes/Profile.php | 54 ++++++++++++++++------------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) (limited to 'classes/Profile.php') diff --git a/classes/Profile.php b/classes/Profile.php index 8dbdcbd97..239c368ca 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -380,54 +380,32 @@ class Profile extends Memcached_DataObject function getSubscriptions($offset=0, $limit=null) { - $qry = - 'SELECT profile.* ' . - 'FROM profile JOIN subscription ' . - 'ON profile.id = subscription.subscribed ' . - 'WHERE subscription.subscriber = %d ' . - 'AND subscription.subscribed != subscription.subscriber ' . - 'ORDER BY subscription.created DESC '; - - if ($offset>0 && !is_null($limit)){ - if (common_config('db','type') == 'pgsql') { - $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; - } else { - $qry .= ' LIMIT ' . $offset . ', ' . $limit; - } - } + $subs = Subscription::bySubscriber($this->id, + $offset, + $limit); - $profile = new Profile(); + $profiles = array(); - $profile->query(sprintf($qry, $this->id)); + while ($subs->fetch()) { + $profiles[] = Profile::staticGet($subs->subscribed); + } - return $profile; + return new ArrayWrapper($profiles); } function getSubscribers($offset=0, $limit=null) { - $qry = - 'SELECT profile.* ' . - 'FROM profile JOIN subscription ' . - 'ON profile.id = subscription.subscriber ' . - 'WHERE subscription.subscribed = %d ' . - 'AND subscription.subscribed != subscription.subscriber ' . - 'ORDER BY subscription.created DESC '; - - if ($offset>0 && !is_null($limit)){ - if ($offset) { - if (common_config('db','type') == 'pgsql') { - $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; - } else { - $qry .= ' LIMIT ' . $offset . ', ' . $limit; - } - } - } + $subs = Subscription::bySubscribed($this->id, + $offset, + $limit); - $profile = new Profile(); + $profiles = array(); - $cnt = $profile->query(sprintf($qry, $this->id)); + while ($subs->fetch()) { + $profiles[] = Profile::staticGet($subs->subscriber); + } - return $profile; + return new ArrayWrapper($profiles); } function getConnectedApps($offset = 0, $limit = null) -- cgit v1.2.3-54-g00ecf From bb55784e902388f12ae9a0beddf283b48f19531e Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sun, 12 Dec 2010 17:37:42 -0800 Subject: Move getConnectedApps() from Profile to User, where it belongs --- actions/oauthconnectionssettings.php | 2 +- classes/Profile.php | 25 ------------------------- classes/User.php | 30 ++++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 26 deletions(-) (limited to 'classes/Profile.php') diff --git a/actions/oauthconnectionssettings.php b/actions/oauthconnectionssettings.php index 9a7cda924..cdb73203f 100644 --- a/actions/oauthconnectionssettings.php +++ b/actions/oauthconnectionssettings.php @@ -97,7 +97,7 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction $offset = ($this->page - 1) * APPS_PER_PAGE; $limit = APPS_PER_PAGE + 1; - $connection = $profile->getConnectedApps($offset, $limit); + $connection = $user->getConnectedApps($offset, $limit); $cnt = 0; diff --git a/classes/Profile.php b/classes/Profile.php index 239c368ca..332d51e20 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -408,31 +408,6 @@ class Profile extends Memcached_DataObject return new ArrayWrapper($profiles); } - function getConnectedApps($offset = 0, $limit = null) - { - $qry = - 'SELECT u.* ' . - 'FROM oauth_application_user u, oauth_application a ' . - 'WHERE u.profile_id = %d ' . - 'AND a.id = u.application_id ' . - 'AND u.access_type > 0 ' . - 'ORDER BY u.created DESC '; - - if ($offset > 0) { - if (common_config('db','type') == 'pgsql') { - $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; - } else { - $qry .= ' LIMIT ' . $offset . ', ' . $limit; - } - } - - $apps = new Oauth_application_user(); - - $cnt = $apps->query(sprintf($qry, $this->id)); - - return $apps; - } - function subscriptionCount() { $c = common_memcache(); diff --git a/classes/User.php b/classes/User.php index 8a3190cbf..1b1b971ec 100644 --- a/classes/User.php +++ b/classes/User.php @@ -978,4 +978,34 @@ class User extends Memcached_DataObject { return common_shorten_links($text, $always, $this); } + + /* + * Get a list of OAuth client application that have access to this + * user's account. + */ + function getConnectedApps($offset = 0, $limit = null) + { + $qry = + 'SELECT u.* ' . + 'FROM oauth_application_user u, oauth_application a ' . + 'WHERE u.profile_id = %d ' . + 'AND a.id = u.application_id ' . + 'AND u.access_type > 0 ' . + 'ORDER BY u.created DESC '; + + if ($offset > 0) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + } + + $apps = new Oauth_application_user(); + + $cnt = $apps->query(sprintf($qry, $this->id)); + + return $apps; + } + } -- cgit v1.2.3-54-g00ecf