MDL-37329 Navigation: Enrolled courses in category should be added only.
authorRajesh Taneja <rajesh@moodle.com>
Wed, 20 Feb 2013 03:12:11 +0000 (11:12 +0800)
committerDamyon Wiese <damyon@moodle.com>
Wed, 20 Feb 2013 04:39:21 +0000 (12:39 +0800)
lib/navigationlib.php

index 521a2fb..3a341cb 100644 (file)
@@ -2757,9 +2757,11 @@ class global_navigation_for_ajax extends global_navigation {
               ORDER BY cc.depth ASC, cc.sortorder ASC, cc.id ASC";
         $params = array('categoryid1' => $categoryid, 'categoryid2' => $categoryid);
         $categories = $DB->get_recordset_sql($sql, $params, 0, $limit);
+        $categorylist = array();
         $subcategories = array();
         $basecategory = null;
         foreach ($categories as $category) {
+            $categorylist[] = $category->id;
             context_helper::preload_from_record($category);
             if ($category->id == $categoryid) {
                 $this->add_category($category, $this, $nodetype);
@@ -2780,7 +2782,10 @@ class global_navigation_for_ajax extends global_navigation {
         if ($nodetype === self::TYPE_MY_CATEGORY) {
             $courses = enrol_get_my_courses();
             foreach ($courses as $course) {
-                $this->add_course($course, true, self::COURSE_MY);
+                // Add course if it's in category.
+                if (in_array($course->category, $categorylist)) {
+                    $this->add_course($course, true, self::COURSE_MY);
+                }
             }
         } else {
             $courses = $DB->get_recordset('course', array('category' => $categoryid), 'sortorder', '*' , 0, $limit);