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.
29 class UserActivityStream extends AtomUserNoticeFeed
31 public $activities = array();
33 function __construct($user, $indent = true)
35 parent::__construct($user, null, $indent);
37 $subscriptions = $this->getSubscriptions();
38 $subscribers = $this->getSubscribers();
39 $groups = $this->getGroups();
40 $faves = $this->getFaves();
41 $notices = $this->getNotices();
43 $objs = array_merge($subscriptions, $subscribers, $groups, $faves, $notices);
45 // Sort by create date
47 usort($objs, 'UserActivityStream::compareObject');
49 foreach ($objs as $obj) {
50 $this->activities[] = $obj->asActivity();
54 function renderEntries()
56 foreach ($this->activities as $act) {
57 // Only show the author sub-element if it's different from default user
58 $act->outputTo($this, false, ($act->actor->id != $this->user->uri));
62 function compareObject($a, $b)
64 $ac = strtotime((empty($a->created)) ? $a->modified : $a->created);
65 $bc = strtotime((empty($b->created)) ? $b->modified : $b->created);
67 return (($ac == $bc) ? 0 : (($ac < $bc) ? 1 : -1));
70 function getSubscriptions()
74 $sub = new Subscription();
76 $sub->subscriber = $this->user->id;
79 while ($sub->fetch()) {
80 if ($sub->subscribed != $this->user->id) {
81 $subs[] = clone($sub);
89 function getSubscribers()
93 $sub = new Subscription();
95 $sub->subscribed = $this->user->id;
98 while ($sub->fetch()) {
99 if ($sub->subscriber != $this->user->id) {
100 $subs[] = clone($sub);
114 $fave->user_id = $this->user->id;
117 while ($fave->fetch()) {
118 $faves[] = clone($fave);
125 function getNotices()
129 $notice = new Notice();
131 $notice->profile_id = $this->user->id;
133 if ($notice->find()) {
134 while ($notice->fetch()) {
135 $notices[] = clone($notice);
146 $gm = new Group_member();
148 $gm->profile_id = $this->user->id;
151 while ($gm->fetch()) {
152 $groups[] = clone($gm);