From 73011e5bdba17abc24d4e82ac76b510cdbbc389b Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Wed, 12 Apr 2017 13:15:55 +1200 Subject: [PATCH] Fixes #63 use core useridentity setting when showing list of users. update report and take attendance pages. --- classes/structure.php | 8 ++++++-- renderables.php | 2 +- renderer.php | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/classes/structure.php b/classes/structure.php index 4f671fc..1cc95cb 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -586,8 +586,12 @@ class mod_attendance_structure { public function get_users($groupid = 0, $page = 1) { global $DB, $CFG; - // Fields we need from the user table. - $userfields = user_picture::fields('u', array('username' , 'idnumber' , 'institution' , 'department')); + $fields = array('username' , 'idnumber' , 'institution' , 'department'); + // Get user identity fields if required - doesn't return original $fields array. + $extrafields = get_extra_user_fields($this->context, $fields); + $fields = array_merge($fields, $extrafields); + + $userfields = user_picture::fields('u',$fields); if (empty($this->pageparams->sort)) { $this->pageparams->sort = ATT_SORT_DEFAULT; diff --git a/renderables.php b/renderables.php index 14cc7b6..773ff8d 100644 --- a/renderables.php +++ b/renderables.php @@ -275,7 +275,7 @@ class attendance_take_data implements renderable { private $urlpath; private $urlparams; - private $att; + public $att; public function __construct(mod_attendance_structure $att) { if ($att->pageparams->grouptype) { diff --git a/renderer.php b/renderer.php index 3a6c891..7f00a67 100644 --- a/renderer.php +++ b/renderer.php @@ -498,6 +498,7 @@ class mod_attendance_renderer extends plugin_renderer_base { } protected function render_attendance_take_list(attendance_take_data $takedata) { + global $PAGE, $CFG; $table = new html_table(); $table->width = '0%'; $table->head = array( @@ -507,6 +508,15 @@ class mod_attendance_renderer extends plugin_renderer_base { $table->align = array('left', 'left'); $table->size = array('20px', ''); $table->wrap[1] = 'nowrap'; + // Check if extra useridentity fields need to be added. + $extrasearchfields = array(); + if (!empty($CFG->showuseridentity) && has_capability('moodle/site:viewuseridentity', $takedata->att->context)) { + $extrasearchfields = explode(',', $CFG->showuseridentity); + } + foreach ($extrasearchfields as $field) { + $table->head[] = get_string($field); + $table->align[] = 'left'; + } foreach ($takedata->statuses as $st) { $table->head[] = html_writer::link("javascript:select_all_in(null, 'st" . $st->id . "', null);", $st->acronym, array('title' => get_string('setallstatusesto', 'attendance', $st->description))); @@ -521,6 +531,9 @@ class mod_attendance_renderer extends plugin_renderer_base { // Show a 'select all' row of radio buttons. $row = new html_table_row(); $row->cells[] = ''; + foreach ($extrasearchfields as $field) { + $row->cells[] = ''; + } $row->cells[] = html_writer::div(get_string('setallstatuses', 'attendance'), 'setallstatuses'); foreach ($takedata->statuses as $st) { $attribs = array( @@ -549,6 +562,9 @@ class mod_attendance_renderer extends plugin_renderer_base { $fullname .= $ucdata['warning']; } $row->cells[] = $fullname; + foreach ($extrasearchfields as $field) { + $row->cells[] = $user->$field; + } if (array_key_exists('colspan', $ucdata)) { $cell = new html_table_cell($ucdata['text']); @@ -868,6 +884,7 @@ class mod_attendance_renderer extends plugin_renderer_base { $table->attributes['class'] = 'generaltable attwidth attreport'; $userrows = $this->get_user_rows($reportdata); + if ($reportdata->pageparams->view == ATT_VIEW_SUMMARY) { $sessionrows = array(); } else { @@ -943,13 +960,23 @@ class mod_attendance_renderer extends plugin_renderer_base { $row = new html_table_row(); $row->cells[] = $this->build_header_cell(''); $row->cells[] = $this->build_header_cell($this->construct_fullname_head($reportdata), false, false); + + $extrafields = get_extra_user_fields($reportdata->att->context); + foreach ($extrafields as $field) { + $row->cells[] = $this->build_header_cell(get_string($field), false, false); + } + $rows[] = $row; + foreach ($reportdata->users as $user) { $row = new html_table_row(); $row->cells[] = $this->build_data_cell($this->user_picture($user)); $text = html_writer::link($reportdata->url_view(array('studentid' => $user->id)), fullname($user)); $row->cells[] = $this->build_data_cell($text, false, false, null, null, false); + foreach ($extrafields as $field) { + $row->cells[] = $this->build_data_cell($user->$field, false, false); + } $rows[] = $row; }