mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-23 11:58:41 +08:00
52 lines
1014 B
PHP
52 lines
1014 B
PHP
<?php
|
|
|
|
namespace App\Services\Frontend;
|
|
|
|
use App\Models\Chapter as ChapterModel;
|
|
use App\Models\User as UserModel;
|
|
use App\Repos\ChapterUser as ChapterUserRepo;
|
|
use App\Validators\Chapter as ChapterValidator;
|
|
|
|
trait ChapterTrait
|
|
{
|
|
|
|
/**
|
|
* @var bool
|
|
*/
|
|
protected $ownedChapter = false;
|
|
|
|
/**
|
|
* @var bool
|
|
*/
|
|
protected $joinedChapter = false;
|
|
|
|
public function checkChapter($id)
|
|
{
|
|
$validator = new ChapterValidator();
|
|
|
|
$chapter = $validator->checkChapter($id);
|
|
|
|
return $chapter;
|
|
}
|
|
|
|
/**
|
|
* @param ChapterModel $chapter
|
|
* @param UserModel $user
|
|
*/
|
|
public function setChapterUser($chapter, $user)
|
|
{
|
|
$chapterUserRepo = new ChapterUserRepo();
|
|
|
|
$chapterUser = $chapterUserRepo->findChapterUser($chapter->id, $user->id);
|
|
|
|
if ($chapterUser) {
|
|
$this->joinedChapter = true;
|
|
}
|
|
|
|
if ($this->ownedCourse || $chapter->free) {
|
|
$this->ownedChapter = true;
|
|
}
|
|
}
|
|
|
|
}
|