mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-22 11:41:27 +08:00
58 lines
1.1 KiB
PHP
58 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Caches;
|
|
|
|
use App\Models\User as UserModel;
|
|
use App\Repos\Course as CourseRepo;
|
|
|
|
class CourseTeacherList extends Cache
|
|
{
|
|
|
|
protected $lifetime = 1 * 86400;
|
|
|
|
public function getLifetime()
|
|
{
|
|
return $this->lifetime;
|
|
}
|
|
|
|
public function getKey($id = null)
|
|
{
|
|
return "course_teacher_list:{$id}";
|
|
}
|
|
|
|
public function getContent($id = null)
|
|
{
|
|
$courseRepo = new CourseRepo();
|
|
|
|
$users = $courseRepo->findTeachers($id);
|
|
|
|
if ($users->count() == 0) {
|
|
return [];
|
|
}
|
|
|
|
return $this->handleContent($users);
|
|
}
|
|
|
|
/**
|
|
* @param UserModel[] $users
|
|
* @return array
|
|
*/
|
|
public function handleContent($users)
|
|
{
|
|
$result = [];
|
|
|
|
foreach ($users as $user) {
|
|
$result[] = [
|
|
'id' => $user->id,
|
|
'name' => $user->name,
|
|
'avatar' => $user->avatar,
|
|
'title' => $user->title,
|
|
'about' => $user->about,
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
}
|