user subscriptions methods

This commit is contained in:
Evan Prodromou 2009-01-21 13:00:30 -05:00
parent ab2dca20ff
commit 00f6f4fb67
1 changed files with 55 additions and 5 deletions

View File

@ -521,7 +521,7 @@ class User extends Memcached_DataObject
} }
} }
function getGroups($offset, $limit) function getGroups($offset=0, $limit=null)
{ {
$qry = $qry =
'SELECT user_group.* ' . 'SELECT user_group.* ' .
@ -530,10 +530,12 @@ class User extends Memcached_DataObject
'WHERE group_member.profile_id = %d ' . 'WHERE group_member.profile_id = %d ' .
'ORDER BY group_member.created DESC '; 'ORDER BY group_member.created DESC ';
if (common_config('db','type') == 'pgsql') { if ($offset) {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; if (common_config('db','type') == 'pgsql') {
} else { $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
$qry .= ' LIMIT ' . $offset . ', ' . $limit; } else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
} }
$groups = new User_group(); $groups = new User_group();
@ -542,4 +544,52 @@ class User extends Memcached_DataObject
return $groups; return $groups;
} }
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 (common_config('db','type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
$profile = new Profile();
$profile->query(sprintf($qry, $this->id));
return $profile;
}
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) {
if (common_config('db','type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
}
$profile = new Profile();
$cnt = $profile->query(sprintf($qry, $this->id));
return $profile;
}
} }