Merge branch 'MDL-31122-master' of git://github.com/sammarshallou/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 25 Jan 2012 00:52:25 +0000 (01:52 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 25 Jan 2012 00:52:25 +0000 (01:52 +0100)
1  2 
lib/navigationlib.php

diff --combined lib/navigationlib.php
@@@ -127,6 -127,8 +127,8 @@@ class navigation_node implements render
      protected static $fullmeurl = null;
      /** @var bool toogles auto matching of active node */
      public static $autofindactive = true;
+     /** @var mixed If set to an int, that section will be included even if it has no activities */
+     public $includesectionnum = false;
  
      /**
       * Constructs a new navigation_node
@@@ -1172,13 -1174,29 +1174,29 @@@ class global_navigation extends navigat
                      }
  
                      $this->add_course_essentials($coursenode, $course);
+                     // Get section number from $cm (if provided) - we need this
+                     // before loading sections in order to tell it to load this section
+                     // even if it would not normally display (=> it contains only
+                     // a label, which we are now editing)
+                     $sectionnum = isset($cm->sectionnum) ? $cm->sectionnum : 0;
+                     if ($sectionnum) {
+                         // This value has to be stored in a member variable because
+                         // otherwise we would have to pass it through a public API
+                         // to course formats and they would need to change their
+                         // functions to pass it along again...
+                         $this->includesectionnum = $sectionnum;
+                     } else {
+                         $this->includesectionnum = false;
+                     }
                      // Load the course sections into the page
                      $sections = $this->load_course_sections($course, $coursenode);
                      if ($course->id != SITEID) {
                          // Find the section for the $CM associated with the page and collect
                          // its section number.
-                         if (isset($cm->sectionnum)) {
-                             $cm->sectionnumber = $cm->sectionnum;
+                         if ($sectionnum) {
+                             $cm->sectionnumber = $sectionnum;
                          } else {
                              foreach ($sections as $section) {
                                  if ($section->id == $cm->section) {
                          }
                      }
                      $activities[$cmid] = $activity;
-                     $sections[$key]->hasactivites = true;
+                     if ($activity->display) {
+                         $sections[$key]->hasactivites = true;
+                     }
                  }
              }
              $this->cache->set('course_sections_'.$course->id, $sections);
              if ($course->id == SITEID) {
                  $this->load_section_activities($coursenode, $section->section, $activities);
              } else {
-                 if ((!$viewhiddensections && !$section->visible) || (!$this->showemptysections && !$section->hasactivites)) {
+                 if ((!$viewhiddensections && !$section->visible) || (!$this->showemptysections &&
+                         !$section->hasactivites && $this->includesectionnum !== $section->section)) {
                      continue;
                  }
                  if ($namingfunctionexists) {
@@@ -4047,8 -4068,6 +4068,8 @@@ class navigation_json 
              $attributes['link'] = $child->action;
          } else if ($child->action instanceof moodle_url) {
              $attributes['link'] = $child->action->out();
 +        } else if ($child->action instanceof action_link) {
 +            $attributes['link'] = $child->action->url->out();
          }
          $attributes['hidden'] = ($child->hidden);
          $attributes['haschildren'] = ($child->children->count()>0 || $child->type == navigation_node::TYPE_CATEGORY);