Browse Source

Fixes #225 Add columns to show users taken sessions by acronym

MOODLE_32_STABLE
Antonio C. Mariani 8 years ago
committed by Dan Marsden
parent
commit
d5d7369af1
  1. 70
      classes/summary.php
  2. 46
      renderer.php
  3. 10
      styles.css

70
classes/summary.php

@ -41,6 +41,9 @@ class mod_attendance_summary {
/** @var array pointsbygroup (groupid, numsessions, maxpoints) */
private $maxpointsbygroupsessions;
/** @var array userstakensessionsbyacronym */
private $userstakensessionsbyacronym;
/**
* Initializes the class
*
@ -53,6 +56,7 @@ class mod_attendance_summary {
$this->attendanceid = $attendanceid;
$this->compute_users_points($userids, $startdate, $enddate);
$this->compute_users_taken_sessions_by_acronym($userids, $startdate, $enddate);
}
/**
@ -119,6 +123,11 @@ class mod_attendance_summary {
}
$usersummary->takensessionspercentage = attendance_calc_fraction($usersummary->takensessionspoints,
$usersummary->takensessionsmaxpoints);
if (isset($this->userstakensessionsbyacronym[$userid])) {
$usersummary->userstakensessionsbyacronym = $this->userstakensessionsbyacronym[$userid];
} else {
$usersummary->userstakensessionsbyacronym = array();
}
return $usersummary;
}
@ -224,6 +233,67 @@ class mod_attendance_summary {
$this->userspoints = $DB->get_records_sql($sql, $params);
}
/**
* Computes the summary of taken sessions by acronym
*
* @param array userids user instances identifier
* @param int $startdate Attendance sessions startdate
* @param int $enddate Attendance sessions enddate
* @return null
*/
private function compute_users_taken_sessions_by_acronym($userids=array(), $startdate = '', $enddate = '') {
global $DB;
list($this->course, $cm) = get_course_and_cm_from_instance($this->attendanceid, 'attendance');
$this->groupmode = $cm->effectivegroupmode;
$params = array(
'attid' => $this->attendanceid,
'cstartdate' => $this->course->startdate,
);
$where = '';
if (!empty($userids)) {
list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$where .= ' AND atl.studentid ' . $insql;
$params = array_merge($params, $inparams);
}
if (!empty($startdate)) {
$where .= ' AND ats.sessdate >= :startdate';
$params['startdate'] = $startdate;
}
if (!empty($enddate)) {
$where .= ' AND ats.sessdate < :enddate ';
$params['enddate'] = $enddate;
}
if ($this->with_groups()) {
$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)';
} else {
$joingroup = '';
$where .= ' AND ats.groupid = 0';
}
$sql = "SELECT atl.studentid AS userid, sts.setnumber, sts.acronym, COUNT(*) AS numtakensessions
FROM {attendance_sessions} ats
JOIN {attendance_log} atl ON (atl.sessionid = ats.id)
JOIN {attendance_statuses} sts
ON (sts.attendanceid = ats.attendanceid AND
sts.id = atl.statusid AND
sts.deleted = 0 AND sts.visible = 1)
{$joingroup}
WHERE ats.attendanceid = :attid
AND ats.sessdate >= :cstartdate
AND ats.lasttakenby != 0
{$where}
GROUP BY atl.studentid, sts.setnumber, sts.acronym";
$this->userstakensessionsbyacronym = array();
foreach ($DB->get_recordset_sql($sql, $params) AS $rec) {
$this->userstakensessionsbyacronym[$rec->userid][$rec->setnumber][$rec->acronym] = $rec->numtakensessions;
}
}
/**
* Computes and store the maximum points possible for each group session
*

46
renderer.php

@ -856,14 +856,18 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->attributes['class'] .= ' summaryreport';
}
$colclass = null;
// User picture.
$table->head[] = '';
$table->align[] = 'left';
$table->size[] = '1px';
$table->colclasses[] = $colclass;
$table->head[] = $this->construct_fullname_head($reportdata);
$table->align[] = 'left';
$table->size[] = '';
$table->colclasses[] = $colclass;
$sessionstats = array();
foreach ($reportdata->sessions as $sess) {
@ -892,40 +896,65 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->head[] = $sesstext;
$table->align[] = 'center';
$table->size[] = '1px';
$table->colclasses[] = $colclass;
}
$setnumber = -1;
foreach ($reportdata->statuses AS $sts) {
if ($sts->setnumber != $setnumber) {
$colclass = empty($colclass) ? 'columncontrast' : null;
$setnumber = $sts->setnumber;
}
$table->head[] = $sts->acronym;
$table->align[] = 'center';
$table->size[] = '1px';
$table->colclasses[] = $colclass;
}
$table->head[] = get_string('takensessions', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$colclass = empty($colclass) ? 'columncontrast' : null;
$table->colclasses[] = $colclass;
$table->head[] = get_string('points', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$table->colclasses[] = $colclass;
$table->head[] = get_string('percentage', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$table->colclasses[] = $colclass;
if ($reportdata->pageparams->view == ATT_VIEW_SUMMARY) {
$table->head[] = get_string('sessionstotal', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$colclass = empty($colclass) ? 'columncontrast' : null;
$table->colclasses[] = $colclass;
$table->head[] = get_string('pointsallsessions', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$table->colclasses[] = $colclass;
$table->head[] = get_string('percentageallsessions', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$table->colclasses[] = $colclass;
$table->head[] = get_string('maxpossiblepoints', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$colclass = empty($colclass) ? 'columncontrast' : null;
$table->colclasses[] = $colclass;
$table->head[] = get_string('maxpossiblepercentage', 'attendance');
$table->align[] = 'center';
$table->size[] = '1px';
$table->colclasses[] = $colclass;
}
if ($bulkmessagecapability) { // Display the table header for bulk messaging.
@ -948,6 +977,12 @@ class mod_attendance_renderer extends plugin_renderer_base {
} else {
$usersummary = $reportdata->summary->get_taken_sessions_summary_for($user->id);
}
foreach ($reportdata->statuses AS $sts) {
$row->cells[] = isset($usersummary->userstakensessionsbyacronym[$sts->setnumber][$sts->acronym]) ?
$usersummary->userstakensessionsbyacronym[$sts->setnumber][$sts->acronym] : 0;
}
$row->cells[] = $usersummary->numtakensessions;
$row->cells[] = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' .
format_float($usersummary->takensessionsmaxpoints, 1, true, true);
@ -972,6 +1007,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->data[] = $row;
}
if ($reportdata->pageparams->view != ATT_VIEW_SUMMARY) {
// Calculate the sum of statuses for each user.
$statrow = new html_table_row();
$statrow->cells[] = '';
@ -994,7 +1030,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
}
}
$statsoutput = '<br/>';
$statsoutput = '';
foreach ($sessionstats as $status) {
$statsoutput .= "$status->description: {$status->count}<br/>";
}
@ -1002,7 +1038,15 @@ class mod_attendance_renderer extends plugin_renderer_base {
$cell->style = 'white-space:nowrap;';
$statrow->cells[] = $cell;
}
foreach ($reportdata->statuses AS $sts) {
$statrow->cells[] = '';
}
$statrow->cells[] = '';
$statrow->cells[] = '';
$statrow->cells[] = '';
$statrow->cells[] = '';
$table->data[] = $statrow;
}
if ($bulkmessagecapability) { // Require that the user can bulk message users.
// Display check boxes that will allow the user to send a message to the students that have been checked.

10
styles.css

@ -163,14 +163,6 @@
color: red;
}
.path-mod-attendance .summaryreport .c5 {
background-color: #EAEAEA;
}
.path-mod-attendance .summaryreport .c6 {
background-color: #EAEAEA;
}
.path-mod-attendance .summaryreport .c7 {
.path-mod-attendance .columncontrast {
background-color: #EAEAEA;
}

Loading…
Cancel
Save