<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class UsersAction extends ForumAction
{
    public function run()
    {
        $sqlAdd = '';
        if (isset($_GET['type']))
        {
            $type = S::gp('type','G');
            $m = S::gp('member','G');
            
            switch ($_GET['type'])
            {
                case 'uid':
                    $sqlAdd = ' AND uid='.intval($m);
                    break;
                case 'username':
                    $sqlAdd = " AND username LIKE '%".trim($m)."%'";
                    break;
            }
        }
        $bookManagers = $this->db()->select()->from(BookManagers::table())->where(array('bookid'=>$this->id(),'status'=>1))->find();
        
        $count = $this->db()->getValue('SELECT COUNT(*) FROM '.BookMembers::table().' WHERE bookid='.$this->id().' AND deleted = 0 '.$sqlAdd);
        $pageObj = new iPage();
        $pageObj->setPageSize(10);
        $pageObj->setTotalRecord($count);
        $sql = "SELECT uid,username FROM `".BookMembers::table()."` WHERE `bookid` = '{$this->id()}' AND deleted = 0 $sqlAdd ORDER BY `bookmembersid` DESC LIMIT {$pageObj->getOffset()},{$pageObj->getPageSize()}";
        $bookMembers = $this->db()->setQueryString($sql)->find();
        
        $this->getController()->render('users', array(
                'bookid' => $this->id(),
                'floor' => $pageObj->getFloor(),
                'pageObj' => $pageObj,
                'bookManagers' => $bookManagers,
                'bookMembers' => $bookMembers,
                'forumInfo' => $this->forumInfo(),
            )
        );
    }
}