Skip to content

Commit

Permalink
Fix updating of course when adding or removing sections. Note: Known …
Browse files Browse the repository at this point in the history
…issue of the section not looking as it should.
  • Loading branch information
gjb2048 committed Jun 9, 2024
1 parent 50798d0 commit e8358a2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ History

Version 403.1.3 - In development
--------------------------------
1. Fix updating of course when adding or removing sections. Note: Known issue of the section not looking as it should.

Version 403.1.2 - 08/04/2024
----------------------------
Expand Down
4 changes: 2 additions & 2 deletions classes/courseformat/stateactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_section_number();
Expand Down
19 changes: 16 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,15 +961,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);
}

Expand Down

0 comments on commit e8358a2

Please sign in to comment.