From 598fe89c99297ecb12216a7f86e5ece6d7fd9e5e Mon Sep 17 00:00:00 2001 From: Nadav Kavalerchik Date: Mon, 20 Jan 2014 18:51:36 +0200 Subject: [PATCH] Calculate the sum of statuses for each user Hi Dan, Please review this little patch that sum up the number of each status occurrence for each user, and display it at the bottom of the attendance table. Nadav :-) --- renderer.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/renderer.php b/renderer.php index ab1983f..42bba70 100755 --- a/renderer.php +++ b/renderer.php @@ -320,7 +320,20 @@ class mod_attendance_renderer extends plugin_renderer_base { $table .= html_writer::tag('center', html_writer::empty_tag('input', $params)); $table = html_writer::tag('form', $table, array('method' => 'post', 'action' => $takedata->url_path())); - return $controls.$table; + // Calculate the sum of statuses for each user + $sessionstats[] = array(); + foreach ($takedata->sessionlog as $userlog) { + foreach($takedata->statuses as $status) { + if ($userlog->statusid == $status->id) $sessionstats[$status->id]++; + } + } + + $statsoutput = '
'; + foreach($takedata->statuses as $status) { + $statsoutput .= "$status->description = ".$sessionstats[$status->id]."
"; + } + + return $controls.$table.$statsoutput; } protected function render_attendance_take_controls(attendance_take_data $takedata) {