Skip to content
Browse files

Merge branch 'wip-MDL-24202-m20' of git://github.com/samhemelryk/mood…

…le into MOODLE_20_STABLE
  • Loading branch information...
2 parents 22a35ff + f24f704 commit 081d16475ba905ed75e4d0cf6d2abd88a56abc77 @stronk7 stronk7 committed Aug 29, 2011
Showing with 18 additions and 7 deletions.
  1. +18 −7 lib/navigationlib.php
View
25 lib/navigationlib.php
@@ -825,6 +825,8 @@ class global_navigation extends navigation_node {
protected $rootnodes = array();
/** @var bool */
protected $showemptysections = false;
+ /** @var bool */
+ protected $showcategories = null;
/** @var array */
protected $extendforuser = array();
/** @var navigation_cache */
@@ -943,14 +945,9 @@ public function initialise() {
$limit = $CFG->navcourselimit;
}
- if (!empty($CFG->navshowcategories) && $DB->count_records('course_categories') == 1) {
- // There is only one category so we don't want to show categories
- $CFG->navshowcategories = false;
- }
-
$mycourses = enrol_get_my_courses(NULL, 'visible DESC,sortorder ASC', $limit);
$showallcourses = (count($mycourses) == 0 || !empty($CFG->navshowallcourses));
- $showcategories = ($showallcourses && !empty($CFG->navshowcategories));
+ $showcategories = ($showallcourses && $this->show_categories());
$issite = ($this->page->course->id != SITEID);
$ismycourse = (array_key_exists($this->page->course->id, $mycourses));
@@ -1203,6 +1200,20 @@ public function initialise() {
}
return true;
}
+
+ /**
+ * Returns true is courses should be shown within categories on the navigation.
+ *
+ * @return bool
+ */
+ protected function show_categories() {
+ global $CFG, $DB;
+ if ($this->showcategories === null) {
+ $this->showcategories = !empty($CFG->navshowcategories) && $DB->count_records('course_categories') > 1;
+ }
+ return $this->showcategories;
+ }
+
/**
* Checks the course format to see whether it wants the navigation to load
* additional information for the course.
@@ -2025,7 +2036,7 @@ public function add_course(stdClass $course, $forcegeneric = false, $ismycourse
}
if (!$ismycourse && !$issite && !empty($course->category)) {
- if (!empty($CFG->navshowcategories)) {
+ if ($this->show_categories()) {
// We need to load the category structure for this course
$this->load_all_categories($course->category);
}

0 comments on commit 081d164

Please sign in to comment.
Something went wrong with that request. Please try again.