<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class NewAction extends ForumAction
{
    public function run()
    {
        $count = $this->db()->getValue('SELECT COUNT(*) FROM '.BookPostDigest::table());
        $pagitation = new iPage();
        $pagitation->setTotalRecord($count);
        $pagitation->setPageSize(10);
    
        $sql = 'SELECT * FROM '.BookPostDigest::table().' ORDER BY postid DESC LIMIT '.$pagitation->getOffset().','.$pagitation->getPageSize();
        $digests = $this->db()->setQueryString($sql)->find();
        if (!empty($digests))
        {
            foreach ($digests as &$digest)
            {
                $memberInfo = Members::single()->getOneCache($digest['uid']);
                if (!empty($memberInfo['medals']))
                {
                    $digest['medals'] = iMedals::single()->getMedalsString($memberInfo['medals']);
                }
                $bookForum = getBookForum($digest['bookid']);
                $digest['forumname'] = $bookForum['forumname'];
                $book = getBookInfo($digest['bookid']);
                $digest['bookname'] = $book['bookname'];
            }
        }
    
        $floor = $pagitation->getFloor();
        
        $this->getController()->render('new', array(
                'digests' => $digests,
                'pagitation' => $pagitation,
                'floor' => $floor,
            )
        );
    }
}