コード例 #1
0
 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;
 }
コード例 #2
0
 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));
     }
 }
コード例 #3
0
 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]);
 }
コード例 #4
0
 public function getTourDate()
 {
     return $this->hasOne(ToursDates::className(), [ToursDates::FIELD_TOUR_DATE_ID => self::FIELD_TOUR_DATE_ID]);
 }
コード例 #5
0
 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]);
 }
コード例 #6
0
ファイル: index.php プロジェクト: andreyshade/booking-tours
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>