/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = TourField::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, 'tour_id' => $this->tour_id, 'position' => $this->position]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; }
protected function getReservationFieldsProvider($id) { $book = \app\models\Book::findOne($id); $tourFields = \app\models\TourField::find()->where(['tour_id' => $book->tour_id])->orderBy('position')->all(); $bookValues = \app\models\BookValue::find()->where(['book_id' => $book->id])->indexBy('tour_field_id')->all(); //print '<pre>'; print_r($tourFields); die(); foreach ($tourFields as $field) { $data[] = ['name' => $field->name, 'value' => array_key_exists($field->id, $bookValues) ? $bookValues[$field->id]->value : '']; } //print '<pre>'; print_r($data); die(); $provider = new \yii\data\ArrayDataProvider(['allModels' => $data]); return $provider; }