3 * StatusNet, the distributed open-source microblogging tool
5 * widget for displaying a list of notice attachments
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('GNUSOCIAL')) { exit(1); }
34 * widget for displaying a list of notice attachments
36 * There are a number of actions that display a list of notices, in
37 * reverse chronological order. This widget abstracts out most of the
38 * code for UI for notice lists. It's overridden to hide some
39 * data for e.g. the profile page.
43 * @author Evan Prodromou <evan@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
48 * @see ProfileNoticeList
50 class AttachmentList extends Widget
52 /** the current stream of notices being displayed. */
59 * @param Notice $notice stream of notices from DB_DataObject
61 function __construct($notice, $out=null)
63 parent::__construct($out);
64 $this->notice = $notice;
68 * show the list of attachments
70 * "Uses up" the stream by looping through it. So, probably can't
71 * be called twice on the same list.
73 * @return int count of items listed.
77 $attachments = $this->notice->attachments();
78 $representable = false;
79 foreach ($attachments as $key=>$att) {
80 // Only show attachments representable with a title
81 if ($att->getTitle() === null) {
82 unset($attachments[$key]);
85 if (!count($attachments)) {
89 $this->showListStart();
91 foreach ($attachments as $att) {
92 $item = $this->newListItem($att);
98 return count($attachments);
101 function showListStart()
103 $this->out->elementStart('ol', array('class' => 'attachments'));
106 function showListEnd()
108 $this->out->elementEnd('ol');
112 * returns a new list item for the current attachment
114 * @param File $attachment the current attachment
116 * @return AttachmentListItem a list item for displaying the attachment
118 function newListItem(File $attachment)
120 return new AttachmentListItem($attachment, $this->out);