<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class PromoAction extends MemberAction
{
    public function run()
    {
        $do = empty($_GET['do']) ? 'index' : 'list';
        
        $do = '_' . $do;
        $this->$do();
    }
    
    private function _list()
    {
        $count = $this->db()->getValue('SELECT COUNT(*) FROM '.Reward::table().' WHERE `ruid` = '.$this->uid());
        $pageObj = new iPage();
        $pageObj->setPageSize(10);
        $pageObj->setTotalRecord($count);
        
        $sql = 'SELECT * FROM `'.Reward::table().'` AS R
	 		 	INNER JOIN `'.Members::table().'` AS M ON M.uid = R.uid 
	 		 	WHERE R.`ruid` = '.$this->uid().' ORDER BY R.`rewardid` DESC LIMIT '.$pageObj->getOffset().','.$pageObj->getPageSize();
        $rewards = $this->db()->setQueryString($sql)->find();
        $floor = $pageObj->getFloor();
        
        $this->getController()->render('promolist',array(
        		'rewards' => $rewards,
        		'pageObj' => $pageObj,
                'floor' => $floor,
            )
        );
    }
    
    private function _index()
    {
        $count = $this->db()->getValue('SELECT COUNT(*) AS count FROM `'.Reward::table().'` WHERE `ruid`='.$this->uid());
        
        $this->getController()->render('promo',array(
        		'count' => $count,
                'uid' => $this->uid(),
            )
        );
    }
}