Browse Source

Check group membership if using groups when displaying/exporting reports.

MOODLE_26_STABLE
Dan Marsden 11 years ago
parent
commit
b44d683b8f
  1. 31
      locallib.php

31
locallib.php

@ -1070,6 +1070,20 @@ class attendance {
global $DB; global $DB;
if (!array_key_exists($userid, $this->userstatusesstat)) { if (!array_key_exists($userid, $this->userstatusesstat)) {
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 $qry = "SELECT al.statusid, count(al.statusid) AS stcnt
FROM {attendance_log} al FROM {attendance_log} al
JOIN {attendance_sessions} ats JOIN {attendance_sessions} ats
@ -1082,6 +1096,7 @@ class attendance {
'aid' => $this->id, 'aid' => $this->id,
'cstartdate' => $this->course->startdate, 'cstartdate' => $this->course->startdate,
'uid' => $userid); 'uid' => $userid);
}
$this->userstatusesstat[$userid] = $DB->get_records_sql($qry, $params); $this->userstatusesstat[$userid] = $DB->get_records_sql($qry, $params);
} }
@ -1127,7 +1142,22 @@ class attendance {
} else { } else {
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate"; $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);
} else {
$sql = "SELECT ats.id, ats.sessdate, ats.groupid, al.statusid, al.remarks $sql = "SELECT ats.id, ats.sessdate, ats.groupid, al.statusid, al.remarks
FROM {attendance_sessions} ats FROM {attendance_sessions} ats
JOIN {attendance_log} al JOIN {attendance_log} al
@ -1141,6 +1171,7 @@ class attendance {
'csdate' => $this->course->startdate, 'csdate' => $this->course->startdate,
'sdate' => $this->pageparams->startdate, 'sdate' => $this->pageparams->startdate,
'edate' => $this->pageparams->enddate); 'edate' => $this->pageparams->enddate);
}
$sessions = $DB->get_records_sql($sql, $params); $sessions = $DB->get_records_sql($sql, $params);
return $sessions; return $sessions;

Loading…
Cancel
Save