<?php
class IndexAction extends ForumAction
{
    public function run()
    {
        $chat = Chat::single($this->id());
        $forumInfo = $this->forumInfo();
        !$forumInfo['chat'] && $chat->initialize();
        
		$count = $this->db()->getValue('SELECT COUNT(*) AS c FROM ' . Chat::table($this->id()));
		$pageObj = new iPage();
		$pageObj->setPageSize(20);
		$pageObj->setTotalRecord($count);
		$sql = 'SELECT id,uid,username,message,createdate FROM ' . Chat::table($this->id()) . ' ORDER BY id DESC LIMIT '.$pageObj->getOffset().','.$pageObj->getPageSize();
		$records = $this->db()->setQueryString($sql)->find();
		$floor = $pageObj->getFloor();
		
		$superManagers = $this->superManagers();
        $bookManagers = $this->bookManagers();
        
		$this->getController()->render('index', array(
		        'bookid' => $this->id(),
		        'pageObj' => $pageObj,
		        'records' => $records,
		        'floor' => $floor,
		        'forumInfo' => $forumInfo,
		        'level' => $this->level(),
		        'superManagers' => $superManagers,
		        'bookManagers' => $bookManagers,
		    )
		);
    }
}