true), array('titel', 'length', 'max'=>100), array('startzeit, endzeit, beschreibung', 'safe'), array('startzeit, endzeit', 'date', 'format'=>'dd.MM.yyyy HH:mm'), // array('startzeit, endzeit', 'DateRangeValidator', 'minDate'=>Yii::app()->params['start_date'].' '.Yii::app()->params['start_time'], 'maxDate'=>Yii::app()->params['end_date'].' '.Yii::app()->params['end_time']), // array('startzeit', 'DateCompareValidator', 'compareAttribute'=>'endzeit', 'operator'=>'<'), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id, verein_id, titel, startzeit, endzeit, beschreibung, standort_id, published', '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( 'standort' => array(self::BELONGS_TO, 'Standort', 'standort_id'), 'verein' => array(self::BELONGS_TO, 'Verein', 'verein_id'), ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'verein_id' => 'Verein', 'titel' => 'Titel', 'startzeit' => 'Startzeit', 'endzeit' => 'Endzeit', 'beschreibung' => 'Beschreibung', 'standort_id' => 'Standort', 'published' => 'Öffentlich', ); } /** * 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('verein_id',$this->verein_id); $criteria->compare('titel',$this->titel,true); $criteria->compare('startzeit',$this->startzeit,true); $criteria->compare('endzeit',$this->endzeit,true); $criteria->compare('beschreibung',$this->beschreibung,true); $criteria->compare('standort_id',$this->standort_id); $criteria->compare('published',true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, )); } public function now() { $criteria=new CDbCriteria; $nowMin = new CDbExpression('SUBDATE(NOW(),INTERVAL 1 HOUR)'); $nowPlus= new CDbExpression('ADDDATE(NOW(),INTERVAL 1 HOUR)'); $now = new CDbExpression("NOW()"); //$criteria->compare('startzeit','> '.$nowMin); //$criteria->compare('startzeit','< '.$nowPlus); //$criteria->compare("endzeit"," <= ".$now,'AND'); $criteria->condition = '(startzeit between SUBDATE(NOW(),INTERVAL 1 HOUR) and ADDDATE(NOW(),INTERVAL 1 HOUR) OR startzeit < NOW() and endzeit > NOW() ) and endzeit > NOW() and published = 1'; $criteria->order = "startzeit ASC"; return new CActiveDataProvider($this, array( 'criteria'=>$criteria, )); } public function beforeSave() { $isValid = parent::beforeSave(); if ($isValid) { $this->startzeit = Format::dbDateTime($this->startzeit); $this->endzeit = Format::dbDateTime($this->endzeit); } return $isValid; } public function behaviors() { return array( // 'LoggableBehavior'=>'application.modules.auditTrail.behaviors.LoggableBehavior', ); } public function scopes() { return array( 'published'=>array( 'condition'=>'published=1', ), 'sorted'=>array( 'order'=>'startzeit ASC', ), ); } }