- if ($matchcount > 0) {
- $usersprinted = array();
- foreach ($userlist as $user) {
- if (in_array($user->id, $usersprinted)) { // Prevent duplicates by r.hidden - MDL-13935.
- continue;
- }
- $usersprinted[] = $user->id; // Add new user to the array of users printed.
-
- context_helper::preload_from_record($user);
-
- $context = context_course::instance($course->id);
- $usercontext = context_user::instance($user->id);
-
- $countries = get_string_manager()->get_list_of_countries();
-
- // Get the hidden field list.
- if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
- $hiddenfields = array();
- } else {
- $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
- }
- $table = new html_table();
- $table->attributes['class'] = 'userinfobox';
-
- $row = new html_table_row();
- $row->cells[0] = new html_table_cell();
- $row->cells[0]->attributes['class'] = 'left side';
-
- $row->cells[0]->text = $OUTPUT->user_picture($user, array('size' => 100, 'courseid' => $course->id));
- $row->cells[1] = new html_table_cell();
- $row->cells[1]->attributes['class'] = 'content';
-
- $row->cells[1]->text = $OUTPUT->container(fullname($user, has_capability('moodle/site:viewfullnames', $context)), 'username');
- $row->cells[1]->text .= $OUTPUT->container_start('info');
-
- if (!empty($user->role)) {
- $row->cells[1]->text .= get_string('role').get_string('labelsep', 'langconfig').$user->role.'<br />';
- }
- if ($user->maildisplay == 1 or ($user->maildisplay == 2 and ($course->id != SITEID) and !isguestuser()) or
- in_array('email', $extrafields) or ($user->id == $USER->id)) {
- $row->cells[1]->text .= get_string('email').get_string('labelsep', 'langconfig').html_writer::link("mailto:$user->email", $user->email) . '<br />';
- }
- foreach ($extrafields as $field) {
- if ($field === 'email') {
- // Skip email because it was displayed with different logic above
- // because this page is intended for students too.
- continue;
- }
- $row->cells[1]->text .= get_user_field_name($field) .
- get_string('labelsep', 'langconfig') . s($user->{$field}) . '<br />';
- }
- if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
- $row->cells[1]->text .= get_string('city').get_string('labelsep', 'langconfig');
- if ($user->city && !isset($hiddenfields['city'])) {
- $row->cells[1]->text .= $user->city;
- }
- if (!empty($countries[$user->country]) && !isset($hiddenfields['country'])) {
- if ($user->city && !isset($hiddenfields['city'])) {
- $row->cells[1]->text .= ', ';
- }
- $row->cells[1]->text .= $countries[$user->country];
- }
- $row->cells[1]->text .= '<br />';
- }
-
- if (!isset($hiddenfields['lastaccess'])) {
- if ($user->lastaccess) {
- $row->cells[1]->text .= get_string('lastaccess').get_string('labelsep', 'langconfig').userdate($user->lastaccess);
- $row->cells[1]->text .= ' ('. format_time(time() - $user->lastaccess, $datestring) .')';
- } else {
- $row->cells[1]->text .= get_string('lastaccess').get_string('labelsep', 'langconfig').get_string('never');
- }
- }
-
- $row->cells[1]->text .= $OUTPUT->container_end();
-
- $row->cells[2] = new html_table_cell();
- $row->cells[2]->attributes['class'] = 'links';
- $row->cells[2]->text = '';
-
- $links = array();
-
- if ($CFG->enableblogs && ($CFG->bloglevel != BLOG_USER_LEVEL || $USER->id == $user->id)) {
- $links[] = html_writer::link(new moodle_url('/blog/index.php?userid='.$user->id), get_string('blogs', 'blog'));
- }
-
- if (!empty($CFG->enablenotes) and (has_capability('moodle/notes:manage', $context) || has_capability('moodle/notes:view', $context))) {
- $links[] = html_writer::link(new moodle_url('/notes/index.php?course=' . $course->id. '&user='.$user->id), get_string('notes', 'notes'));
- }
-
- if (has_capability('moodle/site:viewreports', $context) or has_capability('moodle/user:viewuseractivitiesreport', $usercontext)) {
- $links[] = html_writer::link(new moodle_url('/course/user.php?id='. $course->id .'&user='. $user->id), get_string('activity'));
- }
-
- if ($USER->id != $user->id && !\core\session\manager::is_loggedinas() && has_capability('moodle/user:loginas', $context) && !is_siteadmin($user->id)) {
- $links[] = html_writer::link(new moodle_url('/course/loginas.php?id='. $course->id .'&user='. $user->id .'&sesskey='. sesskey()), get_string('loginas'));
- }
-
- $links[] = html_writer::link(new moodle_url('/user/view.php?id='. $user->id .'&course='. $course->id), get_string('fullprofile') . '...');
-
- $row->cells[2]->text .= implode('', $links);
-
- if ($bulkoperations) {
- if ($selectall) {
- $checked = 'checked="true"';
- } else {
- $checked = '';
- }
- $row->cells[2]->text .= '<br /><input type="checkbox" class="usercheckbox" name="user'.$user->id.'" ' .$checked .'/> ';
- }
- $table->data = array($row);
- echo html_writer::table($table);
- }