From d5670c612b798f4147583fe463ea39d874519f0b Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 7 Mar 2011 18:08:04 +0000 Subject: [PATCH] MDL-25357 Allow maximum number of sections to be set by the admin. Also allow 0 sections at an choice. Also fix one bad
in another lang string. --- admin/settings/courses.php | 12 ++++++------ course/edit_form.php | 4 ++-- lang/en/moodle.php | 4 +++- lib/adminlib.php | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/admin/settings/courses.php b/admin/settings/courses.php index 13291c780932f..45b1ab3d012d6 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -21,10 +21,11 @@ $formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat"); } $temp->add(new admin_setting_configselect('moodlecourse/format', get_string('format'), get_string('coursehelpformat'), 'weeks',$formcourseformats)); - for ($i=1; $i<=52; $i++) { - $sectionmenu[$i] = "$i"; - } - $temp->add(new admin_setting_configselect('moodlecourse/numsections', get_string('numberweeks'), get_string('coursehelpnumberweeks'), 10,$sectionmenu)); + + $temp->add(new admin_setting_configtext('moodlecourse/maxsections', get_string('maxnumberweeks'), get_string('maxnumberweeks_desc'), 52)); + + $temp->add(new admin_settings_num_course_sections('moodlecourse/numsections', get_string('numberweeks'), get_string('coursehelpnumberweeks'), 10)); + $choices = array(); $choices['0'] = get_string('hiddensectionscollapsed'); $choices['1'] = get_string('hiddensectionsinvisible'); @@ -33,15 +34,14 @@ $temp->add(new admin_setting_configselect('moodlecourse/newsitems', get_string('newsitemsnumber'), get_string('coursehelpnewsitemsnumber'), 5,$options)); $temp->add(new admin_setting_configselect('moodlecourse/showgrades', get_string('showgrades'), get_string('coursehelpshowgrades'), 1,array(0 => get_string('no'), 1 => get_string('yes')))); $temp->add(new admin_setting_configselect('moodlecourse/showreports', get_string('showreports'), '', 0,array(0 => get_string('no'), 1 => get_string('yes')))); + if (isset($CFG->maxbytes)) { $choices = get_max_upload_sizes($CFG->maxbytes); } else { $choices = get_max_upload_sizes(); } - $temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices), $choices)); - if (!empty($CFG->legacyfilesinnewcourses)) { $choices = array('0'=>get_string('no'), '2'=>get_string('yes')); $temp->add(new admin_setting_configselect('moodlecourse/legacyfiles', get_string('courselegacyfiles'), get_string('courselegacyfiles_help'), key($choices), $choices)); diff --git a/course/edit_form.php b/course/edit_form.php index 43271c4687605..888e0c3274cfe 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -120,8 +120,8 @@ function definition() { $mform->addHelpButton('format', 'format'); $mform->setDefault('format', $courseconfig->format); - for ($i=1; $i<=52; $i++) { - $sectionmenu[$i] = "$i"; + for ($i = 0; $i <= $courseconfig->maxsections; $i++) { + $sectionmenu[$i] = "$i"; } $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu); $mform->setDefault('numsections', $courseconfig->numsections); diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 8e3fbc93f3c0e..f97e4bd8b0489 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -304,7 +304,7 @@ $string['coursehelpformat'] = 'The course main page will be displayed in this format.'; $string['coursehelphiddensections'] = 'How the hidden sections in the course are displayed to students.'; $string['coursehelpmaximumupload'] = 'Define the largest size of file that can be uploaded in this course, limited by the site-wide setting.'; -$string['coursehelpnewsitemsnumber'] = 'Number of recent items appearing on the course home page, in a news box down the right-hand side
(0 means the news box won\'t appear).'; +$string['coursehelpnewsitemsnumber'] = 'Number of recent items appearing on the course home page, in a news box down the right-hand side (0 means the news box won\'t appear).'; $string['coursehelpnumberweeks'] = 'Number of weeks/topics displayed on the course main page.'; $string['coursehelpshowgrades'] = 'Enable the display of the gradebook. It does not prevent grades from being displayed within the individual activities.'; $string['coursehidden'] = 'This course is currently unavailable to students'; @@ -981,6 +981,8 @@ $string['maximumshort'] = 'Max'; $string['maximumupload'] = 'Maximum upload size'; $string['maximumupload_help'] = 'This setting determines the largest size of file that can be uploaded to the course, limited by the site-wide setting set by an administrator. Activity modules also include a maximum upload size setting for further restricting the file size.'; +$string['maxnumberweeks'] = 'Maximum for number of weeks/topics'; +$string['maxnumberweeks_desc'] = 'This controls the maximum options that appears in the "Number of weeks/topics" setting for courses.'; $string['maxsize'] = 'Max size: {$a}'; $string['maxfilesize'] = 'Maximum size for new files: {$a}'; $string['maxnumcoursesincombo'] = 'Browse {$a->numberofcourses} courses.'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 2f32d8af3ef98..4ce6885de70da 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3591,6 +3591,32 @@ public function load_choices() { } +/** + * admin_setting_configselect for the default number of sections in a course, + * simply so we can lazy-load the choices. + * + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class admin_settings_num_course_sections extends admin_setting_configselect { + public function __construct($name, $visiblename, $description, $defaultsetting) { + parent::__construct($name, $visiblename, $description, $defaultsetting, array()); + } + + /** Lazy-load the available choices for the select box */ + public function load_choices() { + $max = get_config('moodlecourse', 'maxsections'); + if (empty($max)) { + $max = 52; + } + for ($i = 0; $i <= $max; $i++) { + $this->choices[$i] = "$i"; + } + return true; + } +} + + /** * Course category selection *