/** * main page * @return string */ public function actionIndex() { $model = new Tours(); $post = null; if (Yii::$app->request->isPost) { $post = Yii::$app->request->post('Tours'); } $tours = Tours::searchFilterMain($post); return $this->render('index', ['tours' => $tours, 'model' => $model]); }
public function save() { if (!$this->validate()) { return false; } $tour = $this->tour_id ? Tours::findOne($this->tour_id) : new Tours(); $tour->title = $this->title; $tour->max_adults = $this->max_adults; $tour->max_children = $this->max_children; $tour->max_babies = $this->max_babies; $tour->save(); return true; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tours::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', 'title', $this->title]); return $dataProvider; }
/** * Updates an existing Orders model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $tour = Tours::findOne($model->tour_id); $order_meta = OrderMeta::find()->where('order_id=:order_id', [':order_id' => $id])->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { foreach ($_POST['Meta'] as $meta => $val) { $order_meta = OrderMeta::find()->where('order_id=:order_id', [':order_id' => $model->id])->andWhere('meta_id=:meta_id', [':meta_id' => $meta])->one(); $order_meta->meta_val = $val; if (!$order_meta->save()) { return $this->render('update', ['model' => $model, 'order_meta' => $order_meta, 'tour' => $tour]); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'order_meta' => $order_meta, 'tour' => $tour]); } }
public function getTour() { return $this->hasOne(Tours::className(), [Tours::FIELD_TOUR_ID => self::FIELD_TOUR_ID]); }
/* @var $this yii\web\View */ /* @var $model app\models\ToursMeta */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="tours-meta-form"> <?php $form = ActiveForm::begin(); ?> <div class="form-group"> <?php echo Html::label('Tour name'); ?> <?php echo Html::activeDropDownList($model, 'tour_id', ArrayHelper::map(\app\models\Tours::find()->all(), 'id', 'title'), ['class' => 'form-control']); ?> </div> <?php echo $form->field($model, 'tour_key')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'tour_value')->dropDownList(['int' => 'Integer', 'string' => 'String']); ?> <?php echo $form->field($model, 'description')->textInput(['maxlength' => true]); ?>
/** * @return \yii\db\ActiveQuery */ public function getTour() { return $this->hasOne(Tours::className(), ['id' => 'id_tour']); }
/** * Finds the Tours model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tours the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tours::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * search booking for params tour * @param $id * @return array|\yii\db\ActiveRecord[] */ public static function searchByTour($id) { $tour = Tours::findOne($id); $booking = self::find()->where(['location' => $tour->to])->andWhere(['adult_count' => $tour->adult_count])->andWhere(['child_count' => $tour->child_count])->andWhere(['baby_count' => $tour->baby_count])->all(); return $booking; }
public function actionTourDetails($tour_id) { $model = Tours::findOne($tour_id); $dataProvider = new ActiveDataProvider(['query' => ToursDates::find()->where([ToursDates::FIELD_TOUR_ID => $tour_id])->andWhere(['>=', ToursDates::FIELD_DATE, date('Y-m-d')])]); return $this->render('view_tour', ['model' => $model, 'dataProvider' => $dataProvider]); }
public function actionEditTour($tour_id) { if (!($tour = Tours::findOne($tour_id))) { Yii::$app->session->setFlash('danger', 'Tour not found'); return $this->redirect('manage-tours'); } $model = new TourForm(); $model->initForm($tour); $tourDateForm = new ToursDatesForm(); $customFieldForm = new CustomFieldsForm(); $dataProvider = new ActiveDataProvider(['query' => ToursDates::find()->where([ToursDates::FIELD_TOUR_ID => $tour_id])]); $customFieldsDataProvider = new ActiveDataProvider(['query' => CustomFields::find()->where([CustomFields::FIELD_TOUR_ID => $tour_id])]); if ($model->load(Yii::$app->request->post(), 'TourForm') && $model->save()) { Yii::$app->session->setFlash('success', 'Tour successful updated'); return $this->redirect('manage-tours'); } if ($tourDateForm->load(Yii::$app->request->post(), 'ToursDatesForm') && $tourDateForm->save()) { Yii::$app->session->setFlash('success', 'New date successful added'); return $this->redirect(['edit-tour', Tours::FIELD_TOUR_ID => $tour_id]); } if ($customFieldForm->load(Yii::$app->request->post(), 'CustomFieldsForm') && $customFieldForm->save()) { Yii::$app->session->setFlash('success', 'New Custom field successful added'); return $this->redirect(['edit-tour', Tours::FIELD_TOUR_ID => $tour_id]); } return $this->render('edit_tour', ['model' => $model, 'tourDateForm' => $tourDateForm, 'customFieldForm' => $customFieldForm, 'dataProvider' => $dataProvider, 'customFieldsDataProvider' => $customFieldsDataProvider]); }
/** * actionIndex * @param unknown $to */ public function actionIndex() { $provider = new ActiveDataProvider(['query' => Tours::find()->with(['hotelFk', 'hotelFk.hotelFeatures', 'hotelFk.hotelFeatures.featuresFk'])->asArray(), 'pagination' => ['pageSize' => 2]]); return $provider; }
/** * @return \yii\db\ActiveQuery */ public function getTours() { return $this->hasMany(Tours::className(), ['hotel_fk' => 'id']); }