<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class IndexAction extends BcartAction
{
    public function run()
    {
        $pageSize = 5;
        $sql = 'SELECT id,subject FROM '.Bcarts::table().' WHERE `isdelete` = 0 AND commend = 1 AND display = 1 ORDER BY rand() DESC LIMIT '.$pageSize;
        $commendArray = $this->db()->setQueryString($sql)->find();

        $sql = 'SELECT * FROM '.Bcarts::table().' WHERE isdelete = 0 AND display = 1 ORDER BY `date` DESC,score DESC limit 5';
        $weekArray = $this->db()->setQueryString($sql)->find();

        $newArray = $this->db()->select()->from(Bcarts::table())->where(array('isdelete' => 0,'display'=>1))->desc('id')->limit(5)->find();

        $sql = 'SELECT count(*) AS c, uid FROM '.Bcarts::table().' WHERE isdelete = 0 AND uid <> 1 AND display = 1 GROUP BY uid ORDER BY c DESC LIMIT 10';
        $userArray = $this->db()->setQueryString($sql)->find();
        if ($userArray)
        {
            shuffle($userArray);
        }
        
        $this->getController()->render('index', array(
                'commendArray' => $commendArray,
                'weekArray' => $weekArray,
                'newArray' => $newArray,
                'userArray' => $userArray,
            )
        );
    }
}
