Skip to content

Commit

Permalink
MDL-78729 grade: Improve grade library to support dynamic name handli…
Browse files Browse the repository at this point in the history
…ng for non-English names
  • Loading branch information
EliZard12 committed Nov 30, 2024
1 parent e5211c6 commit 925aeec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions grade/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2489,11 +2489,12 @@ public function get_cell_action_menu(array $element, string $mode, grade_plugin_
}

if (($element['type'] == 'userfield') && ($element['name'] == 'fullname')) {
$sortlink->param('sortitemid', 'firstname');
$usernamefields = core_user::get_user_full_name_fields();
$sortlink->param('sortitemid', reset($usernamefields));
$context->ascendingfirstnameurl = $this->get_sorting_link($sortlink, $gpr);
$context->descendingfirstnameurl = $this->get_sorting_link($sortlink, $gpr, 'desc');

$sortlink->param('sortitemid', 'lastname');
$sortlink->param('sortitemid', end($usernamefields));
$context->ascendinglastnameurl = $this->get_sorting_link($sortlink, $gpr);
$context->descendinglastnameurl = $this->get_sorting_link($sortlink, $gpr, 'desc');
} else {
Expand Down
5 changes: 3 additions & 2 deletions grade/report/grader/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ private function setup_sortitemid(string $sort = '') {
$SESSION->gradeuserreport = new stdClass();
}

$namefields = core_user::get_user_full_name_fields();
if ($this->sortitemid) {
if (!isset($SESSION->gradeuserreport->sort)) {
$this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
Expand All @@ -378,10 +379,10 @@ private function setup_sortitemid(string $sort = '') {
} else {
// not requesting sort, use last setting (for paging)

if (isset($SESSION->gradeuserreport->sortitemid)) {
if (isset($SESSION->gradeuserreport->sortitemid) && in_array($SESSION->gradeuserreport->sortitemid, $namefields)) {
$this->sortitemid = $SESSION->gradeuserreport->sortitemid;
} else {
$this->sortitemid = 'lastname';
$this->sortitemid = end($namefields);
}

if (isset($SESSION->gradeuserreport->sort)) {
Expand Down
5 changes: 3 additions & 2 deletions grade/report/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,14 @@ public function setup_users() {
$filtersurnamekey = "filtersurname-{$this->context->id}";

$this->userwheresql = "";
$usernamefields = core_user::get_user_full_name_fields();
$this->userwheresql_params = array();
if (!empty($SESSION->gradereport[$filterfirstnamekey])) {
$this->userwheresql .= ' AND '.$DB->sql_like('u.firstname', ':firstname', false, false);
$this->userwheresql .= ' AND '.$DB->sql_like('u.' . reset($usernamefields), ':firstname', false, false);
$this->userwheresql_params['firstname'] = $SESSION->gradereport[$filterfirstnamekey] . '%';
}
if (!empty($SESSION->gradereport[$filtersurnamekey])) {
$this->userwheresql .= ' AND '.$DB->sql_like('u.lastname', ':lastname', false, false);
$this->userwheresql .= ' AND '.$DB->sql_like('u.' . end($usernamefields), ':lastname', false, false);
$this->userwheresql_params['lastname'] = $SESSION->gradereport[$filtersurnamekey] . '%';
}

Expand Down

0 comments on commit 925aeec

Please sign in to comment.