Having different menu items in the menu bar depending on courses

Having different menu items in the menu bar depending on courses

Mari Cruz García發表於
Number of replies: 2

Dear all,

I have been asked to edit the custom menu bar (the horizontal bar whose menu items in Moodle 2.2 you can create and edit using the 'Theme settings' option).

We want that for the frontpage and most of the courses, students and staff can see the current items:

https://learning.health.org.kw/

Home, PG Programme Course, What is new, etc..

However, there will be some specific courses, all of them included under a category called 'MSc Dissertation Portal', for which we want to show a specific custom bar ovewritting the items in the general custom bar.

I have looked into the property of the menu items using the dom inspector of Firebug:

<a href="http://www.dasmaninstitute.org/kuwait-scotland-education" title="PG Programme Course" class="yui3-menuitem-content" role="menuitem" tabindex="-1" id="yui_3_4_1_1_1369737400059_384">PG Programme Course</a>

so there seems to be a yui class.
I found this thread, but not of the answers are relevant to my case:

https://moodle.org/mod/forum/discuss.php?d=171462

We use a customised theme which is based on 'canvas' and 'based'

Following this tutorial:

http://docs.moodle.org/dev/Themes_2.0_extending_the_custom_menu

It looks that the best way of achieving my goal is extending the core_renderers methods of Moodle by adding a new renderer for the theme that overwrites the general menu bar when a user logs in specific courses (all the courses belonging to the MSc Dissertation Portal category) adding its own menu items.

However, this way looks a bit complicated to me, since I don't master all the php functions in Moodle.

I would like to ask the community if there is any easier way of having a different custom menu bar for the courses in an specific category.

Thank you very much for your advice.

評比平均分數: -
In reply to Mari Cruz García

Re: Having different menu items in the menu bar depending on courses

Richard Oelmann發表於
Core developers的相片 Plugin developers的相片 Testers的相片

Themes can now have their own custom menu in the settings page, so one solution may be to extend your theme with that functionality and then duplicate your theme (or use a child one with just the different settings page) and use apply the second theme as needed to just that course/category.

I believe aaradyha is one such theme that you could look at for the custommenu within the theme settings page.

Richard

In reply to Mari Cruz García

Re: Having different menu items in the menu bar depending on courses

Mari Cruz García發表於

Hello,

I have been doing some further research about this. I think that I am in the right path, but I just want to share my approach with the community, just in case:

Instead of modifying the general core_renderers method $OUTPUT->custom_menu()

I plan to set us a condition whenever the renderer is called.

For example, in frontpage.php, general.php and other pages under the folder mytheme/layout

instead of having:

$custommenu = $OUTPUT->custom_menu();

I would like to have

/*get the categoryid where the user is */

$context = $PAGE->context;
$coursecontext = $context->get_course_context();
$categoryid = null;
if ($coursecontext) {
$courseid = $coursecontext->instanceid;
$course = $DB->get_record('course', array('id' => $courseid), 'id, category');
if ($course) {
$categoryid = $course->category;
}
}

if ($categoryid==20) {
 
$custommenu = $OUTPUT->my_custom_menu();

} else {
$custommenu = $OUTPUT->custom_menu();
 
}

where my_custom_menu is the renderer for the theme that overrides the general renderer custom_menu.

Do you think that it will work in this way?

Thank you very much for your advice.