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.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.3.8, 2.4.5, 2.5.1
    • 2.3.7, 2.4.4, 2.5, 2.6
    • Course
    • None
    • MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE
    • MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • wip-MDL-39764_master_3
    • Hide

      None!

      Show
      None!
    • 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.

      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

            gb2048 Gareth J Barnard
            gb2048 Gareth J Barnard
            Marina Glancy Marina Glancy
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Petr Skoda Petr Skoda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.