]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/favenoticestream.php
5aaad5ce5b51f3c9a452342a5c42e1684b7e68c0
[quix0rs-gnu-social.git] / lib / favenoticestream.php
1 <?php
2
3 class FaveNoticeStream extends CachingNoticeStream
4 {
5     function __construct($user_id, $own)
6     {
7         $stream = new RawFaveNoticeStream($user_id, $own);
8         if ($own) {
9             $key = 'fave:ids_by_user_own:'.$user_id;
10         } else {
11             $key = 'fave:ids_by_user:'.$user_id;
12         }
13         parent::__construct($stream, $key);
14     }
15 }
16
17 class RawFaveNoticeStream extends NoticeStream
18 {
19     protected $user_id;
20     protected $own;
21
22     function __construct($user_id, $own)
23     {
24         $this->user_id = $user_id;
25         $this->own     = $own;
26     }
27
28     /**
29      * Note that the sorting for this is by order of *fave* not order of *notice*.
30      *
31      * @fixme add since_id, max_id support?
32      *
33      * @param <type> $user_id
34      * @param <type> $own
35      * @param <type> $offset
36      * @param <type> $limit
37      * @param <type> $since_id
38      * @param <type> $max_id
39      * @return <type>
40      */
41     function getNoticeIds($offset, $limit, $since_id, $max_id)
42     {
43         $fav = new Fave();
44         $qry = null;
45
46         if ($this->own) {
47             $qry  = 'SELECT fave.* FROM fave ';
48             $qry .= 'WHERE fave.user_id = ' . $this->user_id . ' ';
49         } else {
50              $qry =  'SELECT fave.* FROM fave ';
51              $qry .= 'INNER JOIN notice ON fave.notice_id = notice.id ';
52              $qry .= 'WHERE fave.user_id = ' . $this->user_id . ' ';
53              $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
54         }
55
56         if ($since_id != 0) {
57             $qry .= 'AND notice_id > ' . $since_id . ' ';
58         }
59
60         if ($max_id != 0) {
61             $qry .= 'AND notice_id <= ' . $max_id . ' ';
62         }
63
64         // NOTE: we sort by fave time, not by notice time!
65
66         $qry .= 'ORDER BY modified DESC ';
67
68         if (!is_null($offset)) {
69             $qry .= "LIMIT $limit OFFSET $offset";
70         }
71
72         $fav->query($qry);
73
74         $ids = array();
75
76         while ($fav->fetch()) {
77             $ids[] = $fav->notice_id;
78         }
79
80         $fav->free();
81         unset($fav);
82
83         return $ids;
84     }
85 }
86