public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); // Default name if ($this->name == "") { $this->name = BookingEx::EXTRA_FIELD_PREFIX . $this->id; $this->update(); } $ids = Booking::find()->select(['id'])->where(['tour_id' => $this->tour_id])->column(); // Insert default values foreach ($ids as $booking_id) { $fieldValue = new TourFieldValue(); $fieldValue->booking_id = $booking_id; $fieldValue->field_id = $this->id; $fieldValue->value = $this->default_value; try { $fieldValue->insert(); } catch (Exception $e) { } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { //$query = Booking::find(); $query = Booking::find()->with("fieldValues"); // 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, 'tour_id' => $this->tour_id, 'adults' => $this->adults, 'infants' => $this->infants, 'childs' => $this->childs, 'pick_up' => $this->pick_up, 'drop_off' => $this->drop_off, 'time' => $this->time]); $query->andFilterWhere(['like', 'address', $this->address]); $modeles = $dataProvider->getModels(); foreach ($modeles as $m) { $m->fieldValues; } return $dataProvider; }