Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Navigation 2.0 navbar proposal: Difference between revisions

From MoodleDocs
Line 94: Line 94:


[[Navigation 2.0 implementation plan]]
[[Navigation 2.0 implementation plan]]
[http://moodle.org/mod/forum/discuss.php?d=128002 Forum Discussion]

Revision as of 08:51, 13 July 2009

Navigation Bar in Moodle 2.0

Currently I am aiding Tim and his mega-development effort by looking into what can be done with the navigation bar in Moodle 2.0. The end desire is that build_navigation() is deprecated and replaced by a new OO navbar.

We would obviously like this new navbar to be self responsible whilst still being flexible enough that you can add to it as you need to.

The following is my current thinking on this topic and I would love to know your thoughts on the matter, as well as any changes or work-overs you can spot.

The Plan

As suggested in Navigation 2.0 the navbar object will be made available through $OUTPUT->navbar, both for output and interaction. It will be set up to generate as much of the navbar as it possibly can without any input, and allow the developer to add items to the navbar as they wish.

By default the navigation bar will generate the following items (depending on what is available):

  • Site's short name
  • Course categories (1..n)
  • Course short name
  • Module plural (e.g. forums, SCORMs/AICCs)
  • Module's name

Also worth noting is that when looking at the structure of a Moodle course it made more sense to me that rather than adding an item for the modules plural name, an item should be added for the course section (e.g. week 1, week 2, week 3) however as there is no page specifically for the course section this is not possible. I will however comment an appropriate point for which this could be modified should this ever be an option.

Internal Operation

The navbar object will be initialised by $PAGE at the same time that theme and output are initialised (PAGE::initialise_theme_and_output) by calling an internal method of navbar $this->_navbar = navbar::load(); The load function for navbar will then proceed to investigate the PAGE object in order to work out what it can automatically build. In order to aid the navbar in its auto-generation the following functions should be called if appropriate. $PAGE->set_cm($cm); $PAGE->set_course($course); $PAGE->set_category_by_id($id); In actuality only $PAGE->set_category_by_id() is needed to be called if appropriate as both $PAGE->set_course() and $PAGE->set_cm() are called for you by require_login()

Generation of navbar items will be undertaken by one or more of the following three internal functions depending on what level of information is available. navbar::generate_for_category(); // Called if cm, course, and/or category have been set navbar::generate_for_course(); // Called if cm or course have been set navbar::generate_for_cm(); // Called only if cm has been set Each of the functions will add items for its appropriate object (cm, course, category) to the item stack. When the navbar output function is called any items that the user has added will be added to the end of the item stack, and then the navbar HTML will be generated.

Interaction

When developing code for Moodle the following methods can be used to interact with the navbar. $OUTPUT->navbar->add(title, url, type[optional]); // Add a new navbar item

Implementation

The plan is to deprecate build_navigation and would be done using the above planned code in the following manner.

Replace: $navlinks = array(); if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $course->id)) || has_capability('moodle/site:viewparticipants', $syscontext)) {

   $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'core');

} $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id", 'type' => 'title'); $navlinks[] = array('name' => $strforumposts, 'link' => , 'type' => 'title'); $navlinks[] = array('name' => $strmode, 'link' => , 'type' => 'title'); $navigation = build_navigation($navlinks); print_header("$course->shortname: $fullname: $strmode", $course->fullname,$navigation);

With: if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $course->id)) || has_capability('moodle/site:viewparticipants', $syscontext)) {

   $OUTPUT->navbar->add($strparticipants, $CFG->wwwroot.'/user/index.php?id='.$course->id);

} $OUTPUT->navbar->add($strforumposts); $OUTPUT->navbar->add($strmode); $PAGE->set_heading($course->fullname); echo $OUTPUT->header();

In the template: if ($navigation) { // This is the navigation bar with breadcrumbs  ?>