Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…le into MOODLE_20_STABLE
  • Loading branch information...
commit 081d16475ba905ed75e4d0cf6d2abd88a56abc77 2 parents 22a35ff + f24f704
Eloy Lafuente (stronk7) stronk7 authored

Showing 1 changed file with 18 additions and 7 deletions. Show diff stats Hide diff stats

  1. +18 7 lib/navigationlib.php
25 lib/navigationlib.php
@@ -825,6 +825,8 @@ class global_navigation extends navigation_node {
825 825 protected $rootnodes = array();
826 826 /** @var bool */
827 827 protected $showemptysections = false;
  828 + /** @var bool */
  829 + protected $showcategories = null;
828 830 /** @var array */
829 831 protected $extendforuser = array();
830 832 /** @var navigation_cache */
@@ -943,14 +945,9 @@ public function initialise() {
943 945 $limit = $CFG->navcourselimit;
944 946 }
945 947
946   - if (!empty($CFG->navshowcategories) && $DB->count_records('course_categories') == 1) {
947   - // There is only one category so we don't want to show categories
948   - $CFG->navshowcategories = false;
949   - }
950   -
951 948 $mycourses = enrol_get_my_courses(NULL, 'visible DESC,sortorder ASC', $limit);
952 949 $showallcourses = (count($mycourses) == 0 || !empty($CFG->navshowallcourses));
953   - $showcategories = ($showallcourses && !empty($CFG->navshowcategories));
  950 + $showcategories = ($showallcourses && $this->show_categories());
954 951 $issite = ($this->page->course->id != SITEID);
955 952 $ismycourse = (array_key_exists($this->page->course->id, $mycourses));
956 953
@@ -1203,6 +1200,20 @@ public function initialise() {
1203 1200 }
1204 1201 return true;
1205 1202 }
  1203 +
  1204 + /**
  1205 + * Returns true is courses should be shown within categories on the navigation.
  1206 + *
  1207 + * @return bool
  1208 + */
  1209 + protected function show_categories() {
  1210 + global $CFG, $DB;
  1211 + if ($this->showcategories === null) {
  1212 + $this->showcategories = !empty($CFG->navshowcategories) && $DB->count_records('course_categories') > 1;
  1213 + }
  1214 + return $this->showcategories;
  1215 + }
  1216 +
1206 1217 /**
1207 1218 * Checks the course format to see whether it wants the navigation to load
1208 1219 * additional information for the course.
@@ -2025,7 +2036,7 @@ public function add_course(stdClass $course, $forcegeneric = false, $ismycourse
2025 2036 }
2026 2037
2027 2038 if (!$ismycourse && !$issite && !empty($course->category)) {
2028   - if (!empty($CFG->navshowcategories)) {
  2039 + if ($this->show_categories()) {
2029 2040 // We need to load the category structure for this course
2030 2041 $this->load_all_categories($course->category);
2031 2042 }

0 comments on commit 081d164

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