MDL-79962 roles: consistent sorting of role entity name column.

The "name" field is typically omitted for default/pre-defined roles,
which should be accounted for when sorting.
This commit is contained in:
Paul Holden 2023-11-01 13:05:59 +00:00
parent e4d1369475
commit 7c76e9223b
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164

View File

@ -97,7 +97,7 @@ class role extends base {
->set_type(column::TYPE_TEXT)
->add_fields("{$rolealias}.name, {$rolealias}.shortname, {$rolealias}.id, {$contextalias}.id AS contextid")
->add_fields(context_helper::get_preload_record_columns_sql($contextalias))
->set_is_sortable(true)
->set_is_sortable(true, ["CASE WHEN {$rolealias}.name = '' THEN {$rolealias}.shortname ELSE {$rolealias}.name END"])
->set_callback(static function($name, stdClass $role): string {
if ($name === null) {
return '';