Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-39764 course_format: Allow courses to have numsections > maxsecti…

…ons.
  • Loading branch information...
commit 3b4752e1f259513ca1f7b3ccaf44489f969a4709 1 parent f36066f
@gjb2048 gjb2048 authored
Showing with 64 additions and 0 deletions.
  1. +32 −0 course/format/topics/lib.php
  2. +32 −0 course/format/weeks/lib.php
View
32 course/format/topics/lib.php
@@ -258,6 +258,38 @@ public function course_format_options($foreditform = false) {
}
/**
+ * Adds format options elements to the course/section edit form.
+ *
+ * This function is called from {@link course_edit_form::definition_after_data()}.
+ *
+ * @param MoodleQuickForm $mform form the elements are added to.
+ * @param bool $forsection 'true' if this is a section edit form, 'false' if this is course edit form.
+ * @return array array of references to the added form elements.
+ */
+ public function create_edit_form_elements(&$mform, $forsection = false) {
+ $elements = parent::create_edit_form_elements($mform, $forsection);
+ /*
+ * Increase the number of sections combo box values if the user has increased the number of sections
+ * using the icon on the course page beyond course 'maxsections' or course 'maxsections' has been
+ * reduced below the number of sections already set for the course on the site administration course
+ * defaults page. This is so that the number of sections is not reduced leaving unintended orphaned
+ * activities / resources.
+ */
+ if (!$forsection) {
+ $maxsections = get_config('moodlecourse', 'maxsections');
+ $numsections = $mform->getElementValue('numsections');
+ $numsections = $numsections[0];
+ if ($numsections > $maxsections) {
+ $element = $mform->getElement('numsections');
+ for ($i = $maxsections+1; $i <= $numsections; $i++) {
+ $element->addOption("$i", $i);
+ }
+ }
+ }
+ return $elements;
+ }
+
+ /**
* Updates format options for a course
*
* In case if course format was changed to 'topics', we try to copy options
View
32 course/format/weeks/lib.php
@@ -263,6 +263,38 @@ public function course_format_options($foreditform = false) {
}
/**
+ * Adds format options elements to the course/section edit form.
+ *
+ * This function is called from {@link course_edit_form::definition_after_data()}.
+ *
+ * @param MoodleQuickForm $mform form the elements are added to.
+ * @param bool $forsection 'true' if this is a section edit form, 'false' if this is course edit form.
+ * @return array array of references to the added form elements.
+ */
+ public function create_edit_form_elements(&$mform, $forsection = false) {
+ $elements = parent::create_edit_form_elements($mform, $forsection);
+ /*
+ * Increase the number of sections combo box values if the user has increased the number of sections
+ * using the icon on the course page beyond course 'maxsections' or course 'maxsections' has been
+ * reduced below the number of sections already set for the course on the site administration course
+ * defaults page. This is so that the number of sections is not reduced leaving unintended orphaned
+ * activities / resources.
+ */
+ if (!$forsection) {
+ $maxsections = get_config('moodlecourse', 'maxsections');
+ $numsections = $mform->getElementValue('numsections');
+ $numsections = $numsections[0];
+ if ($numsections > $maxsections) {
+ $element = $mform->getElement('numsections');
+ for ($i = $maxsections+1; $i <= $numsections; $i++) {
+ $element->addOption("$i", $i);
+ }
+ }
+ }
+ return $elements;
+ }
+
+ /**
* Updates format options for a course
*
* In case if course format was changed to 'weeks', we try to copy options
Please sign in to comment.
Something went wrong with that request. Please try again.