From 85e59ac2f356b0920f9221d08ed53f9d1b3a5c1a Mon Sep 17 00:00:00 2001 From: Tim Price Date: Mon, 1 Dec 2014 10:44:49 +1100 Subject: [PATCH 1/2] MDL-48421 navigation: correctly load child categories if parent is loaded --- lib/navigationlib.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 6db3cd230d0..5adc4ff7ad9 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1630,7 +1630,9 @@ class global_navigation extends navigation_node { } 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); + $addedcategories = $this->addedcategories; + unset($addedcategories[$categoryid]); + list($sql, $params) = $DB->get_in_or_equal(array_keys($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}"; From 6eb3da841dfa77b2b53c145749cdba23ced2fa6c Mon Sep 17 00:00:00 2001 From: Tim Price Date: Tue, 16 Dec 2014 11:45:10 +1100 Subject: [PATCH 2/2] MDL-48421 navigation: accounting for potential regression --- lib/navigationlib.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 5adc4ff7ad9..6ba84f9869b 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1632,13 +1632,15 @@ class global_navigation extends navigation_node { // have been loaded $addedcategories = $this->addedcategories; unset($addedcategories[$categoryid]); - list($sql, $params) = $DB->get_in_or_equal(array_keys($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}"; + if (count($addedcategories) > 0) { + list($sql, $params) = $DB->get_in_or_equal(array_keys($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; } else {