<?php 
class DatabaseVersion extends PhonalisaRecord
{

    public $id;
    public $version;

    public static function myAttributes() {

        return array(
            'id'=>'id',
            'version'=>'version',
        );
    }

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Gateway the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'databaseVersion';
    }

    public function rules()
    {
        return array(
            array('version','required'),
            array('id','safe'),
        );
    }

    /**
     * @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(
        );
    }

    public function attributeLabels()
    {
        return array(
            'id' => __('DATABASE_VERSION_MODEL_ID'),
            'version' => __('DATABASE_VERSION_MODEL_NAME'),
            );
    }

    public function increment() {
	$this->version = (int)++$this->version;
	if (!$this->save()) {
	  throw new CHttpException(500,'some thing went wrong by increment DB version');
	}
    }
    
    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CPhonalisaDataProvider 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('id',$this->id);
        $criteria->compare('version',$this->version,true);

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