/
k6011565
/
UP09
Обзор
Документация
Войти
/
k6011565
/
UP09
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
basic/models/Booking.php
62 строки
2 KB
Карина Коковкина
все файлы
24 июн 2026, 15:42
24 июн 2026, 15:42
2a8b11b
Код
Авторство
О чём код?
<?php namespace app\models; use yii\db\ActiveRecord; class Booking extends ActiveRecord { public static function tableName() { return 'booking'; } public function rules() { return [ [['user_id', 'tour_id', 'people_count'], 'required'], [['user_id', 'tour_id', 'people_count'], 'integer'], ['people_count', 'integer', 'min' => 1], [['total_price'], 'number'], ['status', 'in', 'range' => ['pending', 'confirmed', 'cancelled']], ['booking_date', 'safe'], ]; } public function attributeLabels() { return [ 'id' => 'ID', 'user_id' => 'Пользователь', 'tour_id' => 'Тур', 'people_count' => 'Количество человек', 'total_price' => 'Общая стоимость', 'status' => 'Статус', 'booking_date' => 'Дата бронирования', 'created_at' => 'Создано', 'updated_at' => 'Обновлено', ]; } public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id']); } public function getTour() { return $this->hasOne(Tour::class, ['id' => 'tour_id']); } public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($this->isNewRecord) { $this->created_at = time(); } $this->updated_at = time(); return true; } return false; } }