<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class CommentsAction extends BcartAction
{
    public function run()
    {
        $bcart = $this->getCart();

        $pageSize = 10;
        $count = $this->db()->getValue('SELECT COUNT(*) FROM '.BcartComment::table().' WHERE bcid='.S::sqlEscape($bcart['id']));

        $pageObj = new iPage();
        $pageObj->setPageSize($pageSize);
        $pageObj->setTotalRecord($count);

        $sql = 'SELECT * FROM '.BcartComment::table().' WHERE bcid='.S::sqlEscape($bcart['id']).' ORDER BY id DESC '.S::sqlLimit($pageObj->getOffset(), $pageObj->getPageSize());
        $comments = $this->db()->setQueryString($sql)->find();
        $floor = $pageObj->getFloor();

        $allowDeleteComment = false;
        if ($this->uid() && ($bcart['uid'] == $this->uid() || isGM()))
        {
            $allowDeleteComment = true;
        }
        
        $this->getController()->render('comments', array(
                'comments' => $comments,
                'pageObj' => $pageObj,
                'floor' => $floor,
                'bcart' => $bcart,
                'allowDeleteComment' => $allowDeleteComment,
            )
        );
    }
}
