3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Notice stream for favorites
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Notice stream for favorites
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2011 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 class FaveNoticeStream extends ScopingNoticeStream
49 function __construct($user_id, $own, $profile = -1)
51 $stream = new RawFaveNoticeStream($user_id, $own);
53 $key = 'fave:ids_by_user_own:'.$user_id;
55 $key = 'fave:ids_by_user:'.$user_id;
57 if (is_int($profile) && $profile == -1) {
58 $profile = Profile::current();
60 parent::__construct(new CachingNoticeStream($stream, $key),
66 * Raw notice stream for favorites
70 * @author Evan Prodromou <evan@status.net>
71 * @copyright 2011 StatusNet, Inc.
72 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
73 * @link http://status.net/
75 class RawFaveNoticeStream extends NoticeStream
80 function __construct($user_id, $own)
82 $this->user_id = $user_id;
87 * Note that the sorting for this is by order of *fave* not order of *notice*.
89 * @fixme add since_id, max_id support?
91 * @param <type> $user_id
93 * @param <type> $offset
94 * @param <type> $limit
95 * @param <type> $since_id
96 * @param <type> $max_id
99 function getNoticeIds($offset, $limit, $since_id, $max_id)
105 $qry = 'SELECT fave.* FROM fave ';
106 $qry .= 'WHERE fave.user_id = ' . $this->user_id . ' ';
108 $qry = 'SELECT fave.* FROM fave ';
109 $qry .= 'INNER JOIN notice ON fave.notice_id = notice.id ';
110 $qry .= 'WHERE fave.user_id = ' . $this->user_id . ' ';
111 $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
114 if ($since_id != 0) {
115 $qry .= 'AND notice_id > ' . $since_id . ' ';
119 $qry .= 'AND notice_id <= ' . $max_id . ' ';
122 // NOTE: we sort by fave time, not by notice time!
124 $qry .= 'ORDER BY modified DESC ';
126 if (!is_null($offset)) {
127 $qry .= "LIMIT $limit OFFSET $offset";
134 while ($fav->fetch()) {
135 $ids[] = $fav->notice_id;