Browse Source

Respect showuseridentity setting in absentee report.

MOODLE_38_STABLE
Dan Marsden 4 years ago
parent
commit
b827daaa36
  1. 49
      absentee.php
  2. 22
      locallib.php

49
absentee.php

@ -83,14 +83,28 @@ if (!$table->is_downloading($download, $exportfilename)) {
} }
} }
$columns = array('coursename', 'aname', 'userid');
$table->define_columns(array('coursename', 'aname', 'userid', 'numtakensessions', 'percent', 'timesent')); $headers = array(get_string('course'),
$table->define_headers(array(get_string('course'),
get_string('pluginname', 'attendance'), get_string('pluginname', 'attendance'),
get_string('user'), get_string('user'));
$extrafields = array();
if (!empty($CFG->showuseridentity) && has_capability('moodle/site:viewuseridentity', $context)) {
$extrafields = explode(',', $CFG->showuseridentity);
foreach ($extrafields as $field) {
$columns[] = $field;
$headers[] = get_string($field);
}
}
$columns = array_merge($columns, array('numtakensessions', 'percent', 'timesent'));
$headers = array_merge($headers, array(
get_string('takensessions', 'attendance'), get_string('takensessions', 'attendance'),
get_string('averageattendance', 'attendance'), get_string('averageattendance', 'attendance'),
get_string('triggered', 'attendance'))); get_string('triggered', 'attendance')));
$table->define_columns($columns);
$table->define_headers($headers);
$table->sortable(true); $table->sortable(true);
$table->set_attribute('cellspacing', '0'); $table->set_attribute('cellspacing', '0');
$table->set_attribute('class', 'generaltable generalbox'); $table->set_attribute('class', 'generaltable generalbox');
@ -119,28 +133,37 @@ if (!empty($sort)) {
$records = attendance_get_users_to_notify($courses, $orderby); $records = attendance_get_users_to_notify($courses, $orderby);
foreach ($records as $record) { foreach ($records as $record) {
$row = array();
if (!$table->is_downloading($download, $exportfilename)) { if (!$table->is_downloading($download, $exportfilename)) {
$url = new moodle_url('/mod/attendance/index.php', array('id' => $record->courseid)); $url = new moodle_url('/mod/attendance/index.php', array('id' => $record->courseid));
$name = html_writer::link($url, $record->coursename); $row[] = html_writer::link($url, $record->coursename);
$url = new moodle_url('/mod/attendance/view.php', array('studentid' => $record->userid, $url = new moodle_url('/mod/attendance/view.php', array('studentid' => $record->userid,
'id' => $record->cmid, 'view' => ATT_VIEW_ALL)); 'id' => $record->cmid, 'view' => ATT_VIEW_ALL));
$attendancename = html_writer::link($url, $record->aname); $row[] = html_writer::link($url, $record->aname);
$username = html_writer::link($url, fullname($record)); $row[] = html_writer::link($url, fullname($record));
} else { } else {
$name = $record->coursename; $row[] = $record->coursename;
$attendancename = $record->aname; $row[] = $record->aname;
$username = fullname($record); $row[] = fullname($record);
} }
foreach ($extrafields as $field) {
$percent = round($record->percent * 100)."%"; if (isset($record->$field)) {
$row[] = $record->$field;
} else {
$row[] = '';
}
}
$row[] = $record->numtakensessions;
$row[] = round($record->percent * 100)."%";
$timesent = "-"; $timesent = "-";
if (!empty($record->timesent)) { if (!empty($record->timesent)) {
$timesent = userdate($record->timesent); $timesent = userdate($record->timesent);
} }
$row[] = $timesent;
$table->add_data(array($name, $attendancename, $username, $record->numtakensessions, $percent, $timesent)); $table->add_data($row);
} }
$table->finish_output(); $table->finish_output();

22
locallib.php

@ -994,7 +994,7 @@ SELECT a.id, a.course as courseid, c.fullname as coursename, atl.studentid AS us
* @return stdClass * @return stdClass
*/ */
function attendance_get_users_to_notify($courseids = array(), $orderby = '', $allfornotify = false) { function attendance_get_users_to_notify($courseids = array(), $orderby = '', $allfornotify = false) {
global $DB; global $DB, $CFG;
$joingroup = 'LEFT JOIN {groups_members} gm ON (gm.userid = atl.studentid AND gm.groupid = ats.groupid)'; $joingroup = 'LEFT JOIN {groups_members} gm ON (gm.userid = atl.studentid AND gm.groupid = ats.groupid)';
$where = ' AND (ats.groupid = 0 or gm.id is NOT NULL)'; $where = ' AND (ats.groupid = 0 or gm.id is NOT NULL)';
@ -1011,11 +1011,19 @@ function attendance_get_users_to_notify($courseids = array(), $orderby = '', $al
$having .= ' AND n.maxwarn > COUNT(DISTINCT ns.id) '; $having .= ' AND n.maxwarn > COUNT(DISTINCT ns.id) ';
} }
$unames = get_all_user_name_fields(true); $unames = get_all_user_name_fields(true).',';
$unames2 = get_all_user_name_fields(true, 'u'); $unames2 = get_all_user_name_fields(true, 'u').',';
if (!empty($CFG->showuseridentity)) {
$extrafields = explode(',', $CFG->showuseridentity);
foreach ($extrafields as $field) {
$unames .= $field . ', ';
$unames2 .= 'u.' . $field . ', ';
}
}
$idfield = $DB->sql_concat('cm.id', 'atl.studentid', 'n.id'); $idfield = $DB->sql_concat('cm.id', 'atl.studentid', 'n.id');
$sql = "SELECT {$idfield} as uniqueid, a.id as aid, {$unames2}, a.name as aname, cm.id as cmid, c.id as courseid, $sql = "SELECT {$idfield} as uniqueid, a.id as aid, {$unames2} a.name as aname, cm.id as cmid, c.id as courseid,
c.fullname as coursename, atl.studentid AS userid, n.id as notifyid, n.warningpercent, n.emailsubject, c.fullname as coursename, atl.studentid AS userid, n.id as notifyid, n.warningpercent, n.emailsubject,
n.emailcontent, n.emailcontentformat, n.emailuser, n.thirdpartyemails, n.warnafter, n.maxwarn, n.emailcontent, n.emailcontentformat, n.emailuser, n.thirdpartyemails, n.warnafter, n.maxwarn,
COUNT(DISTINCT ats.id) AS numtakensessions, SUM(stg.grade) AS points, SUM(stm.maxgrade) AS maxpoints, COUNT(DISTINCT ats.id) AS numtakensessions, SUM(stg.grade) AS points, SUM(stm.maxgrade) AS maxpoints,
@ -1041,7 +1049,7 @@ function attendance_get_users_to_notify($courseids = array(), $orderby = '', $al
WHERE ats.absenteereport = 1 {$where} WHERE ats.absenteereport = 1 {$where}
GROUP BY uniqueid, a.id, a.name, a.course, c.fullname, atl.studentid, n.id, n.warningpercent, GROUP BY uniqueid, a.id, a.name, a.course, c.fullname, atl.studentid, n.id, n.warningpercent,
n.emailsubject, n.emailcontent, n.emailcontentformat, n.warnafter, n.maxwarn, n.emailsubject, n.emailcontent, n.emailcontentformat, n.warnafter, n.maxwarn,
n.emailuser, n.thirdpartyemails, cm.id, c.id, {$unames2}, ns.userid n.emailuser, n.thirdpartyemails, cm.id, c.id, {$unames2} ns.userid
HAVING n.warnafter <= COUNT(DISTINCT ats.id) AND n.warningpercent > ((SUM(stg.grade) / SUM(stm.maxgrade)) * 100) HAVING n.warnafter <= COUNT(DISTINCT ats.id) AND n.warningpercent > ((SUM(stg.grade) / SUM(stm.maxgrade)) * 100)
{$having} {$having}
{$orderby}"; {$orderby}";
@ -1049,11 +1057,11 @@ function attendance_get_users_to_notify($courseids = array(), $orderby = '', $al
if (!$allfornotify) { if (!$allfornotify) {
$idfield = $DB->sql_concat('cmid', 'userid'); $idfield = $DB->sql_concat('cmid', 'userid');
// Only show one record per attendance for teacher reports. // Only show one record per attendance for teacher reports.
$sql = "SELECT DISTINCT {$idfield} as id, {$unames}, aid, cmid, courseid, aname, coursename, userid, $sql = "SELECT DISTINCT {$idfield} as id, {$unames} aid, cmid, courseid, aname, coursename, userid,
numtakensessions, percent, MAX(timesent) as timesent numtakensessions, percent, MAX(timesent) as timesent
FROM ({$sql}) as m FROM ({$sql}) as m
GROUP BY id, aid, cmid, courseid, aname, userid, numtakensessions, GROUP BY id, aid, cmid, courseid, aname, userid, numtakensessions,
percent, coursename, {$unames} {$orderby}"; percent, {$unames} coursename {$orderby}";
} }
return $DB->get_records_sql($sql, $params); return $DB->get_records_sql($sql, $params);

Loading…
Cancel
Save