<?php
/**
 * ThunderSnarf
 *
 * @author Ricardo H.F. Sette P. <ricardohfsp@gmail.com>
 * @link http://www.freebsdbrasil.com.br/
 * @copyright Copyright &copy; 2010 - FreeBSD Brasil LTDA
 * @license licença GNU/GPL v2.0 http://www.gnu.org/licenses/gpl-2.0.html
 */
?>
<?php

class DomainIP extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'thunder_domainip':
	 * @var integer $domain_id
	 * @var integer $ip_id
	 * @var integer $cache_static
	 * @var integer $cache_dynamic
	 * @var integer $traffic_static
	 * @var integer $traffic_dynamic
	 * @var integer $hit_static
	 * @var integer $hit_dynamic
	 * @var integer $miss_static
	 * @var integer $miss_dynamic
	 * @var integer $last_requested
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'thundersnarf_domainip';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('domain_id, ip_id', 'required'),
			array('domain_id, ip_id, cache_static, cache_dynamic, traffic_static, traffic_dynamic, hit_static, hit_dynamic, miss_static, miss_dynamic, last_requested', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('requested, domain_id, ip_id, cache_static, cache_dynamic, traffic_static, traffic_dynamic, hit_static, hit_dynamic, miss_static, miss_dynamic, last_requested', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'domain' => array(self::BELONGS_TO, 'Domain', 'domain_id'),
			'ip' => array(self::BELONGS_TO, 'IP', 'ip_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'domain_id' => 'Domain',
			'ip_id' => 'Ip',
			'cache_static' => 'Cache Static',
			'cache_dynamic' => 'Cache Dynamic',
			'traffic_static' => 'Traffic Static',
			'traffic_dynamic' => 'Traffic Dynamic',
			'hit_static' => 'Hit Static',
			'hit_dynamic' => 'Hit Dynamic',
			'miss_static' => 'Miss Static',
			'miss_dynamic' => 'Miss Dynamic',
			'last_requested' => 'Last Requested',
			'requested' => 'Número de Requisições',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('domain_id',$this->domain_id);

		$criteria->compare('ip_id',$this->ip_id);

		$criteria->compare('requested',$this->requested);

		$criteria->compare('cache_static',$this->cache_static);

		$criteria->compare('cache_dynamic',$this->cache_dynamic);

		$criteria->compare('traffic_static',$this->traffic_static);

		$criteria->compare('traffic_dynamic',$this->traffic_dynamic);

		$criteria->compare('hit_static',$this->hit_static);

		$criteria->compare('hit_dynamic',$this->hit_dynamic);

		$criteria->compare('miss_static',$this->miss_static);

		$criteria->compare('miss_dynamic',$this->miss_dynamic);

		$criteria->compare('last_requested',$this->last_requested);

		return new CActiveDataProvider('DomainIP', array(
			'criteria'=>$criteria,
		));
	}
}