diff --git a/lib/completionlib.php b/lib/completionlib.php index 9154d28ad61..934de90a00e 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -1316,7 +1316,7 @@ class completion_info { * @param int $limitnum Result max size (optional) * @param context $extracontext If set, includes extra user information fields * as appropriate to display for current user in this context - * @return array Array of user objects with standard user fields + * @return array Array of user objects with user fields (including all identity fields) */ public function get_tracked_users($where = '', $whereparams = array(), $groupid = 0, $sort = '', $limitfrom = '', $limitnum = '', context $extracontext = null) { @@ -1327,11 +1327,12 @@ class completion_info { context_course::instance($this->course->id), 'moodle/course:isincompletionreports', $groupid, true); - // TODO Does not support custom user profile fields (MDL-70456). - $userfieldsapi = \core_user\fields::for_identity($extracontext, false)->with_name(); - $allusernames = $userfieldsapi->get_sql('u')->selects; - $sql = 'SELECT u.id, u.idnumber ' . $allusernames; + $userfieldsapi = \core_user\fields::for_identity($extracontext)->with_name()->excluding('id', 'idnumber'); + $fieldssql = $userfieldsapi->get_sql('u', true); + $sql = 'SELECT u.id, u.idnumber ' . $fieldssql->selects; $sql .= ' FROM (' . $enrolledsql . ') eu JOIN {user} u ON u.id = eu.id'; + $sql .= $fieldssql->joins; + $params = array_merge($params, $fieldssql->params); if ($where) { $sql .= " AND $where"; diff --git a/report/progress/index.php b/report/progress/index.php index 85755bf4cc7..d2a0756dd46 100644 --- a/report/progress/index.php +++ b/report/progress/index.php @@ -55,8 +55,8 @@ $activityinclude = optional_param('activityinclude', 'all', PARAM_TEXT); $activityorder = optional_param('activityorder', 'orderincourse', PARAM_TEXT); // Whether to show extra user identity information -// TODO Does not support custom user profile fields (MDL-70456). -$extrafields = \core_user\fields::get_identity_fields($context, false); +$userfields = \core_user\fields::for_identity($context); +$extrafields = $userfields->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]); $leftcols = 1 + count($extrafields); function csv_quote($value) { diff --git a/report/progress/tests/behat/course_report_progress.feature b/report/progress/tests/behat/course_report_progress.feature index 1cd5091905e..0bd6fc33c29 100644 --- a/report/progress/tests/behat/course_report_progress.feature +++ b/report/progress/tests/behat/course_report_progress.feature @@ -30,3 +30,20 @@ Feature: In a course administration page, navigate through report page, test for Then "Report" "field" should exist And the "Report" select box should contain "Activity completion" And the field "Report" matches value "Activity completion" + + Scenario: Custom profile fields selected for identity should display on the activity completion report + Given the following "custom profile fields" exist: + | datatype | shortname | name | + | text | frog | Favourite frog | + And the following "users" exist: + | username | firstname | lastname | profile_field_frog | + | student2 | Student | Two | Kermit | + And the following "course enrolments" exist: + | user | course | role | + | student2 | C1 | student | + And the following config values are set as admin: + | showuseridentity | email,profile_field_frog | + When I am on the "C1" "Course" page logged in as "admin" + And I navigate to "Reports > Activity completion" in current page administration + Then I should see "Favourite frog" + Then I should see "Kermit" in the "Student Two" "table_row"