To the user's report added taked sessions from previous groups
authorArtem Andreev <andreev.artem@gmail.com>
Sat, 2 Mar 2013 10:08:38 +0000 (14:08 +0400)
committerArtem Andreev <andreev.artem@gmail.com>
Sat, 2 Mar 2013 10:10:29 +0000 (14:10 +0400)
locallib.php
renderables.php
renderer.php

index 68633de..a4f3bad 100644 (file)
@@ -1051,20 +1051,18 @@ class attforblock {
     public function get_user_filtered_sessions_log_extended($userid) {
         global $DB;
 
-        $groups = array_keys(groups_get_all_groups($this->course->id, $userid));
-        $groups[] = 0;
-        list($gsql, $gparams) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED, 'gid0');
+        // all taked sessions (including previous groups)
 
         if ($this->pageparams->startdate && $this->pageparams->enddate) {
             $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND 
-                      ats.sessdate >= :sdate AND ats.sessdate < :edate AND ats.groupid $gsql";
+                      ats.sessdate >= :sdate AND ats.sessdate < :edate";
         } else {
-            $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid $gsql";
+            $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate";
         }
 
-        $sql = "SELECT ats.id, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks
+        $sql = "SELECT ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks
                   FROM {attendance_sessions} ats
-             LEFT JOIN {attendance_log} al
+            RIGHT JOIN {attendance_log} al
                     ON ats.id = al.sessionid AND al.studentid = :uid
                  WHERE $where
               ORDER BY ats.sessdate ASC";
@@ -1075,8 +1073,33 @@ class attforblock {
                 'csdate'    => $this->course->startdate,
                 'sdate'     => $this->pageparams->startdate,
                 'edate'     => $this->pageparams->enddate);
-        $params = array_merge($params, $gparams);
         $sessions = $DB->get_records_sql($sql, $params);
+
+
+        // all sessions for current groups
+
+        $groups = array_keys(groups_get_all_groups($this->course->id, $userid));
+        $groups[] = 0;
+        list($gsql, $gparams) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED, 'gid0');
+
+        if ($this->pageparams->startdate && $this->pageparams->enddate) {
+            $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND
+                      ats.sessdate >= :sdate AND ats.sessdate < :edate AND ats.groupid $gsql";
+        } else {
+            $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid $gsql";
+        }
+
+        $sql = "SELECT ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks
+                  FROM {attendance_sessions} ats
+             LEFT JOIN {attendance_log} al
+                    ON ats.id = al.sessionid AND al.studentid = :uid
+                 WHERE $where
+              ORDER BY ats.sessdate ASC";
+
+        $params = array_merge($params, $gparams);
+        $sessions = array_merge($sessions, $DB->get_records_sql($sql, $params));
+
+
         foreach ($sessions as $sess) {
             if (empty($sess->description)) {
                 $sess->description = get_string('nodescription', 'attforblock');
index a5482ca..01076e1 100644 (file)
@@ -333,6 +333,8 @@ class attforblock_user_data implements renderable {
 
     public $sessionslog;
 
+    public $groups;
+
     public $coursesatts;
 
     private $urlpath;
@@ -364,6 +366,8 @@ class attforblock_user_data implements renderable {
             $this->filtercontrols = new attforblock_filter_controls($att);
 
             $this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid);
+
+            $this->groups = groups_get_all_groups($att->course->id);
         }
         else {
             $this->coursesatts = att_get_user_courses_attendances($userid);
index fcca382..86e0f93 100644 (file)
@@ -592,9 +592,17 @@ class mod_attforblock_renderer extends plugin_renderer_base {
     private function construct_user_sessions_log(attforblock_user_data $userdata) {
         $table = new html_table();
         $table->attributes['class'] = 'generaltable attwidth boxaligncenter';
-        $table->head = array('#', get_string('date'), get_string('time'), get_string('description','attforblock'), get_string('status','attforblock'), get_string('remarks','attforblock'));
-        $table->align = array('', '', 'left', 'left', 'center', 'left');
-        $table->size = array('1px', '1px', '1px', '*', '1px', '1px');
+        $table->head = array(
+            '#',
+            get_string('sessiontypeshort', 'attforblock'),
+            get_string('date'),
+            get_string('time'),
+            get_string('description','attforblock'),
+            get_string('status','attforblock'),
+            get_string('remarks','attforblock')
+        );
+        $table->align = array('', '', '', 'left', 'left', 'center', 'left');
+        $table->size = array('1px', '1px', '1px', '1px', '*', '1px', '1px');
 
         $i = 0;
         foreach ($userdata->sessionslog as $sess) {
@@ -602,6 +610,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
 
             $row = new html_table_row();
             $row->cells[] = $i;
+            $row->cells[] = html_writer::tag('nobr', $sess->groupid ? $userdata->groups[$sess->groupid]->name : get_string('commonsession', 'attforblock'));
             $row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attforblock'));
             $row->cells[] = $this->construct_time($sess->sessdate, $sess->duration);
             $row->cells[] = $sess->description;