<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class CommentsAction extends SoftAction
{
    public function run()
    {
        $id = S::gp('id', 'G', 2);
        $soft = $this->db()->select(array('id','name','cid'))->from(SoftContents::table())->where(array('id'=>$id))->find(true);
        if (empty($soft))
        {
            throw new iSystemException('不存在的软件，不能评论');
        }

        $pageObj = new iPage();
        $pageObj->setPageSize(10);
        $pageObj->setTotalRecord($soft['comments']);
        $sql = 'SELECT uid,content,createdate,floor FROM '.SoftComments::table().' WHERE cid='.$id.' ORDER BY id DESC '.S::sqlLimit($pageObj->getOffset(), $pageObj->getPageSize());
        $comments = $this->db()->setQueryString($sql)->find();
        $floor = $pageObj->getFloor();

        $this->getController()->render('comments', array(
                'soft' => $soft,
                'comments' => $comments,
                'pageObj' => $pageObj,
                'floor' => $floor,
            )
        );
    }
}
