MDL-66667 course: add course image cache
This commit is contained in:
+7
-15
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user