/**
  * 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);
     }
 }
Exemple #2
0
 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;
 }