]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/repeatsofmenoticestream.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / lib / repeatsofmenoticestream.php
1 <?php
2
3 class RepeatsOfMeNoticeStream extends CachingNoticeStream
4 {
5     function __construct($user)
6     {
7         parent::__construct(new RawRepeatsOfMeNoticeStream($user),
8                             'user:repeats_of_me:'.$user->id);
9     }
10 }
11
12 class RawRepeatsOfMeNoticeStream extends NoticeStream
13 {
14     protected $user;
15
16     function __construct($user)
17     {
18         $this->user = $user;
19     }
20
21     function getNoticeIds($offset, $limit, $since_id, $max_id)
22     {
23         $qry =
24           'SELECT DISTINCT original.id AS id ' .
25           'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' .
26           'WHERE original.profile_id = ' . $this->user->id . ' ';
27
28         $since = Notice::whereSinceId($since_id, 'original.id', 'original.created');
29         if ($since) {
30             $qry .= "AND ($since) ";
31         }
32
33         $max = Notice::whereMaxId($max_id, 'original.id', 'original.created');
34         if ($max) {
35             $qry .= "AND ($max) ";
36         }
37
38         $qry .= 'ORDER BY original.created, original.id DESC ';
39
40         if (!is_null($offset)) {
41             $qry .= "LIMIT $limit OFFSET $offset";
42         }
43
44         $ids = array();
45
46         $notice = new Notice();
47
48         $notice->query($qry);
49
50         while ($notice->fetch()) {
51             $ids[] = $notice->id;
52         }
53
54         $notice->free();
55         $notice = NULL;
56
57         return $ids;
58     }
59 }