General developer forum

Exceptions due to jump in section number

 
Picture of Lea Cohen
Exceptions due to jump in section number
 

In one of our courses, in a Moodle 3.1 instance, there are 7 sections in the course, and their id's are 1-6, and 110. Section 110 is an orphaned section, meaning that it doesn't appear in the course since numsections is defined to be 6.

However, in Moodle 3.3, the fact that the last section's id is not consecutive creates exceptions, since the code in course/format/lib.php, which renders the page, assumes the number of sections in the course is derived from the id of the last section:

/**
* Method used in the rendered and during backup instead of legacy 'numsections'
*
* Default renderer will treat sections with sectionnumber greater that the value returned by this
* method as "orphaned" and not display them on the course page unless in editing mode.
* Backup will store this value as 'numsections'.
*
* This method ensures that 3rd party course format plugins that still use 'numsections' continue to
* work but at the same time we no longer expect formats to have 'numsections' property.
*
* @return int
*/
public function get_last_section_number() {
$course = $this->get_course();
if (isset($course->numsections)) {
return $course->numsections;
}
$modinfo = get_fast_modinfo($course);
$sections = $modinfo->get_section_info_all();
return (int)max(array_keys($sections));
}
It uses max(array_keys($sections)) whereas it would be better if it used count($sections)-1.

How can I overcome this problem?


 
Average of ratings: -
Picture of Matteo Scaramuccia
Re: Exceptions due to jump in section number
Core developersParticularly helpful MoodlersPlugin developers

Hi Lea,
it looks like a regression added in MDL-57769.

I'd add a comment there, wait for some comments and, based on those comments, eventually file a new issue in the Tracker and apply a pull request with your suggestion, to get credit of it.

HTH,
Matteo

 
Average of ratings: Useful (2)
Picture of Lea Cohen
Re: Exceptions due to jump in section number
 

Hi Matteo,

Thank you so much for the swift reply, and thanks for the suggestion. I did it smile

 
Average of ratings: -
Picture of Marina Glancy
Re: Exceptions due to jump in section number
 

I have commented on the issue and repeating here:

Make sure you use the latest version of https://moodle.org/plugins/format_topcoll that is compatible with Moodle 3.4

If you do and you still experience an error, please contact the plugin developer

 
Average of ratings: Useful (1)
Picture of Matteo Scaramuccia
Re: Exceptions due to jump in section number
Core developersParticularly helpful MoodlersPlugin developers

TNX Marina for your stepping into this issue and your fast reply!

Appreciated approve Yes!
Matteo

 
Average of ratings: -
Picture of Lea Cohen
Re: Exceptions due to jump in section number
 

Thank you Marina. I saw your reply to my comment, and thank you for repeating it here.

You are right that the issue is with the topcoll format, since when I change to topics or weeks format, I don't get any exceptions.

I'm using version 3.3 of Moodle, therefore the version I have of topcoll is the one compatible with 3.3, which is 3.3.1.1 (2017042203). In addition, from what I can tell by comparing course/format/topcoll/renderer.php between versions 3.3 and 3.4, there is no difference in the print_multiple_section_page function.

If I am correct in using that version, I will open an issue on the github repository of topcoll.

 
Average of ratings: -
Picture of Marina Glancy
Re: Exceptions due to jump in section number
 

Sorry, Lea, I confused, the 'numsections' change was integrated in 3.3 (time flies!)

From what I see in format_topcoll release notes, Version 3.3.1.0 contains the changes for handling 'numsections'. I'm not acquainted with this plugin though

 
Average of ratings: Useful (1)
Picture of Lea Cohen
Re: Exceptions due to jump in section number
 

Thanks. I contacted him and we continued the discussion.

Thank you, Matteo and Marina, for your helpful and quick replies!

 
Average of ratings: -