<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class FloorAction extends ForumAction
{
    public function run()
    {
        $type = empty($_GET['type']) ? 1 : (in_array(intval($_GET['type']), array(1,2,3)) ? S::gp('type','G',2) : 1);
        $count = $this->db()->getValue('SELECT COUNT(1) FROM '.BookFloor::table().' WHERE bookid='.$this->id().' AND type='.$type);
        $pageObj = new iPage();
        $pageObj->setTotalRecord($count);
        $pageObj->setPageSize(10);
        $sql = 'SELECT id,uid,createdate,floor,status FROM '.BookFloor::table().' WHERE bookid='.$this->id().' AND type='.$type." ORDER BY id DESC LIMIT {$pageObj->getOffset()},{$pageObj->getPageSize()}";
        $result = $this->db()->setQueryString($sql)->find();
        
        $navArray = BookFloor::$typeMap;
        $navString = array();
        foreach ($navArray as $key => $value)
        {
            if ($key == $type)
            {
                $navString[] = $value;
            }
            else
            {
                $navString[] = ilink($value, url('system',array('s'=>'forum','a'=>'floor','id'=>$this->id(),'type'=>$key)));
            }
        }
        $navString = implode('/', $navString);
        $floor = $pageObj->getFloor();
        $forumInfo = $this->forumInfo();
        
        $this->getController()->render('floor', array(
                'bookid' => $this->id(),
                'navString' => $navString,
                'pageObj' => $pageObj,
                'result' => $result,
                'floor' => $floor,
                'forumInfo' => $forumInfo,
            )
        );
    }
}