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

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

di Sandip Shrestha -
Numero di risposte: 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?

Media dei voti: -
In riposta a Sandip Shrestha

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

di Mary Evans -
Immagine Core developers Immagine Documentation writers Immagine Peer reviewers Immagine Plugin developers Immagine 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 riposta a Sandip Shrestha

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

di Gareth J Barnard -
Immagine Core developers Immagine Particularly helpful Moodlers Immagine Plugin developers

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

In riposta a Gareth J Barnard

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

di 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 riposta a Sandip Shrestha

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

di Mary Evans -
Immagine Core developers Immagine Documentation writers Immagine Peer reviewers Immagine Plugin developers Immagine 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 riposta a Sandip Shrestha

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

di Gareth J Barnard -
Immagine Core developers Immagine Particularly helpful Moodlers Immagine Plugin developers

Dear Sandip,

Yes.

Kind regards,

Gareth

In riposta a Sandip Shrestha

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

di Tim Hunt -
Immagine Core developers Immagine Documentation writers Immagine Particularly helpful Moodlers Immagine Peer reviewers Immagine 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.

In riposta a Tim Hunt

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

di 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.