diff --git a/mod/quiz/report/attemptsreport.php b/mod/quiz/report/attemptsreport.php index c54f2efa091..1b231718c65 100644 --- a/mod/quiz/report/attemptsreport.php +++ b/mod/quiz/report/attemptsreport.php @@ -203,8 +203,7 @@ abstract class quiz_attempts_report extends quiz_default_report { $headers[] = get_string('firstname'); } - // 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); foreach ($extrafields as $field) { $columns[] = $field; $headers[] = \core_user\fields::get_display_name($field); @@ -218,8 +217,8 @@ abstract class quiz_attempts_report extends quiz_default_report { protected function configure_user_columns($table) { $table->column_suppress('picture'); $table->column_suppress('fullname'); - // 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); foreach ($extrafields as $field) { $table->column_suppress($field); } diff --git a/mod/quiz/report/attemptsreport_table.php b/mod/quiz/report/attemptsreport_table.php index 48509bb2bdf..4f7935181ea 100644 --- a/mod/quiz/report/attemptsreport_table.php +++ b/mod/quiz/report/attemptsreport_table.php @@ -423,10 +423,10 @@ abstract class quiz_attempts_report_table extends table_sql { $fields .= "\n(CASE WHEN $this->qmsubselect THEN 1 ELSE 0 END) AS gradedattempt,"; } - // TODO Does not support custom user profile fields (MDL-70456). - $userfields = \core_user\fields::for_identity($this->context, false)->with_name() + $userfieldsapi = \core_user\fields::for_identity($this->context)->with_name() ->excluding('id', 'idnumber', 'picture', 'imagealt', 'institution', 'department', 'email'); - $extrafields = $userfields->get_sql('u')->selects; + $userfields = $userfieldsapi->get_sql('u', true, '', '', false); + $fields .= ' quiza.uniqueid AS usageid, quiza.id AS attempt, @@ -436,7 +436,7 @@ abstract class quiz_attempts_report_table extends table_sql { u.imagealt, u.institution, u.department, - u.email' . $extrafields . ', + u.email,' . $userfields->selects . ', quiza.state, quiza.sumgrades, quiza.timefinish, @@ -450,9 +450,10 @@ abstract class quiz_attempts_report_table extends table_sql { // This part is the same for all cases. Join the users and quiz_attempts tables. $from = " {user} u"; + $from .= "\n{$userfields->joins}"; $from .= "\nLEFT JOIN {quiz_attempts} quiza ON quiza.userid = u.id AND quiza.quiz = :quizid"; - $params = array('quizid' => $this->quiz->id); + $params = array_merge($userfields->params, ['quizid' => $this->quiz->id]); if ($this->qmsubselect && $this->options->onlygraded) { $from .= " AND (quiza.state <> :finishedstate OR $this->qmsubselect)"; diff --git a/mod/quiz/report/overview/tests/behat/basic.feature b/mod/quiz/report/overview/tests/behat/basic.feature index 91c35bc7069..d0c665ed7b7 100644 --- a/mod/quiz/report/overview/tests/behat/basic.feature +++ b/mod/quiz/report/overview/tests/behat/basic.feature @@ -4,14 +4,16 @@ Feature: Basic use of the Grades report As a teacher I need to use the Grades report - @javascript - Scenario: Using the Grades report - Given the following "users" exist: - | username | firstname | lastname | email | idnumber | - | teacher1 | T1 | Teacher1 | teacher1@example.com | T1000 | - | student1 | S1 | Student1 | student1@example.com | S1000 | - | student2 | S2 | Student2 | student2@example.com | S2000 | - | student3 | S3 | Student3 | student3@example.com | S3000 | + Background: + Given the following "custom profile fields" exist: + | datatype | shortname | name | + | text | fruit | Fruit | + And the following "users" exist: + | username | firstname | lastname | email | idnumber | profile_field_fruit | + | teacher1 | T1 | Teacher1 | teacher1@example.com | T1000 | | + | student1 | S1 | Student1 | student1@example.com | S1000 | Apple | + | student2 | S2 | Student2 | student2@example.com | S2000 | Banana | + | student3 | S3 | Student3 | student3@example.com | S3000 | Pear | And the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | @@ -44,6 +46,8 @@ Feature: Basic use of the Grades report | 1 | True | | 2 | True | + @javascript + Scenario: Using the Grades report # Basic check of the Grades report When I log in as "teacher1" And I am on "Course 1" course homepage @@ -77,3 +81,14 @@ Feature: Basic use of the Grades report And I should see "25.00" in the "S1 Student1" "table_row" # Check student2's grade And I should see "100.00" in the "S2 Student2" "table_row" + + @javascript + Scenario: View custom user profile fields in the grades report + Given the following config values are set as admin: + | showuseridentity | email,profile_field_fruit | + When I log in as "teacher1" + And I am on "Course 1" course homepage + And I follow "Quiz 1" + And I navigate to "Results > Grades" in current page administration + Then I should see "Apple" in the "S1 Student1" "table_row" + And I should see "Banana" in the "S2 Student2" "table_row"