diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 8c1f312..0f1ba62 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -256,6 +256,7 @@ $string['strftimehm'] = '%H:%M'; // Line added to allow display of time. $string['strftimeshortdate'] = '%d.%m.%Y'; $string['studentid'] = 'Student ID'; $string['takeattendance'] = 'Take attendance'; +$string['takensessions'] = 'Taken sessions'; $string['tempaddform'] = 'Add temporary user'; $string['tempexists'] = 'There is already a temporary user with this email address'; $string['tempusers'] = 'Temporary users'; diff --git a/locallib.php b/locallib.php index 9082ec8..3f85862 100644 --- a/locallib.php +++ b/locallib.php @@ -256,6 +256,22 @@ function attendance_get_max_statusset($attendanceid) { return 0; } +/** + * Returns the maxpoints for each statusset + * + * @param array statuses + * @return array + */ +function attendance_get_statusset_maxpoints($statuses) { + $statussetmaxpoints = array(); + foreach ($statuses as $st) { + if (!isset($statussetmaxpoints[$st->setnumber])) { + $statussetmaxpoints[$st->setnumber] = $st->grade; + } + } + return $statussetmaxpoints; +} + /** * Update user grades * @@ -302,3 +318,14 @@ function attendance_update_users_grade($attendance, $userids=array()) { return grade_update('mod/attendance', $course->id, 'mod', 'attendance', $attendance->id, 0, $grades); } + +/** + * Given a float, prints it nicely. + * + * @param float $float The float to print + * @param bool $stripzeros If true, removes final zeros after decimal point + * @return string locale float + */ +function attendance_format_float($float, $stripzeros=true) { + return format_float($float, 1, true, $stripzeros); +} diff --git a/renderables.php b/renderables.php index 0c7f764..e4a9a82 100644 --- a/renderables.php +++ b/renderables.php @@ -449,25 +449,15 @@ class attendance_report_data implements renderable { // Includes disablrd/deleted statuses. public $allstatuses; - public $gradable; - - public $decimalpoints; - public $usersgroups = array(); public $sessionslog = array(); - public $usersstats = array(); - - public $grades = array(); - - public $maxgrades = array(); + public $summary = array(); public $att; public function __construct(mod_attendance_structure $att) { - global $CFG; - $currenttime = time(); if ($att->pageparams->view == ATT_VIEW_NOTPRESENT) { $att->pageparams->enddate = $currenttime; @@ -492,32 +482,16 @@ class attendance_report_data implements renderable { $this->statuses = $att->get_statuses(true, true); $this->allstatuses = $att->get_statuses(false, true); - $this->gradable = $att->grade > 0; - - if (!$this->decimalpoints = grade_get_setting($att->course->id, 'decimalpoints')) { - $this->decimalpoints = $CFG->grade_decimalpoints; - } - - $maxgrade = attendance_get_user_max_grade(count($this->sessions), $this->statuses); + $this->summary = new mod_attendance_summary($att->id, array_keys($this->users), $att->pageparams->startdate, $att->pageparams->enddate); foreach ($this->users as $key => $user) { - $grade = 0; - if ($this->gradable) { - $grade = $att->get_user_grade($user->id, array('enddate' => $currenttime)); - $totalgrade = $att->get_user_grade($user->id); - } - - if ($att->pageparams->view != ATT_VIEW_NOTPRESENT || $grade < $maxgrade) { + $usersummary = $this->summary->get_taken_sessions_summary_for($user->id); + if ($att->pageparams->view != ATT_VIEW_NOTPRESENT || + $usersummary->takensessionspoints < $usersummary->takensessionsmaxpoints || + $usersummary->takensessionsmaxpoints == 0) { $this->usersgroups[$user->id] = groups_get_all_groups($att->course->id, $user->id); $this->sessionslog[$user->id] = $att->get_user_filtered_sessions_log($user->id); - - $this->usersstats[$user->id] = $att->get_user_statuses_stat($user->id); - - if ($this->gradable) { - $this->grades[$user->id] = $totalgrade; - $this->maxgrades[$user->id] = $att->get_user_max_grade($user->id);; - } } else { unset($this->users[$key]); } diff --git a/renderer.php b/renderer.php index fe86450..01ca45f 100644 --- a/renderer.php +++ b/renderer.php @@ -882,18 +882,17 @@ class mod_attendance_renderer extends plugin_renderer_base { $table->size[] = '1px'; } - foreach ($reportdata->statuses as $status) { - $table->head[] = $status->acronym; - $table->align[] = 'center'; - $table->size[] = '1px'; - $sessionstats[$status->id] = 0; - } + $table->head[] = get_string('takensessions', 'attendance'); + $table->align[] = 'center'; + $table->size[] = '1px'; - if ($reportdata->gradable) { - $table->head[] = get_string('grade'); - $table->align[] = 'center'; - $table->size[] = '1px'; - } + $table->head[] = get_string('points', 'attendance'); + $table->align[] = 'center'; + $table->size[] = '1px'; + + $table->head[] = get_string('percentage', 'attendance'); + $table->align[] = 'center'; + $table->size[] = '1px'; if ($bulkmessagecapability) { // Display the table header for bulk messaging. // The checkbox must have an id of cb_selector so that the JavaScript will pick it up. @@ -910,18 +909,11 @@ class mod_attendance_renderer extends plugin_renderer_base { $cellsgenerator = new user_sessions_cells_html_generator($reportdata, $user); $row->cells = array_merge($row->cells, $cellsgenerator->get_cells(true)); - foreach ($reportdata->statuses as $status) { - if (array_key_exists($status->id, $reportdata->usersstats[$user->id])) { - $row->cells[] = $reportdata->usersstats[$user->id][$status->id]->stcnt; - } else { - // No attendance data for this $status => no statistic for this status. - $row->cells[] = 0; - } - } - - if ($reportdata->gradable) { - $row->cells[] = format_float($reportdata->grades[$user->id]).' / '.format_float($reportdata->maxgrades[$user->id]); - } + $usersummary = $reportdata->summary->get_taken_sessions_summary_for($user->id); + $row->cells[] = $usersummary->numtakensessions; + $row->cells[] = attendance_format_float($usersummary->takensessionspoints) . ' / ' . + attendance_format_float($usersummary->takensessionsmaxpoints); + $row->cells[] = attendance_format_float($usersummary->takensessionspercentage * 100, false) . '%'; if ($bulkmessagecapability) { // Create the checkbox for bulk messaging. $row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false, '', @@ -936,22 +928,30 @@ class mod_attendance_renderer extends plugin_renderer_base { $statrow->cells[] = ''; $statrow->cells[] = get_string('summary'); foreach ($reportdata->sessions as $sess) { + $sessionstats = array(); + foreach ($reportdata->statuses as $status) { + if ($status->setnumber == $sess->statusset) { + $status->count = 0; + $sessionstats[$status->id] = $status; + } + } + foreach ($reportdata->users as $user) { - foreach ($reportdata->statuses as $status) { - if (!empty($reportdata->sessionslog[$user->id][$sess->id])) { - if ($reportdata->sessionslog[$user->id][$sess->id]->statusid == $status->id) { - $sessionstats[$status->id]++; - } + if (!empty($reportdata->sessionslog[$user->id][$sess->id])) { + $statusid = $reportdata->sessionslog[$user->id][$sess->id]->statusid; + if (isset($sessionstats[$statusid]->count)) { + $sessionstats[$statusid]->count++; } } } $statsoutput = '
'; - foreach ($reportdata->statuses as $status) { - $statsoutput .= "$status->description:".$sessionstats[$status->id]."
"; + foreach ($sessionstats as $status) { + $statsoutput .= "$status->description: {$status->count}
"; } - $statrow->cells[] = $statsoutput; - + $cell = new html_table_cell($statsoutput); + $cell->style = 'white-space:nowrap;'; + $statrow->cells[] = $cell; } $table->data[] = $statrow;