3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Conversation tree widget for oooooold school playas
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('GNUSOCIAL')) { exit(1); }
36 * The widget class for displaying a hierarchical list of notices.
40 * @author Evan Prodromou <evan@status.net>
41 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
42 * @link http://status.net/
44 class ConversationTree extends NoticeList
50 * Show the tree of notices
56 $cnt = $this->_buildTree();
58 $this->out->elementStart('div', array('id' =>'notices_primary'));
59 // TRANS: Header on conversation page. Hidden by default (h2).
60 $this->out->element('h2', null, _('Notices'));
61 $this->out->elementStart('ol', array('class' => 'notices xoxo old-school'));
63 if (array_key_exists('root', $this->tree)) {
64 $rootid = $this->tree['root'][0];
65 $this->showNoticePlus($rootid);
68 $this->out->elementEnd('ol');
69 $this->out->elementEnd('div');
78 $this->tree = array();
79 $this->table = array();
81 while ($this->notice->fetch()) {
85 $id = $this->notice->id;
86 $notice = clone($this->notice);
88 $this->table[$id] = $notice;
90 if (is_null($notice->reply_to)) {
91 $this->tree['root'] = array($notice->id);
92 } else if (array_key_exists($notice->reply_to, $this->tree)) {
93 $this->tree[$notice->reply_to][] = $notice->id;
95 $this->tree[$notice->reply_to] = array($notice->id);
103 * Shows a notice plus its list of children.
105 * @param integer $id ID of the notice to show
109 function showNoticePlus($id)
111 $notice = $this->table[$id];
113 $this->out->elementStart('li', array('class' => 'h-entry notice',
114 'id' => 'notice-' . $id));
116 $item = $this->newListItem($notice);
119 if (array_key_exists($id, $this->tree)) {
120 $children = $this->tree[$id];
122 $this->out->elementStart('ol', array('class' => 'notices threaded-replies xoxo'));
126 foreach ($children as $child) {
127 $this->showNoticePlus($child);
130 $this->out->elementEnd('ol');
133 $this->out->elementEnd('li');
137 * Override parent class to return our preferred item.
139 * @param Notice $notice Notice to display
141 * @return NoticeListItem a list item to show
143 function newListItem(Notice $notice)
145 return new ConversationTreeItem($notice, $this->out);