-
Bug
-
Resolution: Fixed
-
Minor
-
2.7.3, 2.8.1
-
MOODLE_27_STABLE, MOODLE_28_STABLE
-
MOODLE_27_STABLE, MOODLE_28_STABLE
-
master-48421
-
When the system has multiple levels of subcategories, they are not all being loaded correctly into the navigation block under Courses or My courses. I discovered this with a structure like this:
- Category 1
- Subcategory 1a
- Subsubcategory 1aA
- courses
- Subcategory 1b
- Subsubcategory 1bB
- courses
- Subcategory 1a
- Category 2
Where the block would load all of the courses and subcategories for 1a but none of the subcategories in 1b. The full category list and block display can be seen in the 2 screenshots attached.
This appears to be caused by the parent category being loaded before the child categories are loaded in the block. I'm not sure how the load order for course categories is being set, so I am unable to provide more specific steps to replicate.
The issue is being caused by a bug in the load_all_categories function in lib/navigationlib.php, specifically this section:
else if (array_key_exists($categoryid, $this->addedcategories)) {
// The category itself has been loaded already so we just need to ensure its subcategories
// have been loaded
list($sql, $params) = $DB->get_in_or_equal(array_keys($this->addedcategories), SQL_PARAMS_NAMED, 'parent', false);
if ($showbasecategories) {
// We need to include categories with parent = 0 as well
$sqlwhere .= " AND (cc.parent = :categoryid OR cc.parent = 0) AND cc.parent {$sql}";
} else {
// All we need is categories that match the parent
$sqlwhere .= " AND cc.parent = :categoryid AND cc.parent {$sql}";
}
$params['categoryid'] = $categoryid;
}
which generates an SQL query that contains "cc.parent = categoryid AND cc.parent NOT IN (..., categoryid, ...)"