Skip to content

Commit

Permalink
Merge branch 'wip-MDL-24202-m21' of git://github.com/samhemelryk/mood…
Browse files Browse the repository at this point in the history
…le into MOODLE_21_STABLE
  • Loading branch information
stronk7 committed Aug 29, 2011
2 parents 7816f5a + 208b9e2 commit 4524a47
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,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 */
Expand Down Expand Up @@ -1055,14 +1057,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));

Expand Down Expand Up @@ -1315,6 +1312,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.
Expand Down Expand Up @@ -2137,7 +2148,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);
}
Expand Down

0 comments on commit 4524a47

Please sign in to comment.