1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-23 11:58:41 +08:00
xiaochong0302 6614cdc8d2 1.优化boostrap
2.优化logger
3.优化contact
2024-12-16 20:27:40 +08:00

58 lines
1.2 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Services\Logic\Chapter;
use App\Models\Chapter as ChapterModel;
use App\Models\ChapterUser as ChapterUserModel;
use App\Models\User as UserModel;
use App\Repos\ChapterUser as ChapterUserRepo;
trait ChapterUserTrait
{
/**
* @var bool
*/
protected $ownedChapter = false;
/**
* @var bool
*/
protected $joinedChapter = false;
/**
* @var ChapterUserModel|null
*/
protected $chapterUser;
public function setChapterUser(ChapterModel $chapter, UserModel $user)
{
if ($user->id == 0) return;
$chapterUser = null;
$courseUser = $this->courseUser;
if ($courseUser) {
$chapterUserRepo = new ChapterUserRepo();
$chapterUser = $chapterUserRepo->findChapterUser($chapter->id, $user->id);
}
$this->chapterUser = $chapterUser;
if ($chapterUser) {
$this->joinedChapter = true;
}
if ($this->ownedCourse || $chapter->free) {
$this->ownedChapter = true;
}
}
}