Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 /**
  * 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]);
     }
 }
Ejemplo n.º 3
0
 public function getAvailablePlaces($for)
 {
     $booked_places = $this->getBookedPlaces($for);
     $tour = Tours::findOne($this->tour_id);
     $all_places = 0;
     switch ($for) {
         case Bookings::FIELD_ADULTS:
             $all_places = $tour->max_adults;
             break;
         case Bookings::FIELD_CHILDREN:
             $all_places = $tour->max_children;
             break;
         case Bookings::FIELD_BABIES:
             $all_places = $tour->max_children;
             break;
     }
     $result = $all_places - $booked_places;
     return $result >= 0 ? $result : 0;
 }
Ejemplo n.º 4
0
 /**
  * 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.');
     }
 }
Ejemplo n.º 5
0
 /**
  * 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]);
 }
Ejemplo n.º 7
0
 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]);
 }