From b44d683b8f9dbd00538d826e17929174b16d7c8a Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 9 Dec 2013 21:27:04 +1300 Subject: [PATCH] Check group membership if using groups when displaying/exporting reports. --- locallib.php | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/locallib.php b/locallib.php index f5512ee..de63376 100644 --- a/locallib.php +++ b/locallib.php @@ -1070,7 +1070,21 @@ class attendance { global $DB; if (!array_key_exists($userid, $this->userstatusesstat)) { - $qry = "SELECT al.statusid, count(al.statusid) AS stcnt + if (!empty($this->cm->groupmode)) { + $qry = "SELECT al.statusid, count(al.statusid) AS stcnt + FROM {attendance_log} al + JOIN {attendance_sessions} ats ON al.sessionid = ats.id + JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid + WHERE ats.attendanceid = :aid AND + ats.sessdate >= :cstartdate AND + al.studentid = :uid + GROUP BY al.statusid"; + $params = array( + 'aid' => $this->id, + 'cstartdate' => $this->course->startdate, + 'uid' => $userid); + } else { + $qry = "SELECT al.statusid, count(al.statusid) AS stcnt FROM {attendance_log} al JOIN {attendance_sessions} ats ON al.sessionid = ats.id @@ -1078,10 +1092,11 @@ class attendance { ats.sessdate >= :cstartdate AND al.studentid = :uid GROUP BY al.statusid"; - $params = array( + $params = array( 'aid' => $this->id, 'cstartdate' => $this->course->startdate, 'uid' => $userid); + } $this->userstatusesstat[$userid] = $DB->get_records_sql($qry, $params); } @@ -1127,20 +1142,36 @@ class attendance { } else { $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate"; } + if (!empty($this->cm->groupmode)) { + $sql = "SELECT ats.id, ats.sessdate, ats.groupid, al.statusid, al.remarks + FROM {attendance_sessions} ats + JOIN {attendance_log} al ON ats.id = al.sessionid AND al.studentid = :uid + JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid + WHERE $where + ORDER BY ats.sessdate ASC"; + + $params = array( + 'uid' => $userid, + 'aid' => $this->id, + 'csdate' => $this->course->startdate, + 'sdate' => $this->pageparams->startdate, + 'edate' => $this->pageparams->enddate); - $sql = "SELECT ats.id, ats.sessdate, ats.groupid, al.statusid, al.remarks + } else { + $sql = "SELECT ats.id, ats.sessdate, ats.groupid, al.statusid, al.remarks FROM {attendance_sessions} ats JOIN {attendance_log} al ON ats.id = al.sessionid AND al.studentid = :uid WHERE $where ORDER BY ats.sessdate ASC"; - $params = array( + $params = array( 'uid' => $userid, 'aid' => $this->id, 'csdate' => $this->course->startdate, 'sdate' => $this->pageparams->startdate, 'edate' => $this->pageparams->enddate); + } $sessions = $DB->get_records_sql($sql, $params); return $sessions;