Add summary report (#66)
authorAntonio Carlos Mariani <antonio.c.mariani@ufsc.br>
Tue, 3 May 2016 19:18:13 +0000 (16:18 -0300)
committerAntonio Carlos Mariani <antonio.c.mariani@ufsc.br>
Wed, 4 May 2016 19:54:10 +0000 (16:54 -0300)
classes/page_with_filter_controls.php
lang/en/attendance.php
locallib.php
renderables.php
renderer.php
styles.css

index 9617e8f..cadc9f1 100644 (file)
@@ -124,6 +124,10 @@ class mod_attendance_page_with_filter_controls {
                 $this->startdate = 0;
                 $this->enddate = 0;
                 break;
+            case ATT_VIEW_SUMMARY:
+                $this->startdate = 1;
+                $this->enddate = 1;
+                break;
         }
     }
 
@@ -221,4 +225,4 @@ class mod_attendance_page_with_filter_controls {
     public function set_current_sesstype($sesstype) {
         $this->sesstype = $sesstype;
     }
-}
\ No newline at end of file
+}
index 4f59845..18f6889 100644 (file)
@@ -260,6 +260,7 @@ $string['strftimedmyw'] = '%d.%m.%y&nbsp;(%a)';
 $string['strftimehm'] = '%H:%M'; // Line added to allow display of time.
 $string['strftimeshortdate'] = '%d.%m.%Y';
 $string['studentid'] = 'Student ID';
+$string['summary'] = 'Summary';
 $string['takeattendance'] = 'Take attendance';
 $string['takensessions'] = 'Taken sessions';
 $string['tempaddform'] = 'Add temporary user';
index 984fef9..1d30ecb 100644 (file)
@@ -33,6 +33,7 @@ define('ATT_VIEW_MONTHS', 3);
 define('ATT_VIEW_ALLPAST', 4);
 define('ATT_VIEW_ALL', 5);
 define('ATT_VIEW_NOTPRESENT', 6);
+define('ATT_VIEW_SUMMARY', 7);
 
 define('ATT_SORT_LASTNAME', 1);
 define('ATT_SORT_FIRSTNAME', 2);
index cc1c54b..e00a0f1 100644 (file)
@@ -128,7 +128,7 @@ class attendance_filter_controls implements renderable {
     private $urlpath;
     private $urlparams;
 
-    private $att;
+    public $att;
 
     public function __construct(mod_attendance_structure $att, $report = false) {
         global $PAGE;
@@ -138,7 +138,7 @@ class attendance_filter_controls implements renderable {
         $this->cm = $att->cm;
 
         // This is a report control only if $reports is true and the attendance block can be graded.
-        $this->reportcontrol = $report && ($att->grade > 0);
+        $this->reportcontrol = $report;
 
         $this->curdate = $att->pageparams->curdate;
 
@@ -440,7 +440,11 @@ class attendance_report_data implements renderable {
         $this->statuses = $att->get_statuses(true, true);
         $this->allstatuses = $att->get_statuses(false, true);
 
-        $this->summary = new mod_attendance_summary($att->id, array_keys($this->users), $att->pageparams->startdate, $att->pageparams->enddate);
+        if ($att->pageparams->view == ATT_VIEW_SUMMARY) {
+            $this->summary = new mod_attendance_summary($att->id);
+        } else {
+            $this->summary = new mod_attendance_summary($att->id, array_keys($this->users), $att->pageparams->startdate, $att->pageparams->enddate);
+        }
 
         foreach ($this->users as $key => $user) {
             $usersummary = $this->summary->get_taken_sessions_summary_for($user->id);
index 9610fc7..bbeb2ec 100644 (file)
@@ -176,12 +176,15 @@ class mod_attendance_renderer extends plugin_renderer_base {
     protected function render_view_controls(attendance_filter_controls $fcontrols) {
         $views[ATT_VIEW_ALL] = get_string('all', 'attendance');
         $views[ATT_VIEW_ALLPAST] = get_string('allpast', 'attendance');
-        if ($fcontrols->reportcontrol) {
+        if ($fcontrols->reportcontrol  && $fcontrols->att->grade > 0) {
             $views[ATT_VIEW_NOTPRESENT] = get_string('lowgrade', 'attendance');
         }
         $views[ATT_VIEW_MONTHS] = get_string('months', 'attendance');
         $views[ATT_VIEW_WEEKS] = get_string('weeks', 'attendance');
         $views[ATT_VIEW_DAYS] = get_string('days', 'attendance');
+        if ($fcontrols->reportcontrol) {
+            $views[ATT_VIEW_SUMMARY] = get_string('summary', 'attendance');
+        }
         $viewcontrols = '';
         foreach ($views as $key => $sview) {
             if ($key != $fcontrols->pageparams->view) {
@@ -852,6 +855,9 @@ class mod_attendance_renderer extends plugin_renderer_base {
         $table = new html_table();
 
         $table->attributes['class'] = 'generaltable attwidth';
+        if ($reportdata->pageparams->view == ATT_VIEW_SUMMARY) {
+            $table->attributes['class'] .= ' summaryreport';
+        }
 
         // User picture.
         $table->head[] = '';
@@ -903,6 +909,28 @@ class mod_attendance_renderer extends plugin_renderer_base {
         $table->align[] = 'center';
         $table->size[] = '1px';
 
+        if ($reportdata->pageparams->view == ATT_VIEW_SUMMARY) {
+            $table->head[] = get_string('sessionstotal', 'attendance');
+            $table->align[] = 'center';
+            $table->size[] = '1px';
+
+            $table->head[] = get_string('pointsallsessions', 'attendance');
+            $table->align[] = 'center';
+            $table->size[] = '1px';
+
+            $table->head[] = get_string('percentageallsessions', 'attendance');
+            $table->align[] = 'center';
+            $table->size[] = '1px';
+
+            $table->head[] = get_string('maxpossiblepoints', 'attendance');
+            $table->align[] = 'center';
+            $table->size[] = '1px';
+
+            $table->head[] = get_string('maxpossiblepercentage', '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.
             $table->head[] = html_writer::checkbox('cb_selector', 0, false, '', array('id' => 'cb_selector'));
@@ -918,12 +946,27 @@ 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));
 
-            $usersummary = $reportdata->summary->get_taken_sessions_summary_for($user->id);
+            if ($reportdata->pageparams->view == ATT_VIEW_SUMMARY) {
+                $usersummary = $reportdata->summary->get_all_sessions_summary_for($user->id);
+            } else {
+                $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 ($reportdata->pageparams->view == ATT_VIEW_SUMMARY) {
+                $row->cells[] = $usersummary->numallsessions;
+                $row->cells[] = attendance_format_float($usersummary->takensessionspoints) . ' / ' .
+                                attendance_format_float($usersummary->allsessionsmaxpoints);
+                $row->cells[] = attendance_format_float($usersummary->allsessionspercentage * 100, false) . '%';
+
+                $row->cells[] = attendance_format_float($usersummary->maxpossiblepoints) . ' / ' .
+                                attendance_format_float($usersummary->allsessionsmaxpoints);
+                $row->cells[] = attendance_format_float($usersummary->maxpossiblepercentage * 100, false) . '%';
+            }
+
             if ($bulkmessagecapability) { // Create the checkbox for bulk messaging.
                 $row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false, '',
                                                       array('class' => 'attendancesesscheckbox'));
index 4186842..52a860a 100644 (file)
@@ -17,7 +17,7 @@
 }
 
 .path-mod-attendance .attfiltercontrols {
-    margin-bottom: 10px;
+    margin-bottom: 10px !important;
     margin-right:auto;
     margin-left:auto;
 }
 
 .path-mod-attendance .attendancestatus-A {
     color: red;
-}
\ No newline at end of file
+}
+
+.path-mod-attendance .summaryreport .c5 {
+    background-color: #EAEAEA;
+}
+
+.path-mod-attendance .summaryreport .c6 {
+    background-color: #EAEAEA;
+}
+
+.path-mod-attendance .summaryreport .c7 {
+    background-color: #EAEAEA;
+}