Navigator renderer proposal

Navigator renderer proposal

by Maxim Shiryaev -
Number of replies: 0

Hi.

[Standard language disclaimer: my native are Russian, Pascal, Java(Script), SQL,... - not English or php]

For my customer moodle installation I need some tweaking of a navigation block.

Use case: Several schools with 1-11 forms in them and subjects implemented as a category hierarchy.

  • School No 1 (category)
    • Year 1 (category)
      • Form master course 1 (with cohort enrolment - basically a forum/events not related to specific subjects)
      • Subject courses (category)
        • Math 1 (course with metalink enrolment from Form-master course)
        • Lang 1
        • ...
    • Year 2
      • Form master course 2
      • Subject courses
        • Math 2
        • Lang 2
        • ...
    • ...
  • School No 2

... etc...

The customer prefers hierarhical display of categories/courses in the navigation block. So that form-master course and subject cources are distinct and starting navigation is not bloated with many subjects open.

For the admin it's OK - he sees all the school/form/year/subject as needed.

But when a student (who have access to a single school/year) logs in he sees all the hierarchy as well - starting from the school level. And to access his Math 1 he has to open his single School/Year branch.

The proposal:

Add an option to navigator renderer to promote categories that are single child of their parent to upper level.

Solution: (2.3.1+) blocks/navigation/renderer.php: protected function navigation_node:

  if (count($items)==0) {
    return '';
  }
  // patch begin: count all children of this node.
  // count($items) always return 1 for some reason - bad enumerator?

  $cnt = 0;
  foreach ($items as $a) {
    $cnt = $cnt+1;
  };
  // patch end

  $lis = array();
  foreach ($items as $item) {
    // patch begin
    // now check that this node is a single one.
    // and if it is - skip it returning content from the next level

    if ($cnt == 1 && $item->type == navigation_node::TYPE_CATEGORY) {
      return $this->navigation_node($item->children, array(),
             $expansionlimit, $options, $depth);

    }
    // patch end
....

Result:

Student logs in - without a patch:

  • My courses
    • School No 1 (category)
      • Year 1 (category)
        • Form master course 1 (with cohort enrolment - basically a forum/events not related to specific subjects)
        • Subject courses (category)
          • Math 1 (course with metalink enrolment from Form master course)
          • Lang 1

Student logs in - with a patch:

  • My courses
    • Form master course 1
    • Subjecs
      • Math 1
      • Lang 1

Now since School No 1 and Year 1 are single nodes the deepr levels come upper.

May be the standard navigation block will benefit from such tweak if implemented as an option and depending on roles. (Admins should see the true hierarchy).

By the way, how to detect that a user has an admin role or any other role but a student?

And for some reason I cannot override this renderer in a theme.

If add

include_once($CFG->dirroot . "/blocks/navigator/renderer.php");
class theme_rocket_block_navigation_renderer extends block_navigation_renderer {

to a Rocket theme rederers.php and copy a code from navigator/renderer the site comes blank.

Maxim.

 

Average of ratings: -