Browse Source

CONTRIB-4864 Correct grade calculation when timeframe used in export.

MOODLE_26_STABLE
Dan Marsden 11 years ago
parent
commit
7b3a7add92
  1. 37
      locallib.php

37
locallib.php

@ -1073,13 +1073,28 @@ class attendance {
public function get_user_taken_sessions_count($userid) { public function get_user_taken_sessions_count($userid) {
if (!array_key_exists($userid, $this->usertakensesscount)) { if (!array_key_exists($userid, $this->usertakensesscount)) {
if ($this->pageparams->startdate && $this->pageparams->enddate) {
$this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid, $this->cm, $this->pageparams->startdate, $this->pageparams->enddate);
} else {
$this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid, $this->cm); $this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid, $this->cm);
} }
}
return $this->usertakensesscount[$userid]; return $this->usertakensesscount[$userid];
} }
public function get_user_statuses_stat($userid) { public function get_user_statuses_stat($userid) {
global $DB; global $DB;
$params = array(
'aid' => $this->id,
'cstartdate' => $this->course->startdate,
'uid' => $userid);
$period = '';
if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) {
$period = ' AND ats.sessdate >= :sdate AND ats.sessdate < :edate ';
$params['sdate'] = $this->pageparams->startdate;
$params['edate'] = $this->pageparams->enddate;
}
if (!array_key_exists($userid, $this->userstatusesstat)) { if (!array_key_exists($userid, $this->userstatusesstat)) {
if ($this->get_group_mode()) { if ($this->get_group_mode()) {
@ -1090,12 +1105,8 @@ class attendance {
WHERE ats.attendanceid = :aid AND WHERE ats.attendanceid = :aid AND
ats.sessdate >= :cstartdate AND ats.sessdate >= :cstartdate AND
al.studentid = :uid AND al.studentid = :uid AND
(ats.groupid = 0 or gm.id is NOT NULL) (ats.groupid = 0 or gm.id is NOT NULL)".$period."
GROUP BY al.statusid"; GROUP BY al.statusid";
$params = array(
'aid' => $this->id,
'cstartdate' => $this->course->startdate,
'uid' => $userid);
} else { } 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
@ -1103,14 +1114,12 @@ class attendance {
ON al.sessionid = ats.id ON al.sessionid = ats.id
WHERE ats.attendanceid = :aid AND WHERE ats.attendanceid = :aid AND
ats.sessdate >= :cstartdate AND ats.sessdate >= :cstartdate AND
al.studentid = :uid al.studentid = :uid".$period."
GROUP BY al.statusid"; GROUP BY al.statusid";
$params = array(
'aid' => $this->id,
'cstartdate' => $this->course->startdate,
'uid' => $userid);
} }
$this->userstatusesstat[$userid] = $DB->get_records_sql($qry, $params); $this->userstatusesstat[$userid] = $DB->get_records_sql($qry, $params);
} }
@ -1361,7 +1370,7 @@ function att_get_statuses($attid, $onlyvisible=true) {
return $statuses; return $statuses;
} }
function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $coursemodule) { function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $coursemodule, $startdate = '', $enddate = '') {
global $DB, $COURSE; global $DB, $COURSE;
$groupmode = groups_get_activity_groupmode($coursemodule, $COURSE); $groupmode = groups_get_activity_groupmode($coursemodule, $COURSE);
if (!empty($groupmode)) { if (!empty($groupmode)) {
@ -1387,6 +1396,12 @@ function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $c
'cstartdate' => $coursestartdate, 'cstartdate' => $coursestartdate,
'uid' => $userid); 'uid' => $userid);
if (!empty($startdate) && !empty($enddate)) {
$qry .= ' AND sessdate >= :sdate AND sessdate < :edate ';
$params['sdate'] = $startdate;
$params['edate'] = $enddate;
}
return $DB->count_records_sql($qry, $params); return $DB->count_records_sql($qry, $params);
} }

Loading…
Cancel
Save