MDL-71052 course: use filetypes setting for course overview files.
This commit is contained in:
@@ -253,10 +253,13 @@ preferences,moodle|/user/preferences.php|t/preferences',
|
||||
new lang_string('courselistshortnames_desc', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configtext('coursesperpage', new lang_string('coursesperpage', 'admin'), new lang_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
|
||||
$temp->add(new admin_setting_configtext('courseswithsummarieslimit', new lang_string('courseswithsummarieslimit', 'admin'), new lang_string('configcourseswithsummarieslimit', 'admin'), 10, PARAM_INT));
|
||||
|
||||
$temp->add(new admin_setting_configtext('courseoverviewfileslimit', new lang_string('courseoverviewfileslimit'),
|
||||
new lang_string('configcourseoverviewfileslimit', 'admin'), 1, PARAM_INT));
|
||||
$temp->add(new admin_setting_configtext('courseoverviewfilesext', new lang_string('courseoverviewfilesext'),
|
||||
new lang_string('configcourseoverviewfilesext', 'admin'), '.jpg,.gif,.png'));
|
||||
$temp->add(new admin_setting_filetypes('courseoverviewfilesext', new lang_string('courseoverviewfilesext'),
|
||||
new lang_string('configcourseoverviewfilesext', 'admin'), 'web_image'
|
||||
));
|
||||
|
||||
$temp->add(new admin_setting_configtext('coursegraceperiodbefore', new lang_string('coursegraceperiodbefore', 'admin'),
|
||||
new lang_string('configcoursegraceperiodbefore', 'admin'), 0, PARAM_INT));
|
||||
$temp->add(new admin_setting_configtext('coursegraceperiodafter', new lang_string('coursegraceperiodafter', 'admin'),
|
||||
|
||||
+7
-20
@@ -2276,31 +2276,18 @@ function course_overviewfiles_options($course) {
|
||||
if (empty($CFG->courseoverviewfileslimit)) {
|
||||
return null;
|
||||
}
|
||||
$accepted_types = preg_split('/\s*,\s*/', trim($CFG->courseoverviewfilesext), -1, PREG_SPLIT_NO_EMPTY);
|
||||
if (in_array('*', $accepted_types) || empty($accepted_types)) {
|
||||
$accepted_types = '*';
|
||||
} else {
|
||||
// Since config for $CFG->courseoverviewfilesext is a text box, human factor must be considered.
|
||||
// Make sure extensions are prefixed with dot unless they are valid typegroups
|
||||
foreach ($accepted_types as $i => $type) {
|
||||
if (substr($type, 0, 1) !== '.') {
|
||||
require_once($CFG->libdir. '/filelib.php');
|
||||
if (!count(file_get_typegroup('extension', $type))) {
|
||||
// It does not start with dot and is not a valid typegroup, this is most likely extension.
|
||||
$accepted_types[$i] = '.'. $type;
|
||||
$corrected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($corrected)) {
|
||||
set_config('courseoverviewfilesext', join(',', $accepted_types));
|
||||
}
|
||||
|
||||
// Create accepted file types based on config value, falling back to default all.
|
||||
$acceptedtypes = (new \core_form\filetypes_util)->normalize_file_types($CFG->courseoverviewfilesext);
|
||||
if (in_array('*', $acceptedtypes) || empty($acceptedtypes)) {
|
||||
$acceptedtypes = '*';
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'maxfiles' => $CFG->courseoverviewfileslimit,
|
||||
'maxbytes' => $CFG->maxbytes,
|
||||
'subdirs' => 0,
|
||||
'accepted_types' => $accepted_types
|
||||
'accepted_types' => $acceptedtypes
|
||||
);
|
||||
if (!empty($course->id)) {
|
||||
$options['context'] = context_course::instance($course->id);
|
||||
|
||||
@@ -906,7 +906,7 @@ class core_course_category_testcase extends advanced_testcase {
|
||||
|
||||
// Reset default settings.
|
||||
$CFG->courseoverviewfileslimit = 1;
|
||||
$CFG->courseoverviewfilesext = '.jpg,.gif,.png';
|
||||
$CFG->courseoverviewfilesext = 'web_image';
|
||||
|
||||
$courses = $cat1->get_courses();
|
||||
$this->assertTrue($courses[$c1->id]->has_course_overviewfiles());
|
||||
|
||||
Reference in New Issue
Block a user