Merge branch 'MDL-71595-master' of https://github.com/sammarshallou/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2021-05-31 22:34:39 +02:00
commit 1a8f79a177
3 changed files with 25 additions and 7 deletions

View File

@ -1313,7 +1313,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) {
@ -1324,11 +1324,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";

View File

@ -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) {

View File

@ -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"