Skip to content

Commit

Permalink
Moodle 4.5 subsections WIP 5
Browse files Browse the repository at this point in the history
  • Loading branch information
james-cnz committed Sep 18, 2024
1 parent 56f050f commit 25c1c73
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 51 deletions.
31 changes: 6 additions & 25 deletions classes/output/courseformat/content/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,15 @@ public function __construct(course_format $format, \section_info $section) {
* @return \stdClass data context for a mustache template
*/
public function export_for_template(\renderer_base $output): \stdClass {
global $PAGE;

$format = $this->format;
$course = $format->get_course();
$section = $this->section;
$sectionextra = $this->fmtsectionextra;

$summary = new $this->summaryclass($format, $section);

$data = (object)[
'num' => $section->section ?? '0',
'id' => $section->id,
'sectionreturnid' => $section->section, // CHANGED.
'insertafter' => false,
'summary' => $summary->export_for_template($output),
'highlightedlabel' => $format->get_section_highlighted_name(),
'sitehome' => $course->id == SITEID,
'editing' => $PAGE->user_is_editing(),
'levelsan' => $sectionextra->levelsan,
];

$haspartials = [];
$haspartials['availability'] = $this->add_availability_data($data, $output);
$haspartials['visibility'] = $this->add_visibility_data($data, $output);
$haspartials['editor'] = $this->add_editor_data($data, $output);
$haspartials['header'] = $this->add_header_data($data, $output);
$haspartials['cm'] = $this->add_cm_data($data, $output);
$this->add_format_data($data, $haspartials, $output);
$data = parent::export_for_template($output);

$data->sectionreturnid = $section->section; //TODO: Unset?
$data->sectionreturnnum = $section->section;
unset($data->displayonesection);
$data->levelsan = $sectionextra->levelsan;

return $data;
}
Expand Down
31 changes: 7 additions & 24 deletions classes/output/courseformat/content/section/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,29 @@ public function __construct(\format_multitopic $format, \section_info $section)
* @return \stdClass data context for a mustache template
*/
public function export_for_template(\renderer_base $output): \stdClass {
global $CFG;
global $CFG; // ADDED.

$format = $this->format;
$section = $this->section;
$sectionextra = $this->fmtsectionextra;
$course = $format->get_course();

$data = (object)[
'num' => $section->section,
'id' => $section->id,
];
$data = parent::export_for_template($output);

unset($data->displayonesection);

$data->title = $output->section_title_without_link($section, $course);

if ($sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) { // CHANGED link condition.
if ($sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC && empty($section->component)) {
$data->title = $output->section_title($section, $course);
}

// REMOVED stealth sections.

// ADDED.
$data->fmticon = $sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC ?
'icon fa fa-folder-o fa-fw' : 'icon fa fa-list fa-fw';
// END ADDED.

if (!$section->visible) {
$data->ishidden = true;
}

if ($course->id == SITEID) {
$data->sitehome = true;
}

$data->editing = $format->show_editor();

// REMOVED index page.

$data->name = get_section_name($course, $section);
$data->sectionbulk = ($CFG->version >= 2023021000) && empty($section->component);

$data->sectionbulk = ($CFG->version >= 2023021000);
$data->headinglevel = (!empty($section->component) && $format->get_sectionid() != $section->id) ? 4 : 3;

return $data;
}
Expand Down
8 changes: 6 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ final public function fmt_get_sections_extra($needall = true): array {
$thissectionextra = new \format_multitopic\section_info_extra($thissection);

if (!empty($thissection->component)) {
$thissectionextra->levelsan = FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC + 1;
$thissectionextra->levelsan = 0;
$fmtsectionsextra[$thissection->id] = $thissectionextra;
continue;
}
Expand Down Expand Up @@ -768,6 +768,10 @@ public function get_view_url($section, $options = []) {
// REMOVED convert sectioninfo to number.
if ($section !== null) { // CHANGED.
$sectionextra = $this->fmt_get_section_extra($section, MUST_EXIST); // ADDED.
if (!empty($sectionextra->sectionbase->component) && $sectionextra->sectionbase->component == "mod_subsection") {
$modinfo = get_fast_modinfo($course);
$sectionextra = $this->fmt_get_section_extra((object)['id' => $modinfo->get_instances_of('subsection')[$sectionextra->sectionbase->itemid]->section]);
}
// CHANGED.
$pageid = ($sectionextra->levelsan != FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) ?
$sectionextra->id : $sectionextra->parentid;
Expand All @@ -779,7 +783,7 @@ public function get_view_url($section, $options = []) {
return null;
}
$url->set_anchor('sectionid-' . $sectionextra->id . '-title');
} else if ($sectionextra->levelsan > FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) {
} else if (!empty($sectionextra->sectionbase->component)) {
$url = new moodle_url( '/course/section.php', ['id' => $sectionextra->id]);
}
// END CHANGED.
Expand Down

0 comments on commit 25c1c73

Please sign in to comment.