Moodle version: 2.9.6 (Build: 20160509)
I am trying to implement a custom navigation block for my custom theme that only shows the links to contents in the particular section.
I have implemented a function to fetch relative data from database and echoed out the content from function in the layout.
function theme_activity_navigation()
{
global $CFG, $COURSE, $DB, $USER;
$id = optional_param('id', null, PARAM_INT);
if (!$id) return null;
$section_id = $DB->get_record('course_modules', array('id' => $id, 'course' => $COURSE->id), 'section', IGNORE_MISSING)->section;
$section_sequence = explode(",", $DB->get_field("course_sections", "sequence", array("course" => $COURSE->id, "id" => $section_id)));
$html = '';
foreach ($section_sequence as $sequence) {
$custom_class = '';
if ($sequence == $id) $custom_class .= 'active';
if (sajha_iscomplete_module($sequence)) $custom_class .= ' completed';
$cm = get_coursemodule_from_id('', $sequence, 0, false, IGNORE_MISSING);
$html .= "<li class='{$custom_class}'><a href='{$CFG->wwwroot}/mod/{$cm->modname}/view.php?id={$sequence}'>{$cm->name}</a></li>";
}
return $html;
}
I have used optional_param('id', null, PARAM_INT); to filter sections based content.
optional_param('id', null, PARAM_INT); will get '48' if I am visiting url 'moodlesite.com/mod/page/view.php?id=48'.
This works fine.
However the problem arises in quiz attempt page. Since I use optional_param('id', null, PARAM_INT); and moodle quiz attempt url looks something like 'moodlesite.com/mod/quiz/attempt.php?attempt=41' I can not fetch the course activity id data to do a database hit.
and the function theme_activity_navigation() return null.
Is there a better way to get navigation lists per section or maybe the above function can be modified to fix the quiz issue?