section wise navigation block content for topics format course in custom theme

section wise navigation block content for topics format course in custom theme

by Sandip Shrestha -
Number of replies: 11

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?

Average of ratings: -
In reply to Sandip Shrestha

Re: section wise navigation block content for topics format course in custom theme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi, 

Unfortunatly I am limited with my knowledge of PHP and such, however, I would not consider this question a Theme related issue although it may in part be related to a custom theme by nature of the changes you are attempting to make.

With this in mind I'm very tempted to move this to the Developers Forum if no one here replies in depth within the next 24hrs.

I am really sorry I can't help...but I have a feeling there is an easier way to achieve what you want!

Cheers

Mary

In reply to Mary Evans

Re: section wise navigation block content for topics format course in custom theme

by Sandip Shrestha -

Thank you for replying Mary. I too think this question will be better suited for the developers section now. smile

In reply to Sandip Shrestha

Re: section wise navigation block content for topics format course in custom theme

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Probably get an instance of the 'course' renderer and look at what methods it supplies.

In reply to Gareth J Barnard

Re: section wise navigation block content for topics format course in custom theme

by Sandip Shrestha -

Dear Gareth,

can you elaborate a little more? Do you mean I should look into the moodle's  course's renderer.php and see what the functions there provide?

In reply to Sandip Shrestha

Re: section wise navigation block content for topics format course in custom theme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

This is the course/format/topics/renderer.php from the Moodle 2.9 stable branch.

https://github.com/lazydaisy/moodle/blob/MOODLE_29_STABLE/course/format/topics/renderer.php

In reply to Mary Evans

Re: section wise navigation block content for topics format course in custom theme

by Sandip Shrestha -

Dear Mary, 

Thank you for the response. smile


In reply to Sandip Shrestha

Re: section wise navigation block content for topics format course in custom theme

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Sandip,

Yes.

Kind regards,

Gareth

In reply to Gareth J Barnard

Re: section wise navigation block content for topics format course in custom theme

by Sandip Shrestha -

Dear Gareth, 

Thank you for the response. smile

In reply to Sandip Shrestha

Re: section wise navigation block content for topics format course in custom theme

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Definitely don't look at random URL parameters, and expect it to mean anything consistently on different Moodle pages.

Information about the current page is stored in the Moodle page object. In a block you can access that as $this->page.

$this->page->cm->id is probably what you want, or $this->page->cm->section, etc.

The page class is defined in lib/pagelib.php.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: section wise navigation block content for topics format course in custom theme

by Sandip Shrestha -

Dear Tim,

    Thank you for your response. I am new to moodle and programming in general. Your redirection is the right path for me and has worked absolutely right for this particular issue. 


I have now made my function parameterized function theme_activity_navigation($id){...}  and I am retrieving the page id from a page object context as $id =$this->page->cm->id.