public function search($params)
 {
     $query = ContentTemplateWidget::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if ($this->created_at) {
         $tmp = explode(' - ', $this->created_at);
         if (isset($tmp[0], $tmp[1])) {
             $query->andFilterWhere(['between', 'content_template_widget.created_at', strtotime($tmp[0]), strtotime($tmp[1])]);
         }
     }
     $query->andFilterWhere(['content_template_widget.id' => $this->id, 'content_template_widget.active' => $this->active, 'content_template_widget.single_per_page' => $this->single_per_page, 'content_template_widget.has_settings' => $this->has_settings]);
     $query->andFilterWhere(['like', 'content_template_widget.name', $this->name])->andFilterWhere(['like', 'content_template_widget.widget_class', $this->widget_class])->andFilterWhere(['like', 'content_template_widget.widget_options', $this->widget_options])->andFilterWhere(['like', 'content_template_widget.link_to_settings', $this->link_to_settings]);
     if ($this->position) {
         $query->andFilterWhere(['like', 'content_template_widget.position', '|' . $this->position . '|']);
     }
     return $dataProvider;
 }
 /**
  * @param int    $id ContentTemplate ID
  * @param string $position
  *
  * @return string
  * @throws \yii\web\BadRequestHttpException
  */
 public function actionAvailableWidgets($id, $position)
 {
     if (!Yii::$app->request->isAjax) {
         throw new BadRequestHttpException('AJAX only');
     }
     $widgets = ContentTemplateWidget::find()->andWhere(['active' => 1])->andWhere(['like', 'position', '|' . $position . '|'])->all();
     return $this->renderAjax('availableWidgets', compact('widgets', 'position'));
 }