MDL-43675 navigation: courses branch is now recognised as expandable
authorSam Hemelryk <sam@moodle.com>
Mon, 13 Jan 2014 23:29:36 +0000 (12:29 +1300)
committerSam Hemelryk <sam@moodle.com>
Thu, 16 Jan 2014 21:27:10 +0000 (10:27 +1300)
lib/ajax/getnavbranch.php
lib/navigationlib.php

index 957d0a9..457f8d9 100644 (file)
@@ -112,16 +112,16 @@ try {
     $html = ob_get_contents();
     ob_end_clean();
 } catch (Exception $e) {
     $html = ob_get_contents();
     ob_end_clean();
 } catch (Exception $e) {
-    die('Error: '.$e->getMessage());
+    throw new coding_exception('Error: '.$e->getMessage());
 }
 
 // Check if the buffer contianed anything if it did ERROR!
 if (trim($html) !== '') {
 }
 
 // Check if the buffer contianed anything if it did ERROR!
 if (trim($html) !== '') {
-    die('Errors were encountered while producing the navigation branch'."\n\n\n".$html);
+    throw new coding_exception('Errors were encountered while producing the navigation branch'."\n\n\n".$html);
 }
 // Check that branch isn't empty... if it is ERROR!
 }
 // Check that branch isn't empty... if it is ERROR!
-if (empty($branch) || $branch->nodetype !== navigation_node::NODETYPE_BRANCH) {
-    die('No further information available for this branch');
+if (empty($branch) || ($branch->nodetype !== navigation_node::NODETYPE_BRANCH && !$branch->isexpandable)) {
+    throw new coding_exception('No further information available for this branch');
 }
 
 // Prepare an XML converter for the branch
 }
 
 // Prepare an XML converter for the branch
index 4ae18b2..06081c0 100644 (file)
@@ -2748,6 +2748,9 @@ class global_navigation_for_ajax extends global_navigation {
         $this->rootnodes['site']    = $this->add_course($SITE);
         $this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my'), self::TYPE_ROOTNODE, null, 'mycourses');
         $this->rootnodes['courses'] = $this->add(get_string('courses'), null, self::TYPE_ROOTNODE, null, 'courses');
         $this->rootnodes['site']    = $this->add_course($SITE);
         $this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my'), self::TYPE_ROOTNODE, null, 'mycourses');
         $this->rootnodes['courses'] = $this->add(get_string('courses'), null, self::TYPE_ROOTNODE, null, 'courses');
+        // The courses branch is always displayed, and is always expandable (although may be empty).
+        // This mimicks what is done during {@link global_navigation::initialise()}.
+        $this->rootnodes['courses']->isexpandable = true;
 
         // Branchtype will be one of navigation_node::TYPE_*
         switch ($this->branchtype) {
 
         // Branchtype will be one of navigation_node::TYPE_*
         switch ($this->branchtype) {