コード例 #1
0
ファイル: PostSearch.php プロジェクト: phattringuyen/dekbet
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'publish_date' => $this->publish_date, 'updated_at' => $this->updated_at, 'category_id' => $this->category_id, 'enabled' => $this->enabled]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     $query->orFilterWhere(['like', 'id', $this->globalSearch]);
     $query->orFilterWhere(['like', 'name', $this->globalSearch]);
     $query->orFilterWhere(['like', 'publish_date', $this->globalSearch]);
     $query->orFilterWhere(['like', 'updated_at', $this->globalSearch]);
     $query->orFilterWhere(['like', 'category_id', $this->globalSearch]);
     $query->orFilterWhere(['like', 'enabled', $this->globalSearch]);
     $query->andFilterWhere(DateRangePicker::searchDateRange('publish_date', $this->publish_date, ' - '))->all();
     $query->andFilterWhere(DateRangePicker::searchDateRange('updated_at', $this->updated_at, ' - '))->all();
     return $dataProvider;
 }
コード例 #2
0
ファイル: DataColumn.php プロジェクト: phattringuyen/dekbet
 /**
  * @inheritdoc
  */
 protected function renderFilterCellContent()
 {
     if (is_string($this->filter)) {
         return $this->filter;
     }
     $model = $this->grid->filterModel;
     if ($this->filter !== false && $model instanceof Model && $this->attribute !== null && $model->isAttributeActive($this->attribute)) {
         if ($model->hasErrors($this->attribute)) {
             Html::addCssClass($this->filterOptions, 'has-error');
             $error = ' ' . Html::error($model, $this->attribute, $this->grid->filterErrorOptions);
         } else {
             $error = '';
         }
         if (is_array($this->format)) {
             $filterFormat = $this->format[0];
         } else {
             $filterFormat = $this->format;
         }
         if (preg_match('/date/', $filterFormat)) {
             return DateRangePicker::widget(['attribute' => $this->attribute, 'model' => $model]);
         } else {
             if (is_array($this->filter)) {
                 $options = array_merge(['prompt' => ''], $this->filterSelectOptions);
                 return Html::activeDropDownList($model, $this->attribute, $this->filter, $options) . $error;
             } else {
                 return Html::activeTextInput($model, $this->attribute, $this->filterInputOptions) . $error;
             }
         }
     } else {
         return parent::renderFilterCellContent();
     }
 }