]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/taggedprofilenoticestream.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / lib / taggedprofilenoticestream.php
1 <?
2
3 class TaggedProfileNoticeStream extends CachingNoticeStream
4 {
5     function __construct($profile, $tag)
6     {
7         parent::__construct(new RawTaggedProfileNoticeStream($profile, $tag),
8                             'profile:notice_ids_tagged:'.$profile->id.':'.Cache::keyize($tag));
9     }
10 }
11
12 class RawTaggedProfileNoticeStream extends NoticeStream
13 {
14     protected $profile;
15     protected $tag;
16
17     function __construct($profile, $tag)
18     {
19         $this->profile = $profile;
20         $this->tag     = $tag;
21     }
22
23     function getNoticeIds($offset, $limit, $since_id, $max_id)
24     {
25         // XXX It would be nice to do this without a join
26         // (necessary to do it efficiently on accounts with long history)
27
28         $notice = new Notice();
29
30         $query =
31           "select id from notice join notice_tag on id=notice_id where tag='".
32           $notice->escape($this->tag) .
33           "' and profile_id=" . intval($this->profile->id);
34
35         $since = Notice::whereSinceId($since_id, 'id', 'notice.created');
36         if ($since) {
37             $query .= " and ($since)";
38         }
39
40         $max = Notice::whereMaxId($max_id, 'id', 'notice.created');
41         if ($max) {
42             $query .= " and ($max)";
43         }
44
45         $query .= ' order by notice.created DESC, id DESC';
46
47         if (!is_null($offset)) {
48             $query .= " LIMIT " . intval($limit) . " OFFSET " . intval($offset);
49         }
50
51         $notice->query($query);
52
53         $ids = array();
54
55         while ($notice->fetch()) {
56             $ids[] = $notice->id;
57         }
58
59         return $ids;
60     }
61 }