/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $perPage)
 {
     $query = AnItems::find()->where(['status' => 1])->orderBy('created_at DESC');
     $query->joinwith(['cat', 'region']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $perPage]]);
     $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;
     }
     // якщо вибрана категорія є головним батьком (root) - вибираємо всіх його дітей
     if ($this->category != null) {
         $cats = AnCats::find()->where(['id' => $this->category])->all();
         foreach ($cats as $cat) {
             $children[] = $cat->children()->all();
         }
         foreach ($children as $childs) {
             foreach ($childs as $child) {
                 $this->category[] = $child->id;
             }
         }
     }
     $query->andFilterWhere(['id' => $this->id, 'an_cats.id' => $this->category, 'an_regions.id' => $this->region, 'an_cats.local' => Yii::$app->language, 'an_items.local' => Yii::$app->language]);
     $query->andFilterWhere(['like', 'created_at', $this->created_at])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'person', $this->person])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'site', $this->site]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $perPage]]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AnItems::find();
     $query->joinwith(['cat', 'region']);
     $dataProvider = new ActiveDataProvider(['query' => $query, '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, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'local', $this->local])->andFilterWhere(['like', 'an_cats.id', $this->category])->andFilterWhere(['like', 'an_regions.id', $this->region])->andFilterWhere(['like', 'created_at', $this->created_at])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'person', $this->person])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'site', $this->site]);
     return $dataProvider;
 }
 /**
  * Finds the AnItems model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AnItems the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AnItems::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAnItems()
 {
     return $this->hasMany(AnItems::className(), ['region_id' => 'id']);
 }