<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class InfoAction extends ForumAction
{
    public function run()
    {
        $isMember = false;
        if ($this->uid())
        {
            $forumMember = $this->db()->select()->from(BookMembers::table())->where(array('uid'=>$this->uid(),'bookid'=>$this->id(), 'deleted'=>0))->find(true);
            if (!empty($forumMember))
            {
                $isMember = true;
            }
        }
        
        $superManagers = getSuperBM();
        $forumInfo = $this->forumInfo();
        $level = $this->level();
        
        $bmIds = $this->bookManagers();
        if (!empty($bmIds))
        {
            $sql = 'SELECT m.uid,m.username FROM '.Members::table().' AS m WHERE m.uid IN ('.implode(',', $bmIds).')';
            $bookManagers = $this->db()->setQueryString($sql)->find();
        }

        $deputies = BookManageDeputy::single()->getAllByCache($this->id());
        
        $this->getController()->render('info', array(
                'bookid' => $this->id(),
                'superManagers' => $superManagers,
                'bookManagers' => $bookManagers,
                'deputies' => $deputies,
                'forumInfo' => $forumInfo,
                'isMember' => $isMember,
                'level' => $level,
                'forumLevel' => $this->forumLevel($level),
            )
        );
    }
}