MDL-24202 navigation Fixed bug caused by navigation overriding a CFG setting
This commit is contained in:
+18
-7
@@ -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 @@ class global_navigation extends navigation_node {
|
||||
$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 @@ class global_navigation extends navigation_node {
|
||||
}
|
||||
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 @@ class global_navigation extends navigation_node {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user