static function getTags($tagger, $tagged, $auth_user = null) { $profile_list = new Profile_list(); $include_priv = 1; if (!($auth_user instanceof User || $auth_user instanceof Profile) || $auth_user->id !== $tagger) { $profile_list->private = false; $include_priv = 0; } $key = sprintf('profile_tag:tagger_tagged_privacy:%d-%d-%d', $tagger, $tagged, $include_priv); $tags = Profile_list::getCached($key); if ($tags !== false) { return $tags; } $profile_tag = new Profile_tag(); $profile_list->tagger = $tagger; $profile_tag->tagged = $tagged; $profile_list->selectAdd(); // only fetch id, tag, mainpage and // private hoping this will be faster $profile_list->selectAdd('profile_list.id, ' . 'profile_list.tag, ' . 'profile_list.mainpage, ' . 'profile_list.private'); $profile_list->joinAdd($profile_tag); $profile_list->find(); Profile_list::setCache($key, $profile_list); return $profile_list; }
function showContent() { $offset = ($this->page - 1) * PEOPLETAGS_PER_PAGE; $limit = PEOPLETAGS_PER_PAGE + 1; $ptags = new Profile_list(); $ptags->tag = $this->tag; $user = common_current_user(); if (empty($user)) { $ckey = sprintf('profile_list:tag:%s', $this->tag); $ptags->private = false; $ptags->orderBy('profile_list.modified DESC'); $c = Cache::instance(); if ($offset + $limit <= PEOPLETAG_CACHE_WINDOW && !empty($c)) { $cached_ptags = Profile_list::getCached($ckey, $offset, $limit); if ($cached_ptags === false) { $ptags->limit(0, PEOPLETAG_CACHE_WINDOW); $ptags->find(); Profile_list::setCache($ckey, $ptags, $offset, $limit); } else { $ptags = clone $cached_ptags; } } else { $ptags->limit($offset, $limit); $ptags->find(); } } else { $ptags->whereAdd('(profile_list.private = false OR (' . ' profile_list.tagger =' . $user->id . ' AND profile_list.private = true) )'); $ptags->orderBy('profile_list.modified DESC'); $ptags->find(); } $pl = new PeopletagList($ptags, $this); $cnt = $pl->show(); $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE, $this->page, 'peopletag', array('tag' => $this->tag)); }
/** * get Profile_list objects from the database * given their (tag, tagger) key pairs. * * @param array $keys array of array(tagger, tag) * * @return Profile_list results */ static function getByKeys(array $keys) { $cache = Cache::instance(); if (!empty($cache)) { $tags = array(); foreach ($keys as $key) { $t = Profile_list::getByTaggerAndTag($key[0], $key[1]); if (!empty($t)) { $tags[] = $t; } } return new ArrayWrapper($tags); } else { $tag = new Profile_list(); if (empty($keys)) { //if no IDs requested, just return the tag object return $tag; } $pairs = array(); foreach ($keys as $key) { $pairs[] = '(' . $key[0] . ', "' . $key[1] . '")'; } $tag->whereAdd('(tagger, tag) in (' . implode(', ', $pairs) . ')'); $tag->find(); $temp = array(); while ($tag->fetch()) { $temp[$tag->tagger . '-' . $tag->tag] = clone $tag; } $wrapped = array(); foreach ($keys as $key) { $id = $key[0] . '-' . $key[1]; if (array_key_exists($id, $temp)) { $wrapped[] = $temp[$id]; } } return new ArrayWrapper($wrapped); } }
function getTagSubscriptions($offset = 0, $limit = null, $since_id = 0, $max_id = 0) { $lists = new Profile_list(); $subs = new Profile_tag_subscription(); $lists->joinAdd(array('id', 'profile_tag_subscription:profile_tag_id')); #@fixme: postgres (round(date_part('epoch', my_date))) $lists->selectAdd('unix_timestamp(profile_tag_subscription.created) as "cursor"'); $lists->whereAdd('profile_tag_subscription.profile_id = ' . $this->id); if ($since_id > 0) { $lists->whereAdd('cursor > ' . $since_id); } if ($max_id > 0) { $lists->whereAdd('cursor <= ' . $max_id); } if ($offset >= 0 && !is_null($limit)) { $lists->limit($offset, $limit); } $lists->orderBy('"cursor" DESC'); $lists->find(); return $lists; }