<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class IndexAction extends BcartAction
{
    public function run()
    {
        $this->getController()->isLogin();
        $uid = $_GET['uid'] ? S::gp('uid', 'G', 2) : $this->uid();
        $isSelf = $uid == $this->uid();
        $pageSize = 10;

        $count = $this->db()->getValue('SELECT COUNT(*) FROM '.Bcarts::table().' WHERE isdelete = 0 AND uid='.S::sqlEscape($uid));
        $pageObj = new iPage();
        $pageObj->setPageSize($pageSize);
        $pageObj->setTotalRecord($count);

        $sql = 'SELECT id,tid,subject,favorite,comment,score,scores,bnum,createdate,updatedate FROM '.Bcarts::table().' WHERE isdelete = 0 AND uid = '.S::sqlEscape($uid).' ORDER BY id DESC '.S::sqlLimit($pageObj->getOffset(), $pageObj->getPageSize());
        $bcarts = $this->db()->setQueryString($sql)->find();
        
        $floor = $pageObj->getFloor();

        $this->getController()->render('index', array(
                'bcarts' => $bcarts,
                'pageObj' => $pageObj,
                'floor' => $floor,
                'uid' => $uid,
                'isSelf' => $isSelf,
            )
        );
    }
}
