Browse Source

Add (inaccessible) report on all sessions.

nwp90-nwp90-allsessionsreport
Nick Phillips 6 years ago
committed by Dan Marsden
parent
commit
1d754e3736
  1. 3
      classes/view_page_params.php
  2. 56
      locallib.php
  3. 36
      renderables.php
  4. 163
      renderer.php

3
classes/view_page_params.php

@ -37,6 +37,9 @@ class mod_attendance_view_page_params extends mod_attendance_page_with_filter_co
/** All courses */ /** All courses */
const MODE_ALL_COURSES = 1; const MODE_ALL_COURSES = 1;
/** All sessions */
const MODE_ALL_SESSIONS = 2;
/** @var int */ /** @var int */
public $studentid; public $studentid;

56
locallib.php

@ -109,6 +109,62 @@ function attendance_get_setname($attid, $statusset, $includevalues = true) {
return $statusname; return $statusname;
} }
/**
* Get full filtered log.
* @param int $userid
* @return array
*/
function get_user_sessions_log_full($userid) {
global $DB;
// All taken sessions (including previous groups).
$usercourses = enrol_get_users_courses($userid);
list($usql, $uparams) = $DB->get_in_or_equal(array_keys($usercourses), SQL_PARAMS_NAMED, 'cid0');
// WHERE clause is important:
// gm.userid not null => get unmarked attendances for user's current groups
// ats.groupid 0 => get all sessions that are for all students enrolled in course
// al.id not null => get all marked sessions whether or not user currently still in group
//
$sql = "SELECT ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, ats.statusset,
al.statusid, al.remarks, ats.studentscanmark, ats.autoassignstatus,
ats.preventsharedip, ats.preventsharediptime,
ats.attendanceid, att.name AS attname, att.course AS courseid, c.fullname AS cname
FROM {attendance_sessions} ats
JOIN {attendance} att
ON att.id = ats.attendanceid
JOIN {course} c
ON att.course = c.id
LEFT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid
LEFT JOIN {groups_members} gm
ON (ats.groupid = gm.groupid AND gm.userid = :uid1)
WHERE (gm.userid IS NOT NULL OR ats.groupid = 0 OR al.id IS NOT NULL)
AND att.course $usql
ORDER BY c.fullname ASC, att.name ASC, att.id ASC, ats.sessdate ASC";
$params = array(
'uid' => $userid,
'uid1' => $userid,
);
$params = array_merge($params, $uparams);
$sessions = $DB->get_records_sql($sql, $params);
foreach ($sessions as $sess) {
if (empty($sess->description)) {
$sess->description = get_string('nodescription', 'attendance');
} else {
$modinfo = get_fast_modinfo($sess->courseid);
$cmid = $modinfo->instances['attendance'][$sess->attendanceid]->get_course_module_record()->id;
$ctx = context_module::instance($cmid);
$sess->description = file_rewrite_pluginfile_urls($sess->description,
'pluginfile.php', $ctx->id, 'mod_attendance', 'session', $sess->id);
}
}
return $sessions;
}
/** /**
* Get users courses and the relevant attendances. * Get users courses and the relevant attendances.
* *

36
renderables.php

@ -486,6 +486,42 @@ class attendance_user_data implements renderable {
$this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid); $this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid);
$this->groups = groups_get_all_groups($att->course->id); $this->groups = groups_get_all_groups($att->course->id);
} else if ($this->pageparams->mode == mod_attendance_view_page_params::MODE_ALL_SESSIONS) {
$this->coursesatts = attendance_get_user_courses_attendances($userid);
$this->statuses = array();
$this->summaries = array();
$this->groups = array();
foreach ($this->coursesatts as $atid => $ca) {
// Check to make sure the user can view this cm.
$modinfo = get_fast_modinfo($ca->courseid);
if (!$modinfo->instances['attendance'][$ca->attid]->uservisible) {
unset($this->coursesatts[$atid]);
continue;
} else {
$this->coursesatts[$atid]->cmid = $modinfo->instances['attendance'][$ca->attid]->get_course_module_record()->id;
}
$this->statuses[$ca->attid] = attendance_get_statuses($ca->attid);
$this->summaries[$ca->attid] = new mod_attendance_summary($ca->attid, array($userid));
if (!array_key_exists($ca->courseid, $this->groups)) {
$this->groups[$ca->courseid] = groups_get_all_groups($ca->courseid);
}
}
if (!$mobile) {
$this->summary = new mod_attendance_summary($att->id, array($userid), $att->pageparams->startdate,
$att->pageparams->enddate);
$this->filtercontrols = new attendance_filter_controls($att);
}
$this->sessionslog = get_user_sessions_log_full($userid);
foreach ($this->sessionslog as $sessid => $sess) {
$this->sessionslog[$sessid]->cmid = $this->coursesatts[$sess->attendanceid]->cmid;
}
} else { } else {
$this->coursesatts = attendance_get_user_courses_attendances($userid); $this->coursesatts = attendance_get_user_courses_attendances($userid);
$this->statuses = array(); $this->statuses = array();

163
renderer.php

@ -1022,6 +1022,9 @@ class mod_attendance_renderer extends plugin_renderer_base {
$o .= html_writer::empty_tag('hr'); $o .= html_writer::empty_tag('hr');
$o .= construct_user_data_stat($userdata->summary->get_all_sessions_summary_for($userdata->user->id), $o .= construct_user_data_stat($userdata->summary->get_all_sessions_summary_for($userdata->user->id),
$userdata->pageparams->view); $userdata->pageparams->view);
} else if ($userdata->pageparams->mode == mod_attendance_view_page_params::MODE_ALL_SESSIONS) {
$o .= $this->render_attendance_filter_controls($userdata->filtercontrols);
$o .= $this->construct_user_allsessions_log($userdata);
} else { } else {
$table = new html_table(); $table = new html_table();
$table->head = array(get_string('course'), $table->head = array(get_string('course'),
@ -1226,6 +1229,166 @@ class mod_attendance_renderer extends plugin_renderer_base {
return html_writer::table($table); return html_writer::table($table);
} }
/**
* Construct table showing all sessions, not limited to current course.
*
* @param attendance_user_data $userdata
* @return string
*/
private function construct_user_allsessions_log(attendance_user_data $userdata) {
global $OUTPUT, $USER;
$shortform = false;
if ($USER->id == $userdata->user->id) {
// This is a user viewing their own stuff - hide non-relevant columns.
$shortform = true;
}
$context = context_module::instance($userdata->filtercontrols->cm->id);
$table = new html_table();
$table->attributes['class'] = 'generaltable attwidth boxaligncenter';
$table->head = array();
$table->align = array();
$table->size = array();
$table->colclasses = array();
$table->head[] = get_string('course');
$table->align[] = 'left';
$table->colclasses[] = 'colcourse';
$table->head[] = get_string('pluginname', 'mod_attendance');
$table->align[] = 'left';
$table->colclasses[] = 'colcourse';
$table->size[] = '*';
// use "session" instead
//$table->head[] = get_string('description', 'attendance');
$table->head[] = get_string('session', 'attendance');
$table->align[] = 'left';
$table->colclasses[] = 'desccol';
$table->size[] = '*';
if (!$shortform) {
$table->head[] = get_string('sessiontypeshort', 'attendance');
$table->align[] = '';
$table->size[] = '1px';
$table->colclasses[] = '';
}
$table->head[] = get_string('date');
$table->align[] = 'left';
$table->colclasses[] = 'datecol';
$table->size[] = '1px';
$table->head[] = get_string('status', 'attendance');
$table->align[] = 'center';
$table->colclasses[] = 'statuscol';
$table->size[] = '*';
$table->head[] = get_string('points', 'attendance');
$table->align[] = 'center';
$table->colclasses[] = 'pointscol';
$table->size[] = '1px';
$table->head[] = get_string('remarks', 'attendance');
$table->align[] = 'center';
$table->colclasses[] = 'remarkscol';
$table->size[] = '*';
if (has_capability('mod/attendance:takeattendances', $context)) {
$table->head[] = get_string('action');
$table->align[] = '';
$table->colclasses[] = 'actioncol';
$table->size[] = '';
}
$statusmaxpoints = array();
foreach ($userdata->statuses as $attid => $attstatuses) {
$statusmaxpoints[$attid] = attendance_get_statusset_maxpoints($attstatuses);
}
$i = 0;
foreach ($userdata->sessionslog as $sess) {
$i++;
$statussetmaxpoints = $statusmaxpoints[$sess->attendanceid];
$row = new html_table_row();
// course / activity / session / type / date / status / points / remarks / action
//
$courseurl = new moodle_url('/course/view.php', array('id' => $sess->courseid));
$row->cells[] = html_writer::link($courseurl, $sess->cname);
$attendanceurl = new moodle_url('/mod/attendance/view.php', array('id' => $sess->cmid,
'studentid' => $userdata->user->id,
'view' => ATT_VIEW_ALL));
$row->cells[] = html_writer::link($attendanceurl, $sess->attname);
$row->cells[] = $sess->description;
if (!$shortform) {
if ($sess->groupid) {
$sessiontypeshort = get_string('group') . ': ' . $userdata->groups[$sess->courseid][$sess->groupid]->name;
} else {
$sessiontypeshort = get_string('commonsession', 'attendance');
}
$row->cells[] = html_writer::tag('nobr', $sessiontypeshort);
}
$row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance')) .
" ". $this->construct_time($sess->sessdate, $sess->duration);
if (!empty($sess->statusid)) {
$status = $userdata->statuses[$sess->attendanceid][$sess->statusid];
$row->cells[] = $status->description;
$row->cells[] = format_float($status->grade, 1, true, true) . ' / ' .
format_float($statussetmaxpoints[$status->setnumber], 1, true, true);
$row->cells[] = $sess->remarks;
} else if (($sess->sessdate + $sess->duration) < $userdata->user->enrolmentstart) {
$cell = new html_table_cell(get_string('enrolmentstart', 'attendance',
userdate($userdata->user->enrolmentstart, '%d.%m.%Y')));
$cell->colspan = 3;
$row->cells[] = $cell;
} else if ($userdata->user->enrolmentend and $sess->sessdate > $userdata->user->enrolmentend) {
$cell = new html_table_cell(get_string('enrolmentend', 'attendance',
userdate($userdata->user->enrolmentend, '%d.%m.%Y')));
$cell->colspan = 3;
$row->cells[] = $cell;
} else {
list($canmark, $reason) = attendance_can_student_mark($sess, false);
if ($canmark) {
// Student can mark their own attendance.
// URL to the page that lets the student modify their attendance.
$url = new moodle_url('/mod/attendance/attendance.php',
array('sessid' => $sess->id, 'sesskey' => sesskey()));
$cell = new html_table_cell(html_writer::link($url, get_string('submitattendance', 'attendance')));
$cell->colspan = 3;
$row->cells[] = $cell;
} else { // Student cannot mark their own attendace.
$row->cells[] = '?';
$row->cells[] = '? / ' . format_float($statussetmaxpoints[$sess->statusset], 1, true, true);
$row->cells[] = '';
}
}
if (has_capability('mod/attendance:takeattendances', $context)) {
$params = array('id' => $userdata->filtercontrols->cm->id,
'sessionid' => $sess->id,
'grouptype' => $sess->groupid);
$url = new moodle_url('/mod/attendance/take.php', $params);
$icon = $OUTPUT->pix_icon('redo', get_string('changeattendance', 'attendance'), 'attendance');
$row->cells[] = html_writer::link($url, $icon);
}
$table->data[] = $row;
}
return html_writer::table($table);
}
/** /**
* Construct time for display. * Construct time for display.
* *

Loading…
Cancel
Save