Skip to content

Commit 506d100

Browse files
authored
Merge pull request #274 from catalyst/add-username-column
Add username column
2 parents 361a5cf + 1a7640b commit 506d100

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

attendees.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,18 @@
5555

5656
// Load attendees.
5757
$attendees = facetoface_get_attendees($session->id);
58-
58+
// Preload user records for attendees (single query to avoid N+1).
59+
$users = [];
60+
if (!empty($attendees)) {
61+
$userids = array_map(function ($a) {
62+
return $a->id;
63+
}, $attendees);
64+
$userids = array_unique($userids);
65+
if (!empty($userids)) {
66+
// Fetch only the fields we need (id and username).
67+
$users = $DB->get_records_list('user', 'id', $userids, '', 'id, username');
68+
}
69+
}
5970
// Load cancellations.
6071
$cancellations = facetoface_get_cancellations($session->id);
6172

@@ -246,7 +257,14 @@
246257
$table = new html_table();
247258
$table->head = [get_string('name')];
248259
$table->align = ['left'];
249-
$table->size = ['100%'];
260+
$table->size = ['70%'];
261+
262+
$showusername = facetoface_should_attendees_show_usernames();
263+
if ($showusername) {
264+
$table->head[] = get_string('username');
265+
$table->align[] = 'left';
266+
$table->size[] = '30%';
267+
}
250268

251269
if ($takeattendance) {
252270
$table->head[] = get_string('currentstatus', 'facetoface');
@@ -270,8 +288,16 @@
270288
foreach ($attendees as $attendee) {
271289
$data = [];
272290
$attendeeurl = new moodle_url('/user/view.php', ['id' => $attendee->id, 'course' => $course->id]);
291+
// Show name.
273292
$data[] = html_writer::link($attendeeurl, format_string(fullname($attendee)));
274293

294+
// Show username.
295+
if ($showusername) {
296+
$user = $users[$attendee->id] ?? null;
297+
$username = $user ? $user->username : '';
298+
$data[] = format_string($username);
299+
}
300+
275301
if ($takeattendance) {
276302
// Show current status.
277303
$data[] = get_string('status_' . facetoface_get_status($attendee->statuscode), 'facetoface');

lang/en/facetoface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@
420420
$string['setting:addchangemanageremaildefault'] = 'Ask users for their manager\'s email address.';
421421
$string['setting:attendeesexportfields'] = 'Select the fields to be included in a session\'s exported list of attendees. This will be in addition to the attendee\'s first and last name.';
422422
$string['setting:attendeesexportfields_caption'] = 'Attendees export fields';
423+
$string['setting:attendeesshowusernames'] = 'If enabled, attendee usernames will appear alongside full names in the table, provided the necessary identity settings are properly configured.';
424+
$string['setting:attendeesshowusernames_caption'] = 'Show usernames in attendees table.';
423425
$string['setting:cancelrestriction'] = 'Minimum time before a session that students can cancel their booking. Within this period, cancellations are not allowed.';
424426
$string['setting:cancelrestriction_caption'] = 'Cancellation restriction';
425427
$string['setting:defaultcancellationinstrmngr'] = 'Default cancellation message sent to managers.';

lib.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,7 @@ function facetoface_download_attendees($facetofacename, $session, $attendees, $f
14301430
$timenow = time();
14311431
$timeformat = str_replace(' ', '_', get_string('strftimedate', 'langconfig'));
14321432
$downloadfilename = clean_filename($facetofacename . '_' . userdate($timenow, $timeformat));
1433+
$showusername = facetoface_should_attendees_show_usernames();
14331434

14341435
$dateformat = 0;
14351436
if ('ods' === $format) {
@@ -1486,6 +1487,10 @@ function facetoface_download_attendees($facetofacename, $session, $attendees, $f
14861487
}
14871488
$worksheet->write_string($row, $column++, $fieldname, ['bold' => 1, 'border' => 1]);
14881489
}
1490+
// Username.
1491+
if ($showusername) {
1492+
$worksheet->write_string($row, $column++, get_string('username'), ['bold' => 1, 'border' => 1]);
1493+
}
14891494
// Current status.
14901495
$worksheet->write_string($row, $column++, get_string('currentstatus', 'facetoface'), ['bold' => 1, 'border' => 1]);
14911496

@@ -1565,6 +1570,9 @@ function facetoface_download_attendees($facetofacename, $session, $attendees, $f
15651570
$worksheet->write_string($row, $column++, $data, $format);
15661571
}
15671572
}
1573+
if ($showusername) {
1574+
$worksheet->write_string($row, $column++, $user->username, ['border' => 1, 'v_align' => 'top']);
1575+
}
15681576
$worksheet->write_string(
15691577
$row,
15701578
$column++,
@@ -4757,6 +4765,21 @@ function facetoface_enrol_user($context, $courseid, $userid): bool {
47574765
return true;
47584766
}
47594767

4768+
/**
4769+
* Check if usernames should be shown in the attendees table.
4770+
*
4771+
* @return bool true if usernames can be displayed, false otherwise
4772+
*/
4773+
function facetoface_should_attendees_show_usernames(): bool {
4774+
global $CFG;
4775+
4776+
$protectusernames = $CFG->protectusernames;
4777+
$attendeesshowusernames = get_config('facetoface', 'attendeesshowusernames');
4778+
$showidentity = !empty($CFG->showuseridentity) && in_array('username', explode(',', $CFG->showuseridentity));
4779+
4780+
return $attendeesshowusernames && $showidentity && !$protectusernames;
4781+
}
4782+
47604783
/**
47614784
* Facetoface assignment candidates
47624785
*

settings.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@
101101
0
102102
));
103103

104+
$settings->add(new admin_setting_configcheckbox(
105+
'facetoface/attendeesshowusernames',
106+
get_string('setting:attendeesshowusernames_caption', 'mod_facetoface'),
107+
get_string('setting:attendeesshowusernames', 'mod_facetoface'),
108+
0
109+
));
110+
104111
$settings->add(new admin_setting_heading(
105112
'facetoface/manageremail_header',
106113
get_string('manageremailheading', 'facetoface'),

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232
defined('MOODLE_INTERNAL') || die();
3333

34-
$plugin->version = 2025112400;
35-
$plugin->release = 2025112400;
34+
$plugin->version = 2025112600;
35+
$plugin->release = 2025112600;
3636
$plugin->requires = 2023100900; // Requires 4.3.
3737
$plugin->component = 'mod_facetoface';
3838
$plugin->maturity = MATURITY_STABLE;

0 commit comments

Comments
 (0)