Skip to content

Commit

Permalink
MDL-71697 Custom user field support: Grade report grader
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud Kassaei committed Jun 16, 2021
1 parent 9533e8d commit c259a06
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
13 changes: 6 additions & 7 deletions grade/report/grader/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,8 @@ public function load_users() {
list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context, '', 0, $showonlyactiveenrol);

// Fields we need from the user table.
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_userpic();
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$userfieldsapi = \core_user\fields::for_identity($this->context)->with_userpic();
$userfieldssql = $userfieldsapi->get_sql('u', true, '', '', false);

// We want to query both the current context and parent contexts.
list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($this->context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'relatedctx');
Expand Down Expand Up @@ -472,9 +471,10 @@ public function load_users() {

$params = array_merge($gradebookrolesparams, $this->userwheresql_params, $this->groupwheresql_params, $enrolledparams, $relatedctxparams);
}

$sql = "SELECT $userfields
$params = array_merge($userfieldssql->params, $params);
$sql = "SELECT {$userfieldssql->selects}
FROM {user} u
{$userfieldssql->joins}
JOIN ($enrolledsql) je ON je.id = u.id
$this->groupsql
$sortjoin
Expand Down Expand Up @@ -659,8 +659,7 @@ public function get_left_rows($displayaverages) {

$strfeedback = $this->get_lang_string("feedback");

// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core_user\fields::get_identity_fields($this->context, false);
$extrafields = \core_user\fields::get_identity_fields($this->context);

$arrows = $this->get_sort_arrows($extrafields);

Expand Down
23 changes: 18 additions & 5 deletions grade/report/grader/tests/behat/ajax_grader.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ Feature: Using the AJAX grading feature of Grader report to update grades and fe
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "custom profile fields" exist:
| datatype | shortname | name |
| text | frog | Favourite frog |
And the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | t1 |
| student1 | Student | 1 | student1@example.com | s1 |
| student2 | Student | 2 | student2@example.com | s2 |
| student3 | Student | 3 | student3@example.com | s3 |
| username | firstname | lastname | email | idnumber | profile_field_frog |
| teacher1 | Teacher | 1 | teacher1@example.com | t1 | |
| student1 | Student | 1 | student1@example.com | s1 | litle yellow frog |
| student2 | Student | 2 | student2@example.com | s2 | prince frog |
| student3 | Student | 3 | student3@example.com | s3 | |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
Expand Down Expand Up @@ -251,3 +254,13 @@ Feature: Using the AJAX grading feature of Grader report to update grades and fe
And I click on "The grade entered for Item VU for Student 2 is more than the maximum allowed" "text"
And I should not see "The grade entered for Item VU for Student 2 is more than the maximum allowed"
And the grade for "Student 2" in grade item "Item VU" should match "66.00"

@javascript
Scenario: Teacher can see user custom filed columns as additional user identity
Given the following config values are set as admin:
| showuseridentity | email,profile_field_frog |
And I log in as "teacher1"
And I am on "Course 1" course homepage
When I navigate to "View > Grader report" in the course gradebook
Then I should see "litle yellow frog" in the "student1" "table_row"
And I should see "prince frog" in the "student2" "table_row"

0 comments on commit c259a06

Please sign in to comment.