From 2f2242efa2fd10a04f90ccd8c5162f95e857f242 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Fri, 17 Aug 2012 11:44:00 +0800 Subject: [PATCH] MDl-30667 Course: Maxbytes list will show current value, if it's lower then maxbytes --- admin/settings/courses.php | 5 +++-- course/edit_form.php | 2 +- lib/moodlelib.php | 12 +++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/admin/settings/courses.php b/admin/settings/courses.php index f07107ca631..aec51028e58 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -35,10 +35,11 @@ if ($hassiteconfig $temp->add(new admin_setting_configselect('moodlecourse/showgrades', new lang_string('showgrades'), new lang_string('coursehelpshowgrades'), 1,array(0 => new lang_string('no'), 1 => new lang_string('yes')))); $temp->add(new admin_setting_configselect('moodlecourse/showreports', new lang_string('showreports'), '', 0,array(0 => new lang_string('no'), 1 => new lang_string('yes')))); + $currentmaxbytes = get_config('moodlecourse', 'maxbytes'); if (isset($CFG->maxbytes)) { - $choices = get_max_upload_sizes($CFG->maxbytes); + $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $currentmaxbytes); } else { - $choices = get_max_upload_sizes(); + $choices = get_max_upload_sizes(0, 0, 0, $currentmaxbytes); } $temp->add(new admin_setting_configselect('moodlecourse/maxbytes', new lang_string('maximumupload'), new lang_string('coursehelpmaximumupload'), key($choices), $choices)); diff --git a/course/edit_form.php b/course/edit_form.php index 75380f3f919..319bdac5c5b 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -156,7 +156,7 @@ class course_edit_form extends moodleform { $mform->addHelpButton('showreports', 'showreports'); $mform->setDefault('showreports', $courseconfig->showreports); - $choices = get_max_upload_sizes($CFG->maxbytes); + $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $course->maxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->addHelpButton('maxbytes', 'maximumupload'); $mform->setDefault('maxbytes', $courseconfig->maxbytes); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 58a6c59e4db..0cefa5e1eb9 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5913,9 +5913,11 @@ function get_user_max_upload_file_size($context, $sitebytes=0, $coursebytes=0, $ * @param int $sizebytes Set maximum size * @param int $coursebytes Current course $course->maxbytes (in bytes) * @param int $modulebytes Current module ->maxbytes (in bytes) + * @param int|array $custombytes custom upload size/s which will be added to list, + * Only value/s smaller then maxsize will be added to list. * @return array */ -function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) { +function get_max_upload_sizes($sitebytes = 0, $coursebytes = 0, $modulebytes = 0, $custombytes = null) { global $CFG; if (!$maxsize = get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes)) { @@ -5927,6 +5929,14 @@ function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) { $sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152, 5242880, 10485760, 20971520, 52428800, 104857600); + // If custombytes is given then add it to the list. + if (!is_null($custombytes)) { + if (is_number($custombytes)) { + $custombytes = array((int)$custombytes); + } + $sizelist = array_unique(array_merge($sizelist, $custombytes)); + } + // Allow maxbytes to be selected if it falls outside the above boundaries if (isset($CFG->maxbytes) && !in_array(get_real_size($CFG->maxbytes), $sizelist)) { // note: get_real_size() is used in order to prevent problems with invalid values