/** * 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 getLists($auth_user, $offset = 0, $limit = null, $since_id = 0, $max_id = 0) { $ids = array(); $keypart = sprintf('profile:lists:%d', $this->id); $idstr = self::cacheGet($keypart); if ($idstr !== false) { $ids = explode(',', $idstr); } else { $list = new Profile_list(); $list->selectAdd(); $list->selectAdd('id'); $list->tagger = $this->id; $list->selectAdd('id as "cursor"'); if ($since_id > 0) { $list->whereAdd('id > ' . $since_id); } if ($max_id > 0) { $list->whereAdd('id <= ' . $max_id); } if ($offset >= 0 && !is_null($limit)) { $list->limit($offset, $limit); } $list->orderBy('id DESC'); if ($list->find()) { while ($list->fetch()) { $ids[] = $list->id; } } self::cacheSet($keypart, implode(',', $ids)); } $showPrivate = ($auth_user instanceof User || $auth_user instanceof Profile) && $auth_user->id === $this->id; $lists = array(); foreach ($ids as $id) { $list = Profile_list::getKV('id', $id); if (!empty($list) && ($showPrivate || !$list->private)) { if (!isset($list->cursor)) { $list->cursor = $list->id; } $lists[] = $list; } } return new ArrayWrapper($lists); }