示例#1
0
 protected function _initItems()
 {
     if ($this->mode == 'top') {
         $this->_items = EventRecord::find()->where(['active' => EventRecord::$STATUS_IS_ACTIVE])->andWhere(['>', 'eventdate', time() - 86400])->orderBy(['eventdate' => SORT_ASC])->limit(self::CNT)->all();
         $this->_view = 'events';
     } elseif ($this->mode == 'all') {
         $this->_items = EventRecord::find()->where(['active' => EventRecord::$STATUS_IS_ACTIVE])->andWhere(['>', 'eventdate', time() - 86400])->orderBy(['eventdate' => SORT_ASC])->all();
         $this->_view = 'events_all';
     }
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     if (!isset($params['parent_id'])) {
         throw new \Exception('Property parent_id must be setted');
     }
     $query = EventRecord::find()->where(['parent_id' => $params['parent_id']]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]], 'pagination' => ['pageSize' => 10]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'active' => $this->active, 'sort' => $this->sort, 'eventdate' => $this->eventdate, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'eventactive', $this->eventactive])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }