attachmentlist.php 3.17 KB
Newer Older
1 2
<?php
/**
3
 * StatusNet, the distributed open-source microblogging tool
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * widget for displaying a list of notice attachments
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  UI
23
 * @package   StatusNet
24 25
 * @author    Evan Prodromou <evan@status.net>
 * @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/
29 30
 */

31
if (!defined('GNUSOCIAL')) { exit(1); }
32 33 34 35 36 37 38 39 40 41

/**
 * widget for displaying a list of notice attachments
 *
 * There are a number of actions that display a list of notices, in
 * reverse chronological order. This widget abstracts out most of the
 * code for UI for notice lists. It's overridden to hide some
 * data for e.g. the profile page.
 *
 * @category UI
42
 * @package  StatusNet
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/
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
 * @see      Notice
 * @see      NoticeListItem
 * @see      ProfileNoticeList
 */
class AttachmentList extends Widget
{
    /** the current stream of notices being displayed. */

    var $notice = null;

    /**
     * constructor
     *
     * @param Notice $notice stream of notices from DB_DataObject
     */
    function __construct($notice, $out=null)
    {
        parent::__construct($out);
        $this->notice = $notice;
    }

    /**
mmn's avatar
mmn committed
68
     * show the list of attachments
69 70 71 72
     *
     * "Uses up" the stream by looping through it. So, probably can't
     * be called twice on the same list.
     *
mmn's avatar
mmn committed
73
     * @return int count of items listed.
74 75 76
     */
    function show()
    {
77
    	$att = $this->notice->attachments();
78
        if (empty($att)) return 0;
79 80 81 82 83 84 85 86 87 88 89 90 91 92
        $this->showListStart();

        foreach ($att as $n=>$attachment) {
            $item = $this->newListItem($attachment);
            $item->show();
        }

        $this->showListEnd();

        return count($att);
    }

    function showListStart()
    {
mmn's avatar
mmn committed
93
        $this->out->elementStart('ol', array('class' => 'attachments'));
94
    }
95

96 97
    function showListEnd()
    {
98
        $this->out->elementEnd('ol');
99 100 101
    }

    /**
mmn's avatar
mmn committed
102
     * returns a new list item for the current attachment
103
     *
mmn's avatar
mmn committed
104
     * @param File $attachment the current attachment
105
     *
mmn's avatar
mmn committed
106
     * @return AttachmentListItem a list item for displaying the attachment
107
     */
mmn's avatar
mmn committed
108
    function newListItem(File $attachment)
109 110 111 112
    {
        return new AttachmentListItem($attachment, $this->out);
    }
}