<?php

/**
 * This is the model class for table "currency".
 *
 * The followings are the available columns in table 'currency':
 * @property integer $id
 * @property string $symbol_code
 * @property string $title
 * @property string $en_title
 * @property double $Buy_rate
 * @property double $Sell_rate
 * @property string $up_down
 */
class Currency extends CActiveRecord
{
	public $import_file;
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'currency';
	}

	/**
	 * @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('symbol_code, title, en_title, Buy_rate, Sell_rate, up_down', 'required'),
			array('Buy_rate, Sell_rate', 'numerical'),
			array('symbol_code, title, en_title', 'length', 'max'=>500),
			array('up_down', 'length', 'max'=>4),

			//array('import_file', 'required','on'=>'import'),
			array('import_file', 'file', 
					'types'=>'xls,xlsx',
					// 'maxSize'=>1024 * 1024 * 10, // 10MB
					'tooLarge'=>'The file was larger than 10MB. Please upload a smaller file.',
					'allowEmpty' => false,
					'on'=>'import',
                              ),
			//array('up_down', 'flexyiiPossibleValues', 'values'=> array("up","down")),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, symbol_code, title, en_title, Buy_rate, Sell_rate, up_down', '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(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
                			'id' => Yii::t('admin','ID'),
                			'symbol_code' => Yii::t('admin','Symbol Code'),
                			'title' => Yii::t('admin','Title'),
                			'en_title' => Yii::t('admin','En Title'),
                			'Buy_rate' => Yii::t('admin','Buy Rate'),
                			'Sell_rate' => Yii::t('admin','Sell Rate'),
                			'up_down' => Yii::t('admin','Up Down'),
							'import_file' => 'Select file',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('symbol_code',$this->symbol_code,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('en_title',$this->en_title,true);
		$criteria->compare('Buy_rate',$this->Buy_rate);
		$criteria->compare('Sell_rate',$this->Sell_rate);
		$criteria->compare('up_down',$this->up_down,true);

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

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Currency the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
