Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recalculate parent sections when necessary #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ class format_onetopic extends core_courseformat\base {
/** @var array Messages to display */
public static $formatmsgs = [];

/** @var stdClass Onetopic-specific extra section information */
private $parentsections = null;
/** @var array Onetopic-specific extra section information */
private $parentsections = [];

/** @var course_modinfo|null Mod info used to calculate parent sections */
private $parentsectionsmodinfo = null;

/** @var array Modules used in template */
public $tplcmsused = [];
Expand Down Expand Up @@ -876,14 +879,16 @@ public function get_config_for_external() {
*/
public function fot_get_sections_extra() {

if (isset($this->parentsections)) {
$modinfo = $this->courseid ? $this->get_modinfo() : null;

if ($this->parentsectionsmodinfo == $modinfo) {
return $this->parentsections;
}

$course = $this->get_course();
$realcoursedisplay = property_exists($course, 'coursedisplay') ? $course->coursedisplay : false;
$firstsection = ($realcoursedisplay == COURSE_DISPLAY_MULTIPAGE) ? 1 : 0;
$sections = $this->get_sections();
$sections = $modinfo->get_section_info_all();
$parentsections = [];
$level0section = null;
foreach ($sections as $section) {
Expand All @@ -897,6 +902,7 @@ public function fot_get_sections_extra() {
$parentsections[$section->section] = $parent;
}
$this->parentsections = $parentsections;
$this->parentsectionsmodinfo = $modinfo;
return $parentsections;
}

Expand Down