Images can now be saved into either the course or system context

This commit is contained in:
Mark Nelson 2013-09-09 16:50:48 +08:00
parent b7890cbb4f
commit 4b2692d377
10 changed files with 212 additions and 6 deletions

View file

@ -141,17 +141,28 @@ class customcert_element_image extends customcert_element_base {
* @return array the list of images that can be used
*/
public static function get_images() {
global $COURSE;
// Create file storage object.
$fs = get_file_storage();
// The array used to store the images.
$arrfiles = array();
$arrfiles[0] = get_string('noimage', 'customcert');
// Loop through the files uploaded in the system context.
if ($files = $fs->get_area_files(context_system::instance()->id, 'mod_customcert', 'image', false, 'filename', false)) {
foreach ($files as $hash => $file) {
$arrfiles[$hash] = $file->get_filename();
}
}
// Loop through the files uploaded in the course context.
if ($files = $fs->get_area_files(context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', false, 'filename', false)) {
foreach ($files as $hash => $file) {
$arrfiles[$hash] = $file->get_filename();
}
}
customcert_perform_asort($arrfiles);
$arrfiles = array_merge(array('0' => get_string('noimage', 'customcert')), $arrfiles);
return $arrfiles;
}

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013062800;
$plugin->version = 2013090900;
$plugin->requires = 2012120300; // Requires this Moodle version.
$plugin->component = 'customcertelement_image';