Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-39764

Course maxsections cannot be exceeded when changing an existing course with a greater number of sections.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.7, 2.4.4, 2.5, 2.6
    • Fix Version/s: 2.3.8, 2.4.5, 2.5.1
    • Component/s: Course
    • Labels:
      None
    • Testing Instructions:
      Hide
      1. Create a course in topics format with 14 sections (do not use existing course, it is important to test creating a course)
      2. In Home -> Site administration -> Courses -> Course default settings set the maximum number of sections to '12'
      3. Edit the course settings and observe that the number of sections combo-box is set at '14', even though this is greater than the maximum '12' and that values in the range 0-14 are shown.
      4. Do not change this field and press save
      5. Make sure all 14 sections are shown.

      Repeat test for weeks format

      Ensure this is tested in 23_STABLE, solution there is different. Then any of 24/25/master should be enough.

      Show
      Create a course in topics format with 14 sections (do not use existing course, it is important to test creating a course) In Home -> Site administration -> Courses -> Course default settings set the maximum number of sections to '12' Edit the course settings and observe that the number of sections combo-box is set at '14', even though this is greater than the maximum '12' and that values in the range 0-14 are shown. Do not change this field and press save Make sure all 14 sections are shown. Repeat test for weeks format Ensure this is tested in 23_STABLE, solution there is different. Then any of 24/25/master should be enough.
    • Workaround:
      Hide

      None!

      Show
      None!
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      wip-MDL-39764_master_3

      Description

      When editing a course you can add new sections using an icon at the bottom of the section list. Currently, this icon is shown even when the default max sections has been reached (as set up in Home /Site administration /Courses /Course default settings - moodlecourse | maxsections setting) which controls the population of the numsections combo-box in the course settings.

      Therefore it is possible for the user to add new sections beyond the maximum and add activities / resources to them. But when they edit the course settings, the new number of sections in the course is greater than the maximum value populated in the combo-box so it reverts to '0'. Then the user only sees the '0' section, goes back to the course settings to set the number of sections to the maximum, which is still less than has been added previously through the icon, only to find that there are now orphaned activities at the bottom of the course.

      Looking at the code in '/course/format/renderer.php' method 'print_multiple_section_page':

                  // Increase number of sections.
                  $straddsection = get_string('increasesections', 'moodle');
                  $url = new moodle_url('/course/changenumsections.php',
                      array('courseid' => $course->id,
                            'increase' => true,
                            'sesskey' => sesskey()));
                  $icon = $this->output->pix_icon('t/switch_plus', $straddsection);
                  echo html_writer::link($url, $icon.get_accesshide($straddsection), array('class' => 'increase-sections'));
      

      there is no 'guard' to check the maxsections. Therefore the code should be:

                  $max = get_config('moodlecourse', 'maxsections');
                  if (!isset($max) || !is_numeric($max)) {
                      $max = 52;
                  }
                  if ($course->numsections < $max) {
                      // Increase number of sections.
                      $straddsection = get_string('increasesections', 'moodle');
                      $url = new moodle_url('/course/changenumsections.php',
                                      array('courseid' => $course->id,
                                           'increase' => true,
                                           'sesskey' => sesskey()));
                      $icon = $this->output->pix_icon('t/switch_plus', $straddsection);
                      echo html_writer::link($url, $icon . get_accesshide($straddsection), array('class' => 'increase-sections'));
                  }
      

      where I have borrowed the principle setting retrieval code of:

      $max = get_config('moodlecourse', 'maxsections');
      if (!isset($max) || !is_numeric($max)) {
          $max = 52;
      }
      

      from 'admin_settings_num_course_sections' in '/lib/adminlib.php'.

      This arose from this thread in the course formats forum: https://moodle.org/mod/forum/discuss.php?d=228468

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    8/Jul/13