Created
April 26, 2016 10:02
-
-
Save bmbrands/c1eb21dfa7f491b1205ea0ca806b5493 to your computer and use it in GitHub Desktop.
Get a image for a course from the course summary files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once("config.php"); | |
function course_image($courseid) { | |
global $DB, $CFG; | |
require_once($CFG->libdir. '/coursecatlib.php'); | |
$courserecord = $DB->get_record('course', array('id' => $courseid)); | |
$course = new course_in_list($courserecord); | |
foreach ($course->get_course_overviewfiles() as $file) { | |
$isimage = $file->is_valid_image(); | |
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", | |
'/'. $file->get_contextid(). '/'. $file->get_component(). '/'. | |
$file->get_filearea(). $file->get_filepath(). $file->get_filename(), !$isimage); | |
if ($isimage) { | |
return html_writer::empty_tag('img', | |
array('src' => $url, 'alt' => 'Course Image '. $course->fullname, 'class' => 'courseimage')); | |
} | |
} | |
} | |
// Echo the course image for course with id number 77 | |
echo course_image(77); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment