public function save() { if (!$this->validate()) { return false; } $tourDate = new ToursDates(); $tourDate->tour_id = $this->tour_id; $tourDate->date = $this->date; $tourDate->save(); return true; }
public function validateMaxAvailable($attribute, $params) { $tour_date = ToursDates::findOne($this->tour_date_id); if ($this->{$attribute} > $tour_date->getAvailablePlaces($attribute)) { $this->addError($attribute, 'Max available places for this field is ' . $tour_date->getAvailablePlaces($attribute)); } }
public function actionBookPlace($tour_date_id) { $model = new BookingsForm(); $tour_date = ToursDates::findOne($tour_date_id); $query = new Query(); $custom_fields = CustomFields::getCustomFieldsArray($tour_date->tour_id); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', 'Congratulations! Places successful booked'); return $this->redirect(['tour-details', Tours::FIELD_TOUR_ID => $tour_date->tour_id]); } return $this->render('book_place', ['model' => $model, 'tour_date' => $tour_date, 'custom_fields' => $custom_fields]); }
public function getTourDate() { return $this->hasOne(ToursDates::className(), [ToursDates::FIELD_TOUR_DATE_ID => self::FIELD_TOUR_DATE_ID]); }
public function actionViewDetailsTourDate($tour_date_id) { $model = ToursDates::findOne($tour_date_id); $dataProvider = new ActiveDataProvider(['query' => Bookings::find()->where([Bookings::FIELD_TOUR_DATE_ID => $tour_date_id])]); return $this->render('details_tour_date', ['model' => $model, 'dataProvider' => $dataProvider]); }
use yii\db\Expression; use yii\helpers\Html; use app\models\ToursDates; use app\models\Tours; $this->title = 'Booking tours'; ?> <div class="site-index"> <div class="jumbotron"> <h1>Welcome to Booking Tours service!</h1> <p class="lead">Chose available tour to continue</p> </div> <div class="body-content"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'emptyText' => 'No available tours at this moment', 'columns' => [['class' => DataColumn::className(), 'attribute' => Tours::FIELD_TITLE], ['class' => DataColumn::className(), 'label' => 'Nearest Tour', 'value' => function ($model) { /* @var $model Tours*/ $query = new Query(); $query->select(ToursDates::FIELD_DATE)->from(ToursDates::tableName())->where([ToursDates::FIELD_TOUR_ID => $model->tour_id])->andWhere(['>=', ToursDates::FIELD_DATE, date('Y-m-d')])->orderBy([ToursDates::FIELD_DATE => SORT_ASC]); $result = $query->one(); return $result[ToursDates::FIELD_DATE]; }], ['class' => ActionColumn::className(), 'contentOptions' => ['class' => 'text-center'], 'template' => '{view}', 'buttons' => ['view' => function ($url, $model, $key) { /* @var $model Tours */ return Html::a('View Details', ['booking/tour-details', Tours::FIELD_TOUR_ID => $model->tour_id], ['class' => 'btn btn-success']); }]]]]); ?> </div> </div>