/
k6011565
/
UP09
Обзор
Документация
Войти
/
k6011565
/
UP09
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
basic/models/Review.php
59 строк
1 KB
Карина Коковкина
все файлы
24 июн 2026, 15:42
24 июн 2026, 15:42
2a8b11b
Код
Авторство
О чём код?
<?php namespace app\models; use yii\db\ActiveRecord; class Review extends ActiveRecord { public static function tableName() { return 'review'; } public function rules() { return [ [['user_id', 'tour_id', 'rating'], 'required'], [['user_id', 'tour_id', 'rating'], 'integer'], ['rating', 'in', 'range' => [1, 2, 3, 4, 5]], ['comment', 'string'], ['comment', 'required', 'message' => 'Пожалуйста, напишите текст отзыва.'], ]; } public function attributeLabels() { return [ 'id' => 'ID', 'user_id' => 'Пользователь', 'tour_id' => 'Тур', 'rating' => 'Оценка', 'comment' => 'Комментарий', '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; } }