mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-21 19:22:45 +08:00
91 lines
2.0 KiB
PHP
91 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\Builders;
|
|
|
|
use App\Repos\Chapter as ChapterRepo;
|
|
use App\Repos\Course as CourseRepo;
|
|
|
|
class LearningList extends Builder
|
|
{
|
|
|
|
public function handleCourses($relations)
|
|
{
|
|
$courses = $this->getCourses($relations);
|
|
|
|
foreach ($relations as $key => $value) {
|
|
$relations[$key]['course'] = $courses[$value['course_id']] ?? null;
|
|
}
|
|
|
|
return $relations;
|
|
}
|
|
|
|
public function handleChapters($relations)
|
|
{
|
|
$chapters = $this->getChapters($relations);
|
|
|
|
foreach ($relations as $key => $value) {
|
|
$relations[$key]['chapter'] = $chapters[$value['chapter_id']] ?? null;
|
|
}
|
|
|
|
return $relations;
|
|
}
|
|
|
|
public function handleUsers($relations)
|
|
{
|
|
$users = $this->getUsers($relations);
|
|
|
|
foreach ($relations as $key => $value) {
|
|
$relations[$key]['user'] = $users[$value['user_id']] ?? null;
|
|
}
|
|
|
|
return $relations;
|
|
}
|
|
|
|
protected function getCourses($relations)
|
|
{
|
|
$ids = kg_array_column($relations, 'course_id');
|
|
|
|
$courseRepo = new CourseRepo();
|
|
|
|
$courses = $courseRepo->findByIds($ids, ['id', 'title']);
|
|
|
|
$result = [];
|
|
|
|
foreach ($courses->toArray() as $course) {
|
|
$result[$course['id']] = $course;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
protected function getChapters($relations)
|
|
{
|
|
$ids = kg_array_column($relations, 'chapter_id');
|
|
|
|
$chapterRepo = new ChapterRepo();
|
|
|
|
$chapters = $chapterRepo->findByIds($ids, ['id', 'title']);
|
|
|
|
$result = [];
|
|
|
|
foreach ($chapters->toArray() as $chapter) {
|
|
$result[$chapter['id']] = $chapter;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
protected function getUsers($relations)
|
|
{
|
|
$ids = kg_array_column($relations, 'user_id');
|
|
|
|
return $this->getShallowUserByIds($ids);
|
|
}
|
|
|
|
}
|