-
Bug
-
Resolution: Fixed
-
Major
-
1.9.12, 2.0.3, 2.1.1, 2.2
-
MOODLE_19_STABLE, MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
-
MOODLE_19_STABLE, MOODLE_20_STABLE, MOODLE_21_STABLE
-
w31_
MDL-27597_m22_catlike -
If you have a course category $cat, with $cat->id == 1 ('Miscellaneous' by default in Moodle installs), then make this function call:
get_categories($cat, NULL, false);
Intending to get all the descendant categories of this category, then you will, also get any categories with an ID starting with 1 (or their sub categories).
e.g. this will also return every category with the ID 10, 15, 105, etc. or a category with the path '/10/25', '/10/26' or '/101/124' etc.
The problem is this line in datalib.php:
JOIN {$CFG->prefix}course_categories ccp
ON (cc.path LIKE ".sql_concat('ccp.path',"'%'").")
(or the Moodle 2.0 version:
JOIN
ccp
ON (cc.path LIKE ".$DB->sql_concat('ccp.path',"'%'").")
)
Searching for cc.path LIKE "/1%" will find all the other categories as well.
Possible solutions:
1. Change the line to:
ON (cc.path LIKE ".sql_concat('ccp.path',"'/%'").") // And the M2.0 equivalent
2. Change the line to:
ON ((cc.id = ccp.id) OR (cc.path LIKE ".sql_concat('ccp.path',"'/%'").")) // And the M2.0 equivalent
Solution 1. will no longer return the parent in the list (which for my purposes would be even better!), solution 2. would be closer to (what I guess is) the intended functionality.