<?php

/**
 * This is the model class for table "addressbook".
 *
 * The followings are the available columns in table 'addressbook':
 * @property integer $id
 * @property string $title
 * @property integer $descr
 */
class DateTimeProfile extends PhonalisaRecord
{

    public  $id; 
    public  $title;
    public  $descr;
    
    public static function myAttributes() {

        return array(
            'id'=>'id',
            'title'=>'title',
            'descr'=>'descr',
        );
    }
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Addressbook 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 'dateTimeProfile';
	}

	
	
	/**
	 * @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', 'required'),
            //array('title','ext.PhonalisaValidators.isUnique'),
			array('title,descr', 'safe'), // FIXME  ! do some Html-encoding stuff or so ... 
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, owner, title, descr', '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' => __('ID'),
			'title' => __('DATE_TIME_PROFILE_MODEL_TITLE'),
			'descr' => __('DATE_TIME_PROFILE_MODEL_DESC'),
		);
	}
	
	/**
	 * 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($order = 'title' )
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
        $filter = $this->getFilter($criteria, $order);
        
        $filter['pagination'] = array(
            'pageSize'=> getGridPageSize('date-time-profile-grid'),
        );
        
        if ($filter != null) {
            return new CPhonalisaDataProvider($this, $filter
            );
        }

	}
    
    public function afterDelete() {
        parent::afterDelete();
        $dateTimeRules = DateTimeRule::model()->findAllByAttributes(array('parentId'=>$this->id));
        foreach ($dateTimeRules as $dateTimeRule) {
            $dateTimeRule->delete();
        }
    }
}
