Creating a custom block with dropdown menu for topics

Creating a custom block with dropdown menu for topics

by Martin Arturo Martinez Espinoza -
Number of replies: 1

Dear friends, 

I have some questions regarding this idea and I will try to be as clear as possible. What I want to do is create a Moodle block where I generate a drop down menu that has the topics from the course and the students can use this block as their navigation menu. To give an example I will attach two screenshots:


1. The first one is to show the order and how the topics  look like: Introduction, Week 1, Week 2,.... and how in each topic there are several activities to consider



2. The next one shows my current custom block version with static info about the links but I cannot link the items that are in my dropdown which is why I am asking if anyone knows, first, how to make the menu dynamic so that after a new item, activity is created it is registered and added to the menu and, second, how to make the dropdown link to the respectivy resource/activity



Any idea or suggestion is welcome. Thanks



Average of ratings: -
In reply to Martin Arturo Martinez Espinoza

Re: Creating a custom block with dropdown menu for topics

by Dominique Palumbo -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi,

you can get all the data with the Moodle API (or with some queries)

$modinfo = get_fast_modinfo($course);
$cm = $modinfo->get_cm($cmid);

https://docs.moodle.org/dev/Module_visibility_and_display#get_fast_modinfo_data

To keep it uptodate  even after a section or an activity is added or removed. You can do it with ajax .

I mean each time the user click on a drop down you call the Moodle api by an ajax call and fill the drop down again.

(with jquery is easy. But don't forget the security)

Hope it's help.

Dominique.