3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010 StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Class for activity streams
23 * Includes faves, notices, and subscriptions.
25 * We extend atomusernoticefeed since it does some nice setup for us.
28 class UserActivityStream extends AtomUserNoticeFeed
30 public $activities = array();
32 function __construct($user, $indent = true)
34 parent::__construct($user, null, $indent);
36 $subscriptions = $this->getSubscriptions();
37 $subscribers = $this->getSubscribers();
38 $groups = $this->getGroups();
39 $faves = $this->getFaves();
40 $notices = $this->getNotices();
42 $objs = array_merge($subscriptions, $subscribers, $groups, $faves, $notices);
44 // Sort by create date
46 usort($objs, 'UserActivityStream::compareObject');
48 foreach ($objs as $obj) {
49 $this->activities[] = $obj->asActivity();
53 function renderEntries()
55 foreach ($this->activities as $act) {
56 // Only show the author sub-element if it's different from default user
57 $act->outputTo($this, false, ($act->actor->id != $this->user->uri));
61 function compareObject($a, $b)
63 $ac = strtotime((empty($a->created)) ? $a->modified : $a->created);
64 $bc = strtotime((empty($b->created)) ? $b->modified : $b->created);
66 return (($ac == $bc) ? 0 : (($ac < $bc) ? 1 : -1));
69 function getSubscriptions()
73 $sub = new Subscription();
75 $sub->subscriber = $this->user->id;
78 while ($sub->fetch()) {
79 if ($sub->subscribed != $this->user->id) {
80 $subs[] = clone($sub);
88 function getSubscribers()
92 $sub = new Subscription();
94 $sub->subscribed = $this->user->id;
97 while ($sub->fetch()) {
98 if ($sub->subscriber != $this->user->id) {
99 $subs[] = clone($sub);
113 $fave->user_id = $this->user->id;
116 while ($fave->fetch()) {
117 $faves[] = clone($fave);
124 function getNotices()
128 $notice = new Notice();
130 $notice->profile_id = $this->user->id;
132 if ($notice->find()) {
133 while ($notice->fetch()) {
134 $notices[] = clone($notice);
145 $gm = new Group_member();
147 $gm->profile_id = $this->user->id;
150 while ($gm->fetch()) {
151 $groups[] = clone($gm);