From 341bfedf9039bb5b9577291da4569219f892dfef Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Fri, 23 Nov 2012 15:50:11 +0800 Subject: [PATCH] MDL-36795 - lib / administration: maxsections now limits the default setting for numsections. In the default course settings, setting the maximum number topics / weeks to 0 would not change the default number of sections on the same page as any other number would. A more appropriate check has been put in place. This also incorporates a fix for MDL-28584. The course edit screen now also checks to see if maxsections is set or numeric. If it is not set or numeric then it defaults to 52. --- course/format/topics/lib.php | 6 +++++- course/format/weeks/lib.php | 6 +++++- lib/adminlib.php | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/course/format/topics/lib.php b/course/format/topics/lib.php index 0f783e1063b..f26cafda2dd 100644 --- a/course/format/topics/lib.php +++ b/course/format/topics/lib.php @@ -213,8 +213,12 @@ class format_topics extends format_base { } if ($foreditform && !isset($courseformatoptions['coursedisplay']['label'])) { $courseconfig = get_config('moodlecourse'); + $max = $courseconfig->maxsections; + if (!isset($max) || !is_numeric($max)) { + $max = 52; + } $sectionmenu = array(); - for ($i = 0; $i <= $courseconfig->maxsections; $i++) { + for ($i = 0; $i <= $max; $i++) { $sectionmenu[$i] = "$i"; } $courseformatoptionsedit = array( diff --git a/course/format/weeks/lib.php b/course/format/weeks/lib.php index ba1f54f9c32..a5c11539af3 100644 --- a/course/format/weeks/lib.php +++ b/course/format/weeks/lib.php @@ -219,7 +219,11 @@ class format_weeks extends format_base { if ($foreditform && !isset($courseformatoptions['coursedisplay']['label'])) { $courseconfig = get_config('moodlecourse'); $sectionmenu = array(); - for ($i = 0; $i <= $courseconfig->maxsections; $i++) { + $max = $courseconfig->maxsections; + if (!isset($max) || !is_numeric($max)) { + $max = 52; + } + for ($i = 0; $i <= $max; $i++) { $sectionmenu[$i] = "$i"; } $courseformatoptionsedit = array( diff --git a/lib/adminlib.php b/lib/adminlib.php index 9bb8e77f386..8f185f2461e 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3818,7 +3818,7 @@ class admin_settings_num_course_sections extends admin_setting_configselect { /** Lazy-load the available choices for the select box */ public function load_choices() { $max = get_config('moodlecourse', 'maxsections'); - if (empty($max)) { + if (!isset($max) || !is_numeric($max)) { $max = 52; } for ($i = 0; $i <= $max; $i++) { -- 2.43.0