1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 12:23:06 +08:00
xiaochong0302 1e3b60dbad 1.kg_course表增加索引
2.优化错误页
3.优化富文本内容长度获取
4.优化layer关闭窗口后发布状态同步
2023-09-16 20:51:57 +08:00

92 lines
2.0 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Validators;
use App\Exceptions\BadRequest;
use App\Exceptions\BadRequest as BadRequestException;
use App\Models\Review as ReviewModel;
use App\Repos\Review as ReviewRepo;
class Review extends Validator
{
public function checkReview($id)
{
$reviewRepo = new ReviewRepo();
$review = $reviewRepo->findById($id);
if (!$review) {
throw new BadRequestException('review.not_found');
}
return $review;
}
public function checkCourse($id)
{
$validator = new Course();
return $validator->checkCourse($id);
}
public function checkContent($content)
{
$value = $this->filter->sanitize($content, ['trim', 'string']);
$length = kg_strlen($value);
if ($length < 10) {
throw new BadRequestException('review.content_too_short');
}
if ($length > 255) {
throw new BadRequestException('review.content_too_long');
}
return $value;
}
public function checkRating($rating)
{
if ($rating < 1 || $rating > 5) {
throw new BadRequestException('review.invalid_rating');
}
return $rating;
}
public function checkAnonymous($status)
{
if (!in_array($status, [0, 1])) {
throw new BadRequestException('review.invalid_anonymous_status');
}
return $status;
}
public function checkPublishStatus($status)
{
if (!in_array($status, [0, 1])) {
throw new BadRequestException('review.invalid_publish_status');
}
return $status;
}
public function checkIfAllowEdit(ReviewModel $review)
{
$case = time() - $review->create_time > 3600;
if ($case) {
throw new BadRequestException('review.edit_not_allowed');
}
}
}