diff --git a/Changes.md b/Changes.md index 02b1c5f4..e2f46842 100644 --- a/Changes.md +++ b/Changes.md @@ -3,6 +3,7 @@ History Version 404.0.2 - TBR ---------------------------- +1. Fix updating of course when adding or removing sections. Note: Known issue of the section not looking as it should. Version 404.0.1 - 22/04/2024 ---------------------------- diff --git a/classes/courseformat/stateactions.php b/classes/courseformat/stateactions.php index 2b4eeaab..89505f6f 100644 --- a/classes/courseformat/stateactions.php +++ b/classes/courseformat/stateactions.php @@ -49,9 +49,9 @@ public function section_add( ?int $targetsectionid = null, ?int $targetcmid = null ): void { - parent::section_add($updates, $course, $ids, $targetsectionid, $targetcmid); $format = course_get_format($course); $format->section_added(); + parent::section_add($updates, $course, $ids, $targetsectionid, $targetcmid); } /** @@ -72,8 +72,8 @@ public function section_delete( ?int $targetsectionid = null, ?int $targetcmid = null ): void { - parent::section_delete($updates, $course, $ids, $targetsectionid, $targetcmid); $format = course_get_format($course); $format->section_deleted(); + parent::section_delete($updates, $course, $ids, $targetsectionid, $targetcmid); } } diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index bebd0f0f..586f0957 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -81,7 +81,7 @@ public function export_for_template(\renderer_base $output) { $data = (object)[ 'title' => $format->page_title(), 'format' => $format->get_format(), - 'sectionreturn' => 0, + 'sectionreturn' => null, ]; $singlesection = $this->format->get_sectionnum(); diff --git a/lib.php b/lib.php index 318b6f86..aa917498 100755 --- a/lib.php +++ b/lib.php @@ -953,15 +953,28 @@ public function restore_gnumsections($numsections) { * A section has been added. Should only be called from the state actions instance. */ public function section_added() { - $data = ['gnumsections' => $this->settings['gnumsections'] + 1]; - $this->update_format_options($data); + $this->change_gnumsections(true); } /** * A section has been deleted. Should only be called from the state actions instance. */ public function section_deleted() { - $data = ['gnumsections' => $this->settings['gnumsections'] - 1]; + $this->change_gnumsections(false); + } + + /** + * A section has been added or deleted. Should only be called via the state actions instance. + * + * @param bool $add Add a section or delete if false. + */ + protected function change_gnumsections($add) { + if ($add) { + $newgnumsetions = $this->settings['gnumsections'] + 1; + } else { + $newgnumsetions = $this->settings['gnumsections'] - 1; + } + $data = ['gnumsections' => $newgnumsetions]; $this->update_format_options($data); }