Skip to content

Commit

Permalink
M4.4 work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Apr 14, 2024
1 parent 49d2830 commit c21a95a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
56 changes: 55 additions & 1 deletion classes/output/courseformat/content/sectionnavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,69 @@
* Base class to render a course add section navigation.
*/
class sectionnavigation extends \core_courseformat\output\local\content\sectionnavigation {
/** @var stdClass the calculated data to prevent calculations when rendered several times */
protected $data = null;

/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output typically, the renderer that's calling this function
* @return stdClass data context for a mustache template
*/
public function export_for_template(\renderer_base $output): \stdClass {
$data = parent::export_for_template($output);
global $USER;

if ($this->data !== null) {
return $this->data;
}

$format = $this->format;
$course = $format->get_course();
$context = \context_course::instance($course->id);

$modinfo = $this->format->get_modinfo();
$sections = $modinfo->get_section_info_all();

// FIXME: This is really evil and should by using the navigation API.
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context, $USER);

$data = (object)[
'previousurl' => '',
'nexturl' => '',
'larrow' => $output->larrow(),
'rarrow' => $output->rarrow(),
'currentsection' => $this->sectionno,
];

$back = $this->sectionno - 1;
while ($back > 0 and empty($data->previousurl)) {
if ($canviewhidden || $sections[$back]->uservisible) {
if (!$sections[$back]->visible) {
$data->previoushidden = true;
}
$data->previousname = get_section_name($course, $sections[$back]);
$data->previousurl = course_get_url($course, $back, ['navigation' => true]);
$data->hasprevious = true;
}
$back--;
}

$forward = $this->sectionno + 1;
$numsections = course_get_format($course)->get_last_section_number();
while ($forward <= $numsections and empty($data->nexturl)) {
if ($canviewhidden || $sections[$forward]->uservisible) {
if (!$sections[$forward]->visible) {
$data->nexthidden = true;
}
$data->nextname = get_section_name($course, $sections[$forward]);
$data->nexturl = course_get_url($course, $forward, ['navigation' => true]);
$data->hasnext = true;
}
$forward++;
}

$data->rtl = right_to_left();
$this->data = $data;
return $data;
}

Expand Down
37 changes: 37 additions & 0 deletions classes/output/courseformat/content/sectionselector.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,41 @@ class sectionselector extends \core_courseformat\output\local\content\sectionsel
public function get_template_name(\renderer_base $renderer): string {
return 'format_topcoll/local/content/sectionselector';
}

/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output typically, the renderer that's calling this function
* @return stdClass data context for a mustache template
*/
public function export_for_template(\renderer_base $output): \stdClass {

$format = $this->format;
$course = $format->get_course();

$modinfo = $this->format->get_modinfo();

$data = $this->navigation->export_for_template($output);

// Add the section selector.
$sectionmenu = [];
$sectionmenu[course_get_url($course)->out(false)] = get_string('maincoursepage');
$section = 0;
$numsections = $format->get_last_section_number();
while ($section <= $numsections) {
$thissection = $modinfo->get_section_info($section);
$url = course_get_url($course, $section, ['navigation' => true]);
if ($thissection->uservisible && $url && $section != $data->currentsection) {
$sectionmenu[$url->out(false)] = get_section_name($course, $section);
}
$section++;
}

$select = new \url_select($sectionmenu, '', ['' => get_string('jumpto')]);
$select->class = 'jumpmenu';
$select->formid = 'sectionmenu';

$data->selector = $output->render($select);
return $data;
}
}
4 changes: 2 additions & 2 deletions lang/en/format_topcoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,11 @@
// Information.
$string['information'] = 'Information';
$string['informationsettings'] = 'Information settings';
$string['informationsettingsdesc'] = 'Collapsed Topics format information';
$string['informationsettingsdesc'] = 'Collapsed Topics course format information';
$string['informationchanges'] = 'Changes';
$string['settings'] = 'Settings';
$string['settingssettings'] = 'Settings settings';
$string['settingssettingsdesc'] = 'Collapsed Topics format settings';
$string['settingssettingsdesc'] = 'Collapsed Topics course format settings';
$string['love'] = 'love';
$string['versioninfo'] = 'Release {$a->release}, version {$a->version} on Moodle {$a->moodle}. Made with {$a->love} in Great Britain.';
$string['versionalpha'] = 'Alpha version - Almost certainly contains bugs. This is a development version for developers \'only\'! Don\'t even think of installing on a production server!';
Expand Down

0 comments on commit c21a95a

Please sign in to comment.