MDL-77946 access: fix category sort order of capability contexts.

This commit is contained in:
Paul Holden 2023-04-18 10:23:01 +01:00
parent 5d320dd7d1
commit ebcc7e58ce
No known key found for this signature in database
GPG key ID: A81A96D6045F6164
2 changed files with 17 additions and 14 deletions

View file

@ -4266,21 +4266,21 @@ function get_user_capability_contexts(string $capability, bool $getcategories, $
$fieldlist = \core\access\get_user_capability_course_helper::map_fieldnames($categoryfieldsexceptid);
if ($categoryorderby) {
$fields = explode(',', $categoryorderby);
$orderby = '';
$categoryorderby = '';
foreach ($fields as $field) {
if ($orderby) {
$orderby .= ',';
if ($categoryorderby) {
$categoryorderby .= ',';
}
$orderby .= 'c.'.$field;
$categoryorderby .= 'c.'.$field;
}
$orderby = 'ORDER BY '.$orderby;
$categoryorderby = 'ORDER BY '.$categoryorderby;
}
$rs = $DB->get_recordset_sql("
SELECT c.id $fieldlist
FROM {course_categories} c
JOIN {context} x ON c.id = x.instanceid AND x.contextlevel = ?
$contextlimitsql
$orderby", array_merge([CONTEXT_COURSECAT], $contextlimitparams));
$categoryorderby", array_merge([CONTEXT_COURSECAT], $contextlimitparams));
$basedlimit = $limit;
foreach ($rs as $category) {
$categories[] = $category;
@ -4289,6 +4289,7 @@ function get_user_capability_contexts(string $capability, bool $getcategories, $
break;
}
}
$rs->close();
}
$courses = [];