<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * 广告访问详情
 *
 * @author yzxh24
 */
class DetailAction extends BaseAction
{
    public function run()
    {
        $id = intval($_GET['id']);
        $criteria = $this->_buildCriteria(new CDbCriteria(array('condition'=>'adid='.$id)));
        $criteria->select = 'COUNT(1) AS c, ip';
        $criteria->group = 'ip';
        $criteria->order = 'c DESC';

        $dataProvider = new CActiveDataProvider('AdLog',array('pagination'=>array('pageSize'=>20)));
        $dataProvider->setCriteria($criteria);

        $sql = "SELECT COUNT(*) FROM (SELECT COUNT(*) FROM ".AdLog::tableName() . " WHERE" . $criteria->condition." GROUP BY ip) AS C";
        $command = AdLog::model()->getDbConnection()->createCommand($sql);
        if (isset($_GET['RangeStart_date']['value']))
        {
        	$command->bindParam(':ycp0', $_GET['RangeStart_date']['value']);
        }
        if (isset($_GET['RangeEnd_date']['value']))
        {
        	$command->bindParam(':ycp1', $_GET['RangeEnd_date']['value']);
        }

        $count = $command->queryScalar();
        $dataProvider->setTotalItemCount($count);

        $this->getController()->render('detail',array(
            'dataProvider' => $dataProvider,
        ));
    }
    
    private function _buildCriteria(CDbCriteria $criteria)
    {
    	return Helper::buildCriteria($criteria, $_GET);
    }
}