<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class ListAction extends BbsAction
{
    public function run()
    {
        $tid = S::gp('tid', 'G', 2);
        $all = S::gp('all', 'G', 2);
        $pageSize = 5;
        $page = $_GET['page'] ? S::gp('page', 'G', 2) : 1;
        $offset = ($page - 1) * $pageSize;
        
        $thread = $this->getExistsThread($tid);
        $thread['content'] = '';
        $permissions = Members::single()->getPermissions($this->uid());
        
        $attachments = $this->_analyzeAttachment($thread, 'thread', $permissions['isdelatt']);
        if ($all)
        {
            $pageSize = count($attachments);
            $offset = 0;
        }
        $attachments = Attachment::single()->listView($attachments, $tid, $offset, $pageSize);

        $forum = $this->getController()->getForumCache($thread['fid']);
        
        $this->getController()->render('list', array(
                'all' => $all,
                'thread' => $thread,
                'attachments' => $attachments,
                'forum' => $forum,
            )
        );
    }
}