true), array('startDateRu, endDateRu', 'safe'), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id, sport_event_category_id, start_date, end_date, country_id', '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( 'sportEventCategory' => array(self::BELONGS_TO, 'SportEventCategory', 'sport_event_category_id'), 'i18ns' => array(self::HAS_MANY, 'SportEventI18n', 'id', 'index' => 'lang'), 'i18n' => array(self::HAS_ONE, 'SportEventI18n', 'id', 'condition' => 'lang=\'' . Yii::app()->language . '\''), ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'start_date' => 'Начало', 'end_date' => 'Конец', 'sport_event_category_id' => 'Категория', 'country_id' => 'Страна', ); } /** * 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('id', $this->id); // $criteria->compare('sport_event_category_id', $this->sport_event_category_id); if (isset($this->sport_event_category_id)) $criteria->compare('sport_event_category_id', $this->sport_event_category_id); else $criteria->addInCondition('sport_event_category_id', array_keys($this->getSportEventCategories())); $criteria->compare('start_date', $this->start_date, true); $criteria->compare('end_date', $this->end_date, true); $criteria->compare('country_id', $this->country_id); $sort = new CSort(); $sort->defaultOrder = array( 'start_date' => true, ); return new CActiveDataProvider($this, array( 'criteria' => $criteria, 'sort' => $sort, )); } public static function getCountries() { return array( '2' => Yii::t('site', 'Украина'), '3' => Yii::t('site', 'Россия'), '1' => Yii::t('site', 'Мир'), ); } public function getCountry() { if ($this->country_id == '1') return Yii::t('site', 'Мир'); elseif ($this->country_id == '2') return Yii::t('site', 'Украина'); else /* if ($this->country_id == '3') */ return Yii::t('site', 'Россия'); } public function getStartDateRu() { return ($this->start_date !== null) ? date('d.m.Y', CDateTimeParser::parse($this->start_date, 'yyyy-MM-dd')) : date('d.m.Y'); } public function setStartDateRu($value) { $this->start_date = date('Y-m-d', CDateTimeParser::parse($value, 'dd.MM.yyyy')); } public function getEndDateRu() { return ($this->end_date !== null) ? date('d.m.Y', CDateTimeParser::parse($this->end_date, 'yyyy-MM-dd')) : date('d.m.Y'); } public function setEndDateRu($value) { $this->end_date = date('Y-m-d', CDateTimeParser::parse($value, 'dd.MM.yyyy')); } public function getSportEventCategories() { $criteria = new CDbCriteria(); $criteria->compare('calendar_section_id', $this->calendar_section_id); return CHtml::listData(SportEventCategory::model()->findAll($criteria), 'id', 'i18n.name'); } /** * @param Node $node * @return void */ public function setNode($node) { $this->calendar_section_id = $node->data_id; } }