<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class ImageAction extends SoftAction
{
    public function run()
    {
        $id = S::gp('id', 'G', 2);
        $all = S::gp('all', 'G', 2);
        $count = $this->db()->getValue('SELECT COUNT(*) FROM '.SoftCpics::table().' WHERE cid='.$id);
        if (!$count)
        {
            throw new iSystemException('此软件暂时没有更多截图');
        }

        $soft = $this->db()->select(array('id', 'name', 'cid'))->from(SoftContents::table())->where(array('id'=>$id))->find(true);
        $pageObj = new iPage();
        $pageObj->setTotalRecord($count);
        $pageObj->setPageSize($all ? $count : 1);
        $sql = 'SELECT name,date FROM '.SoftCpics::table().' WHERE cid='.$id.' '.S::sqlLimit($pageObj->getOffset(), $pageObj->getPageSize());
        $result = $this->db()->setQueryString($sql)->find();
        foreach ($result as &$item)
        {
            $item['purl'] = $GLOBALS['path'] . 'data/soft/image/'.$item['date'].'/'.$item['name'];
        }

        $this->getController()->render('image', array(
                'result' => $result,
                'soft' => $soft,
                'pageObj' => $pageObj,
                'all' => $all,
            )
        );
    }
}
