|
@ -746,116 +746,6 @@ class mod_attendance_structure { |
|
|
return $DB->get_records('attendance_log', array('sessionid' => $sessionid), '', 'studentid,statusid,remarks,id'); |
|
|
return $DB->get_records('attendance_log', array('sessionid' => $sessionid), '', 'studentid,statusid,remarks,id'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function get_user_stat($userid) { |
|
|
|
|
|
$ret = array(); |
|
|
|
|
|
$ret['completed'] = $this->get_user_taken_sessions_count($userid); |
|
|
|
|
|
$ret['statuses'] = $this->get_user_statuses_stat($userid); |
|
|
|
|
|
|
|
|
|
|
|
return $ret; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function get_user_taken_sessions_count($userid) { |
|
|
|
|
|
if (!array_key_exists($userid, $this->usertakensesscount)) { |
|
|
|
|
|
if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { |
|
|
|
|
|
$this->usertakensesscount[$userid] = attendance_get_user_taken_sessions_count($this->id, $this->course->startdate, |
|
|
|
|
|
$userid, $this->cm, $this->pageparams->startdate, $this->pageparams->enddate); |
|
|
|
|
|
} else { |
|
|
|
|
|
$this->usertakensesscount[$userid] = attendance_get_user_taken_sessions_count($this->id, $this->course->startdate, |
|
|
|
|
|
$userid, $this->cm); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return $this->usertakensesscount[$userid]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param type $userid |
|
|
|
|
|
* @param type $filters - An array things to filter by. For now only enddate is valid. |
|
|
|
|
|
* @return type |
|
|
|
|
|
*/ |
|
|
|
|
|
public function get_user_statuses_stat($userid, array $filters = null) { |
|
|
|
|
|
global $DB; |
|
|
|
|
|
$params = array( |
|
|
|
|
|
'aid' => $this->id, |
|
|
|
|
|
'cstartdate' => $this->course->startdate, |
|
|
|
|
|
'uid' => $userid); |
|
|
|
|
|
|
|
|
|
|
|
$processedfilters = array(); |
|
|
|
|
|
|
|
|
|
|
|
// We test for any valid filters sent. |
|
|
|
|
|
if (isset($filters['enddate'])) { |
|
|
|
|
|
$processedfilters[] = 'ats.sessdate <= :enddate'; |
|
|
|
|
|
$params['enddate'] = $filters['enddate']; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Make the filter array into a SQL string. |
|
|
|
|
|
if (!empty($processedfilters)) { |
|
|
|
|
|
$processedfilters = ' AND '.implode(' AND ', $processedfilters); |
|
|
|
|
|
} else { |
|
|
|
|
|
$processedfilters = ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$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 ($this->get_group_mode()) { |
|
|
|
|
|
$qry = "SELECT al.statusid, count(al.statusid) AS stcnt |
|
|
|
|
|
FROM {attendance_log} al |
|
|
|
|
|
JOIN {attendance_sessions} ats ON al.sessionid = ats.id |
|
|
|
|
|
LEFT 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 AND |
|
|
|
|
|
(ats.groupid = 0 or gm.id is NOT NULL)".$period.$processedfilters." |
|
|
|
|
|
GROUP BY al.statusid"; |
|
|
|
|
|
} else { |
|
|
|
|
|
$qry = "SELECT al.statusid, count(al.statusid) AS stcnt |
|
|
|
|
|
FROM {attendance_log} al |
|
|
|
|
|
JOIN {attendance_sessions} ats |
|
|
|
|
|
ON al.sessionid = ats.id |
|
|
|
|
|
WHERE ats.attendanceid = :aid AND |
|
|
|
|
|
ats.sessdate >= :cstartdate AND |
|
|
|
|
|
al.studentid = :uid".$period.$processedfilters." |
|
|
|
|
|
GROUP BY al.statusid"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// We do not want to cache, or use a cached version of the results when a filter is set. |
|
|
|
|
|
if ($filters !== null) { |
|
|
|
|
|
return $DB->get_records_sql($qry, $params); |
|
|
|
|
|
} else if (!array_key_exists($userid, $this->userstatusesstat)) { |
|
|
|
|
|
// Not filtered so if we do not already have them do the query. |
|
|
|
|
|
$this->userstatusesstat[$userid] = $DB->get_records_sql($qry, $params); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Return the cached stats. |
|
|
|
|
|
return $this->userstatusesstat[$userid]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param type $userid |
|
|
|
|
|
* @param type $filters - An array things to filter by. For now only enddate is valid. |
|
|
|
|
|
* @return type |
|
|
|
|
|
*/ |
|
|
|
|
|
public function get_user_grade($userid, array $filters = null) { |
|
|
|
|
|
return attendance_get_user_grade($this->get_user_statuses_stat($userid, $filters), $this->get_statuses(true, true)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// For getting sessions count implemented simplest method - taken sessions. |
|
|
|
|
|
// It can have error if users don't have attendance info for some sessions. |
|
|
|
|
|
// In the future we can implement another methods: |
|
|
|
|
|
// * all sessions between user start enrolment date and now; |
|
|
|
|
|
// * all sessions between user start and end enrolment date. |
|
|
|
|
|
// While implementing those methods we need recalculate grades of all users |
|
|
|
|
|
// on session adding. |
|
|
|
|
|
public function get_user_max_grade($userid) { |
|
|
|
|
|
return attendance_get_user_max_grade($this->get_user_taken_sessions_count($userid), $this->get_statuses(true, true)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function update_users_grade($userids) { |
|
|
public function update_users_grade($userids) { |
|
|
attendance_update_users_grade($this, $userids); |
|
|
attendance_update_users_grade($this, $userids); |
|
|
} |
|
|
} |
|
|