MDL-66667 course: add course image cache

This commit is contained in:
Dmitrii Metelkin
2021-03-15 12:50:35 +11:00
parent fc335f5ea0
commit 2affc87d2b
8 changed files with 371 additions and 15 deletions
+7 -15
View File
@@ -165,24 +165,16 @@ class course_summary_exporter extends \core\external\exporter {
* Get the course image if added to course.
*
* @param object $course
* @return string url of course image
* @return string|false url of course image or false if it's not exist.
*/
public static function get_course_image($course) {
global $CFG;
$courseinlist = new \core_course_list_element($course);
foreach ($courseinlist->get_course_overviewfiles() as $file) {
if ($file->is_valid_image()) {
$pathcomponents = [
'/pluginfile.php',
$file->get_contextid(),
$file->get_component(),
$file->get_filearea() . $file->get_filepath() . $file->get_filename()
];
$path = implode('/', $pathcomponents);
return (new moodle_url($path))->out();
}
$image = \cache::make('core', 'course_image')->get($course->id);
if (is_null($image)) {
$image = false;
}
return false;
return $image;
}
/**