<?php

/**
 * This is the model class for table "page".
 *
 * The followings are the available columns in table 'page':
 * @property integer $id
 * @property string $title
 * @property string $slug
 * @property string $content
 * @property string $language
 * @property string $layout
 * @property integer $create_datetime
 * @property integer $update_datetime
 * @property string $image
 * @property string $en_title
 * @property string $en_content
 * @property string $attachment_url
 * @property string $attachment_title
 */
class Page extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'page';
	}

	/**
	 * @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('title, slug, content, layout, create_datetime, update_datetime, en_title, en_content', 'required'),
			array('create_datetime, update_datetime', 'numerical', 'integerOnly'=>true),
			array('title, image, en_title', 'length', 'max'=>200),
			array('slug', 'length', 'max'=>80),
			array('language', 'length', 'max'=>2),
			array('layout', 'length', 'max'=>45),
			 array('attachment_url, attachment_title', 'length', 'max'=>100),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, title, slug, content, language, layout, create_datetime, update_datetime, image, en_title, en_content', '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'),
                			'title' => Yii::t('admin','Title'),
                			'slug' => Yii::t('admin','Slug'),
                			'content' => Yii::t('admin','Content'),
                			'language' => Yii::t('admin','Language'),
                			'layout' => Yii::t('admin','Layout'),
                			'create_datetime' => Yii::t('admin','Create Datetime'),
                			'update_datetime' => Yii::t('admin','Update Datetime'),
                			'image' => Yii::t('admin','Image'),
                			'en_title' => Yii::t('admin','En Title'),
                			'en_content' => Yii::t('admin','En Content'),
							'attachment_url' => Yii::t('admin','Attachment Url'),
            				'attachment_title' => Yii::t('admin','Attachment Title'),
		);
	}

	/**
	 * 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('title',$this->title,true);
		$criteria->compare('slug',$this->slug,true);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('language',$this->language,true);
		$criteria->compare('layout',$this->layout,true);
		$criteria->compare('create_datetime',$this->create_datetime);
		$criteria->compare('update_datetime',$this->update_datetime);
		$criteria->compare('image',$this->image,true);
		$criteria->compare('en_title',$this->en_title,true);
		$criteria->compare('en_content',$this->en_content,true);

		$criteria->compare('attachment_url',$this->attachment_url,true);
		$criteria->compare('attachment_title',$this->attachment_title,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 Page the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
