mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-37122 core get_max_upload_sizes: Include "Course/Site/Activity limit (X)" in list of options
This change removes the "0 bytes" option from the get_max_upload_sizes list and replaces it with "Course limit (X)" or "Site limit (X)" (whichever is smaller). This means we can remove all custom handling in the modules that were removing and adding these options. It only affects pages that pass valid options for sitelimit and courselimit - so admin pages will work correctly. It also orders the list so the course/site limit options will be first (as it will be the largest). AMOS START REM [courseuploadlimit, core] has been parameterized to get [uploadlimitwithsize, core] AMOS END
This commit is contained in:
parent
8fd56c1942
commit
6b219310cf
10 changed files with 122 additions and 18 deletions
|
@ -361,7 +361,6 @@ $string['coursestart'] = 'Course start';
|
|||
$string['coursesummary'] = 'Course summary';
|
||||
$string['coursesummary_help'] = 'The course summary is displayed in the list of courses. A course search searches course summary text in addition to course names.';
|
||||
$string['courseupdates'] = 'Course updates';
|
||||
$string['courseuploadlimit'] = 'Course upload limit';
|
||||
$string['create'] = 'Create';
|
||||
$string['createaccount'] = 'Create my new account';
|
||||
$string['createcategory'] = 'Create category';
|
||||
|
@ -1714,6 +1713,7 @@ $string['uploadfailednotrecovering'] = 'Your file upload has failed because ther
|
|||
$string['uploadfilelog'] = 'Upload log for file {$a}';
|
||||
$string['uploadformlimit'] = 'Uploaded file {$a} exceeded the maximum size limit set by the form';
|
||||
$string['uploadlabel'] = 'Title:';
|
||||
$string['uploadlimitwithsize'] = '{$a->contextname} upload limit ({$a->displaysize})';
|
||||
$string['uploadnewfile'] = 'Upload new file';
|
||||
$string['uploadnofilefound'] = 'No file was found - are you sure you selected one to upload?';
|
||||
$string['uploadnotallowed'] = 'Uploads are not allowed';
|
||||
|
|
|
@ -6022,7 +6022,10 @@ function get_user_max_upload_file_size($context, $sitebytes=0, $coursebytes=0, $
|
|||
* array of possible sizes in an array, translated to the
|
||||
* local language.
|
||||
*
|
||||
* @todo Finish documenting this function
|
||||
* The list of options will go up to the minimum of $sitebytes, $coursebytes or $modulebytes.
|
||||
*
|
||||
* If $coursebytes or $sitebytes is not 0, an option will be included for "Course/Site upload limit (X)"
|
||||
* with the value set to 0. This option will be the first in the list.
|
||||
*
|
||||
* @global object
|
||||
* @uses SORT_NUMERIC
|
||||
|
@ -6041,7 +6044,7 @@ function get_max_upload_sizes($sitebytes = 0, $coursebytes = 0, $modulebytes = 0
|
|||
}
|
||||
|
||||
$filesize = array();
|
||||
$filesize[intval($maxsize)] = display_size($maxsize);
|
||||
$filesize[(string)intval($maxsize)] = display_size($maxsize);
|
||||
|
||||
$sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152,
|
||||
5242880, 10485760, 20971520, 52428800, 104857600);
|
||||
|
@ -6063,12 +6066,31 @@ function get_max_upload_sizes($sitebytes = 0, $coursebytes = 0, $modulebytes = 0
|
|||
}
|
||||
|
||||
foreach ($sizelist as $sizebytes) {
|
||||
if ($sizebytes < $maxsize) {
|
||||
$filesize[intval($sizebytes)] = display_size($sizebytes);
|
||||
if ($sizebytes < $maxsize && $sizebytes > 0) {
|
||||
$filesize[(string)intval($sizebytes)] = display_size($sizebytes);
|
||||
}
|
||||
}
|
||||
|
||||
krsort($filesize, SORT_NUMERIC);
|
||||
$limitlevel = '';
|
||||
$displaysize = '';
|
||||
if ($modulebytes &&
|
||||
(($modulebytes < $coursebytes || $coursebytes == 0) &&
|
||||
($modulebytes < $sitebytes || $sitebytes == 0))) {
|
||||
$limitlevel = get_string('activity', 'core');
|
||||
$displaysize = display_size($modulebytes);
|
||||
} else if ($coursebytes && ($coursebytes < $sitebytes || $sitebytes == 0)) {
|
||||
$limitlevel = get_string('course', 'core');
|
||||
$displaysize = display_size($coursebytes);
|
||||
} else if ($sitebytes) {
|
||||
$limitlevel = get_string('site', 'core');
|
||||
$displaysize = display_size($sitebytes);
|
||||
}
|
||||
|
||||
if ($limitlevel) {
|
||||
$params = (object) array('contextname'=>$limitlevel, 'displaysize'=>$displaysize);
|
||||
$filesize = array('0'=>get_string('uploadlimitwithsize', 'core', $params)) + $filesize;
|
||||
}
|
||||
|
||||
return $filesize;
|
||||
}
|
||||
|
|
|
@ -2245,4 +2245,95 @@ class moodlelib_testcase extends advanced_testcase {
|
|||
set_config('phpunit_test_get_config_4', 'test c', 'mod_forum');
|
||||
$this->assertFalse($cache->get('mod_forum'));
|
||||
}
|
||||
|
||||
function test_get_max_upload_sizes() {
|
||||
// Test with very low limits so we are not affected by php upload limits.
|
||||
// Test activity limit smallest.
|
||||
$sitebytes = 102400;
|
||||
$coursebytes = 51200;
|
||||
$modulebytes = 10240;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
|
||||
|
||||
$this->assertEquals('Activity upload limit (10KB)', $result['0']);
|
||||
$this->assertEquals(2, count($result));
|
||||
|
||||
// Test course limit smallest.
|
||||
$sitebytes = 102400;
|
||||
$coursebytes = 10240;
|
||||
$modulebytes = 51200;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
|
||||
|
||||
$this->assertEquals('Course upload limit (10KB)', $result['0']);
|
||||
$this->assertEquals(2, count($result));
|
||||
|
||||
// Test site limit smallest.
|
||||
$sitebytes = 10240;
|
||||
$coursebytes = 102400;
|
||||
$modulebytes = 51200;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
|
||||
|
||||
$this->assertEquals('Site upload limit (10KB)', $result['0']);
|
||||
$this->assertEquals(2, count($result));
|
||||
|
||||
// Test site limit not set.
|
||||
$sitebytes = 0;
|
||||
$coursebytes = 102400;
|
||||
$modulebytes = 51200;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
|
||||
|
||||
$this->assertEquals('Activity upload limit (50KB)', $result['0']);
|
||||
$this->assertEquals(3, count($result));
|
||||
|
||||
$sitebytes = 0;
|
||||
$coursebytes = 51200;
|
||||
$modulebytes = 102400;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
|
||||
|
||||
$this->assertEquals('Course upload limit (50KB)', $result['0']);
|
||||
$this->assertEquals(3, count($result));
|
||||
|
||||
// Test no limits.
|
||||
$sitebytes = 0;
|
||||
$coursebytes = 0;
|
||||
$modulebytes = 0;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
|
||||
|
||||
$this->assertEquals(6, count($result));
|
||||
|
||||
// Test custom bytes in range.
|
||||
$sitebytes = 102400;
|
||||
$coursebytes = 51200;
|
||||
$modulebytes = 51200;
|
||||
$custombytes = 10240;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes, $custombytes);
|
||||
|
||||
$this->assertEquals(3, count($result));
|
||||
|
||||
// Test custom bytes in range but non-standard.
|
||||
$sitebytes = 102400;
|
||||
$coursebytes = 51200;
|
||||
$modulebytes = 51200;
|
||||
$custombytes = 25600;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes, $custombytes);
|
||||
|
||||
$this->assertEquals(4, count($result));
|
||||
|
||||
// Test custom bytes out of range.
|
||||
$sitebytes = 102400;
|
||||
$coursebytes = 51200;
|
||||
$modulebytes = 51200;
|
||||
$custombytes = 102400;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes, $custombytes);
|
||||
|
||||
$this->assertEquals(3, count($result));
|
||||
|
||||
// Test custom bytes out of range and non-standard.
|
||||
$sitebytes = 102400;
|
||||
$coursebytes = 51200;
|
||||
$modulebytes = 51200;
|
||||
$custombytes = 256000;
|
||||
$result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes, $custombytes);
|
||||
|
||||
$this->assertEquals(3, count($result));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@ information provided here is intended especially for developers.
|
|||
|
||||
=== 2.5 ===
|
||||
|
||||
* Function get_max_file_sizes now returns an option for (for example) "Course limit (500MB)" or
|
||||
"Site limit (200MB)" when appropriate with the option set to 0. This function no longer returns
|
||||
an option for 0 bytes. Existing code that was replacing the 0 option in the return
|
||||
from this function with a more sensible message, can now use the return from this function directly.
|
||||
* Functions responsible for output in course/lib.php are deprecated, the code is moved to
|
||||
appropriate renderers: print_section_add_menus()
|
||||
See functions' phpdocs in lib/deprecatedlib.php
|
||||
|
|
|
@ -91,14 +91,6 @@ class assign_submission_file extends assign_submission_plugin {
|
|||
$COURSE->maxbytes,
|
||||
get_config('assignsubmission_file', 'maxbytes'));
|
||||
|
||||
// Remove the option for 0 bytes.
|
||||
unset($choices[0]);
|
||||
|
||||
if ($COURSE->maxbytes == 0) {
|
||||
$choices = array(0=>get_string('siteuploadlimit', 'assignsubmission_file')) + $choices;
|
||||
} else {
|
||||
$choices = array(0=>get_string('courseuploadlimit') . ' (' . display_size($COURSE->maxbytes) . ')') + $choices;
|
||||
}
|
||||
$settings[] = array('type' => 'select',
|
||||
'name' => 'maxsubmissionsizebytes',
|
||||
'description' => get_string('maximumsubmissionsize', 'assignsubmission_file'),
|
||||
|
|
|
@ -968,7 +968,6 @@ class assignment_upload extends assignment_base {
|
|||
$ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
|
||||
|
||||
$choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
|
||||
$choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
|
||||
$mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices);
|
||||
$mform->setDefault('maxbytes', $CFG->assignment_maxbytes);
|
||||
|
||||
|
|
|
@ -299,7 +299,6 @@ class assignment_uploadsingle extends assignment_base {
|
|||
$mform->setDefault('emailteachers', 0);
|
||||
|
||||
$choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
|
||||
$choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
|
||||
$mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices);
|
||||
$mform->setDefault('maxbytes', $CFG->assignment_maxbytes);
|
||||
|
||||
|
|
|
@ -72,7 +72,6 @@ class mod_forum_mod_form extends moodleform_mod {
|
|||
|
||||
$choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
|
||||
$choices[1] = get_string('uploadnotallowed');
|
||||
$choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
|
||||
$mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices);
|
||||
$mform->addHelpButton('maxbytes', 'maxattachmentsize', 'forum');
|
||||
$mform->setDefault('maxbytes', $CFG->forum_maxbytes);
|
||||
|
|
|
@ -148,7 +148,6 @@ class mod_workshop_mod_form extends moodleform_mod {
|
|||
$mform->setDefault('nattachments', 1);
|
||||
|
||||
$options = get_max_upload_sizes($CFG->maxbytes, $this->course->maxbytes);
|
||||
$options[0] = get_string('courseuploadlimit') . ' ('.display_size($this->course->maxbytes).')';
|
||||
$mform->addElement('select', 'maxbytes', get_string('maxbytes', 'workshop'), $options);
|
||||
$mform->setDefault('maxbytes', $workshopconfig->maxbytes);
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ if ($ADMIN->fulltree) {
|
|||
|
||||
if (isset($CFG->maxbytes)) {
|
||||
$options = get_max_upload_sizes($CFG->maxbytes);
|
||||
$options[0] = get_string('courseuploadlimit');
|
||||
$settings->add(new admin_setting_configselect('workshop/maxbytes', get_string('maxbytes', 'workshop'),
|
||||
get_string('configmaxbytes', 'workshop'), 0, $options));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue