MDL-71595 report_progress: Add custom user field support

This commit is contained in:
sam marshall
2021-05-11 16:57:02 +01:00
parent 3da88a7664
commit 588cb0fff6
3 changed files with 25 additions and 7 deletions
+6 -5
View File
@@ -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";