/** * Creates data provider instance with search query applied * @param array $params * @return ActiveDataProvider * @throws Exception if search is not validated */ public function search($params, $descendantCategories) { $this->load($params, ''); $query = Product::find(); if (\Yii::$app->controller->module->showChildCategoriesProducts) { if (!empty($params['id'])) { $query->where(['in', 'category_id', ArrayHelper::map($descendantCategories, 'id', 'id')]); } } else { if (!empty($params['id'])) { $query->where(['category_id' => $params['id']]); } } $filterTypes = FilterType::find()->all(); foreach ($filterTypes as $filterType) { $className = $filterType->class_name; /*Getting get-method name*/ $getMethodName = explode("\\", $className); $getMethodName = lcfirst(end($getMethodName)); $query->joinWith($getMethodName); $tableName = $className::tableName(); $column = $filterType->column; $query->andFilterWhere([$tableName . '.' . 'id' => $this->{$column}]); } if (isset($params['sort'])) { switch ($params['sort']) { case self::SORT_CHEAP: $query->orderBy(['price' => SORT_ASC]); break; case self::SORT_EXPENSIVE: $query->orderBy(['price' => SORT_DESC]); break; case self::SORT_OLD: $query->orderBy(['creation_time' => SORT_ASC]); break; case self::SORT_NEW: $query->orderBy(['creation_time' => SORT_DESC]); break; } } else { $query->orderBy(['category_id' => SORT_ASC, 'position' => SORT_ASC]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); if ($this->validate()) { return $dataProvider; } else { throw new Exception(); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = FilterType::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'class_name', $this->class_name])->andFilterWhere(['like', 'column', $this->column])->andFilterWhere(['like', 'displaying_column', $this->displaying_column])->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
?> </td> </tr> <?php } ?> <?php } ?> </table> <table class="table table-bordered table-condensed table-stripped table-hover"> <tr> <td class="col-md-5"> <?php echo $form->field($newFilter, 'filter_type')->dropDownList(ArrayHelper::map(FilterType::find()->all(), 'id', function ($model) { return \Yii::t('shop', $model->title); }))->label(false); ?> </td> <td class="col-md-5"> <?php echo $form->field($newFilter, 'input_type')->dropDownList(ArrayHelper::map(FilterInputType::find()->all(), 'id', function ($model) { return \Yii::t('shop', $model->title); }))->label(false); ?> </td> <td class="col-md-2 text-center"> <?php echo Html::submitButton(Yii::t('shop', 'Add'), ['class' => 'btn btn-primary']); ?>