From 88c00facc807d1c138146c02c703e2294b5d357b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 27 Sep 2011 10:51:02 -0400 Subject: [PATCH] fix getOtherTags() to not use joinAdd() --- classes/Profile.php | 55 ++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/classes/Profile.php b/classes/Profile.php index 7f45031f66..f983225fd5 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -436,42 +436,55 @@ class Profile extends Managed_DataObject 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) { - $lists = new Profile_list(); + $list = new Profile_list(); - $tags = new Profile_tag(); - $tags->tagged = $this->id; + $qry = sprintf('select profile_list.*, unix_timestamp(profile_tag.modified) as "cursor" ' . + '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) { - $lists->whereAdd('( ( profile_list.private = false ) ' . - 'OR ( profile_list.tagger = ' . $auth_user->id . ' AND ' . - 'profile_list.private = true ) )'); + $qry .= sprintf('AND ( ( profile_list.private = false ) ' . + 'OR ( profile_list.tagger = %d AND ' . + 'profile_list.private = true ) )', + $auth_user->id); } else { - $lists->private = false; + $qry .= 'AND profile_list.private = 0 '; } - if ($since_id>0) { - $lists->whereAdd('cursor > '.$since_id); + if ($since_id > 0) { + $qry .= sprintf('AND (cursor > %d) ', $since_id); } - if ($max_id>0) { - $lists->whereAdd('cursor <= '.$max_id); + if ($max_id > 0) { + $qry .= sprintf('AND (cursor < %d) ', $max_id); } - if($offset>=0 && !is_null($limit)) { - $lists->limit($offset, $limit); + $qry .= 'ORDER BY profile_tag.modified DESC '; + + if ($offset >= 0 && !is_null($limit)) { + $qry .= sprintf('LIMIT %d OFFSET %d ', $limit, $offset); } - $lists->orderBy('profile_tag.modified DESC'); - $lists->find(); - - return $lists; + $list->query($qry); + return $list; } function getPrivateTags($offset=0, $limit=null, $since_id=0, $max_id=0)