fix getOtherTags() to not use joinAdd()

This commit is contained in:
Evan Prodromou 2011-09-27 10:51:02 -04:00
parent 707f90d012
commit 88c00facc8

View File

@ -436,42 +436,55 @@ class Profile extends Managed_DataObject
return new ArrayWrapper($lists); return new ArrayWrapper($lists);
} }
/**
* Get tags that other people put on this profile, in reverse-chron order
*
* @param (Profile|User) $auth_user Authorized user (used for privacy)
* @param int $offset Offset from latest
* @param int $limit Max number to get
* @param datetime $since_id max date
* @param datetime $max_id min date
*
* @return Profile_list resulting lists
*/
function getOtherTags($auth_user=null, $offset=0, $limit=null, $since_id=0, $max_id=0) function getOtherTags($auth_user=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
{ {
$lists = new Profile_list(); $list = new Profile_list();
$tags = new Profile_tag(); $qry = sprintf('select profile_list.*, unix_timestamp(profile_tag.modified) as "cursor" ' .
$tags->tagged = $this->id; 'from profile_tag join profile_list '.
'on (profile_tag.tagger = profile_list.tagger ' .
' and profile_tag.tag = profile_list.tag) ' .
'where profile_tag.tagged = %d ',
$this->id);
$lists->joinAdd($tags);
#@fixme: postgres (round(date_part('epoch', my_date)))
$lists->selectAdd('unix_timestamp(profile_tag.modified) as "cursor"');
if ($auth_user instanceof User || $auth_user instanceof Profile) { if ($auth_user instanceof User || $auth_user instanceof Profile) {
$lists->whereAdd('( ( profile_list.private = false ) ' . $qry .= sprintf('AND ( ( profile_list.private = false ) ' .
'OR ( profile_list.tagger = ' . $auth_user->id . ' AND ' . 'OR ( profile_list.tagger = %d AND ' .
'profile_list.private = true ) )'); 'profile_list.private = true ) )',
$auth_user->id);
} else { } else {
$lists->private = false; $qry .= 'AND profile_list.private = 0 ';
} }
if ($since_id>0) { if ($since_id > 0) {
$lists->whereAdd('cursor > '.$since_id); $qry .= sprintf('AND (cursor > %d) ', $since_id);
} }
if ($max_id>0) { if ($max_id > 0) {
$lists->whereAdd('cursor <= '.$max_id); $qry .= sprintf('AND (cursor < %d) ', $max_id);
} }
if($offset>=0 && !is_null($limit)) { $qry .= 'ORDER BY profile_tag.modified DESC ';
$lists->limit($offset, $limit);
if ($offset >= 0 && !is_null($limit)) {
$qry .= sprintf('LIMIT %d OFFSET %d ', $limit, $offset);
} }
$lists->orderBy('profile_tag.modified DESC'); $list->query($qry);
$lists->find(); return $list;
return $lists;
} }
function getPrivateTags($offset=0, $limit=null, $since_id=0, $max_id=0) function getPrivateTags($offset=0, $limit=null, $since_id=0, $max_id=0)