<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class AdapterAction extends DownloadAction
{
    public function run()
    {
        $bookId = S::gp('bid', 'G', 2);
        $action = S::gp('action', 'G');
        $type = S::gp('type', 'G');

        switch ($action)
        {
            case 'small':
                $size = 50;
                break;
            case 'big':
                $size = 100;
                break;
            default:
                $size = 50;
        }

        $book = getBookInfo($bookId);
        $count = $this->db()->getValue('SELECT COUNT(*) FROM '.Chapter::table().' WHERE bookid='.$bookId.' AND isimage = 0 AND display = 1');
        $offset = ceil($count / $size);

        $this->getController()->render('adapter', array('book'=>$book,'offset'=>$offset, 'action'=>$action, 'type'=>$type, 'count'=>$count, 'size'=>$size, 'bookid'=>$bookId));
    }
}
