mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-23 03:50:56 +08:00
84 lines
1.7 KiB
PHP
84 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Validators;
|
|
|
|
use App\Exceptions\BadRequest as BadRequestException;
|
|
use App\Repos\Chapter as ChapterRepo;
|
|
use App\Repos\Comment as CommentRepo;
|
|
use App\Repos\Course as CourseRepo;
|
|
|
|
class Comment extends Validator
|
|
{
|
|
|
|
public function checkComment($id)
|
|
{
|
|
$commentRepo = new CommentRepo();
|
|
|
|
$comment = $commentRepo->findById($id);
|
|
|
|
if (!$comment) {
|
|
throw new BadRequestException('comment.not_found');
|
|
}
|
|
|
|
return $comment;
|
|
}
|
|
|
|
public function checkChapter($chapterId)
|
|
{
|
|
$chapterRepo = new ChapterRepo();
|
|
|
|
$chapter = $chapterRepo->findById($chapterId);
|
|
|
|
if (!$chapter) {
|
|
throw new BadRequestException('comment.invalid_chapter_id');
|
|
}
|
|
|
|
return $chapter;
|
|
}
|
|
|
|
public function checkParent($parentId)
|
|
{
|
|
$commentRepo = new CourseRepo();
|
|
|
|
$parent = $commentRepo->findById($parentId);
|
|
|
|
if (!$parent) {
|
|
throw new BadRequestException('comment.invalid_parent_id');
|
|
}
|
|
|
|
return $parent;
|
|
}
|
|
|
|
public function checkContent($content)
|
|
{
|
|
$value = $this->filter->sanitize($content, ['trim', 'string']);
|
|
|
|
$length = kg_strlen($value);
|
|
|
|
if ($length < 1) {
|
|
throw new BadRequestException('comment.content_too_short');
|
|
}
|
|
|
|
if ($length > 1000) {
|
|
throw new BadRequestException('comment.content_too_long');
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
public function checkMentions($mentions)
|
|
{
|
|
|
|
}
|
|
|
|
public function checkPublishStatus($status)
|
|
{
|
|
if (!in_array($status, [0, 1])) {
|
|
throw new BadRequestException('consult.invalid_publish_status');
|
|
}
|
|
|
|
return $status;
|
|
}
|
|
|
|
}
|