|
@ -205,7 +205,7 @@ class att_page_with_filter_controls { |
|
|
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) { |
|
|
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) { |
|
|
$this->sessgroupslist[self::SESSTYPE_ALL] = get_string('all', 'attendance'); |
|
|
$this->sessgroupslist[self::SESSTYPE_ALL] = get_string('all', 'attendance'); |
|
|
} |
|
|
} |
|
|
// Show Common groups always |
|
|
// Show Common groups always. |
|
|
$this->sessgroupslist[self::SESSTYPE_COMMON] = get_string('commonsessions', 'attendance'); |
|
|
$this->sessgroupslist[self::SESSTYPE_COMMON] = get_string('commonsessions', 'attendance'); |
|
|
foreach ($allowedgroups as $group) { |
|
|
foreach ($allowedgroups as $group) { |
|
|
$this->sessgroupslist[$group->id] = format_string($group->name); |
|
|
$this->sessgroupslist[$group->id] = format_string($group->name); |
|
@ -731,14 +731,14 @@ class attendance { |
|
|
$sess->description); |
|
|
$sess->description); |
|
|
$DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id)); |
|
|
$DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id)); |
|
|
|
|
|
|
|
|
$info_array = array(); |
|
|
$infoarray = array(); |
|
|
$info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration); |
|
|
$infoarray[] = construct_session_full_date_time($sess->sessdate, $sess->duration); |
|
|
|
|
|
|
|
|
// Trigger a session added event. |
|
|
// Trigger a session added event. |
|
|
$event = \mod_attendance\event\session_added::create(array( |
|
|
$event = \mod_attendance\event\session_added::create(array( |
|
|
'objectid' => $this->id, |
|
|
'objectid' => $this->id, |
|
|
'context' => $this->context, |
|
|
'context' => $this->context, |
|
|
'other' => array('info' => implode(',', $info_array)) |
|
|
'other' => array('info' => implode(',', $infoarray)) |
|
|
)); |
|
|
)); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$sess->description = $description; |
|
|
$sess->description = $description; |
|
@ -885,7 +885,7 @@ class attendance { |
|
|
$this->update_users_grade(array_keys($sesslog)); |
|
|
$this->update_users_grade(array_keys($sesslog)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// create url for link in log screen |
|
|
// Create url for link in log screen. |
|
|
$params = array( |
|
|
$params = array( |
|
|
'sessionid' => $this->pageparams->sessionid, |
|
|
'sessionid' => $this->pageparams->sessionid, |
|
|
'grouptype' => $this->pageparams->grouptype); |
|
|
'grouptype' => $this->pageparams->grouptype); |
|
@ -898,7 +898,7 @@ class attendance { |
|
|
$event->trigger(); |
|
|
$event->trigger(); |
|
|
|
|
|
|
|
|
$group = 0; |
|
|
$group = 0; |
|
|
if ($this->pageparams->grouptype != attendance::SESSION_COMMON) { |
|
|
if ($this->pageparams->grouptype != self::SESSION_COMMON) { |
|
|
$group = $this->pageparams->grouptype; |
|
|
$group = $this->pageparams->grouptype; |
|
|
} else { |
|
|
} else { |
|
|
if ($this->pageparams->group) { |
|
|
if ($this->pageparams->group) { |
|
@ -950,7 +950,8 @@ class attendance { |
|
|
'', false, true); |
|
|
'', false, true); |
|
|
} else { |
|
|
} else { |
|
|
$startusers = ($page - 1) * $usersperpage; |
|
|
$startusers = ($page - 1) * $usersperpage; |
|
|
$users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby, $startusers, $usersperpage); |
|
|
$users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, |
|
|
|
|
|
$orderby, $startusers, $usersperpage); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if (!empty($CFG->enablegroupmembersonly) and $this->cm->groupmembersonly) { |
|
|
if (!empty($CFG->enablegroupmembersonly) and $this->cm->groupmembersonly) { |
|
@ -972,11 +973,11 @@ class attendance { |
|
|
if (!empty($users)) { |
|
|
if (!empty($users)) { |
|
|
list($sql, $params) = $DB->get_in_or_equal(array_keys($users), SQL_PARAMS_NAMED, 'usid0'); |
|
|
list($sql, $params) = $DB->get_in_or_equal(array_keys($users), SQL_PARAMS_NAMED, 'usid0'); |
|
|
|
|
|
|
|
|
// CONTRIB-4868 |
|
|
// See CONTRIB-4868. |
|
|
$mintime = 'MIN(CASE WHEN (ue.timestart > :zerotime) THEN ue.timestart ELSE ue.timecreated END)'; |
|
|
$mintime = 'MIN(CASE WHEN (ue.timestart > :zerotime) THEN ue.timestart ELSE ue.timecreated END)'; |
|
|
$maxtime = 'CASE WHEN MIN(ue.timeend) = 0 THEN 0 ELSE MAX(ue.timeend) END'; |
|
|
$maxtime = 'CASE WHEN MIN(ue.timeend) = 0 THEN 0 ELSE MAX(ue.timeend) END'; |
|
|
|
|
|
|
|
|
// CONTRIB-3549 |
|
|
// See CONTRIB-3549. |
|
|
$sql = "SELECT ue.userid, MIN(ue.status) as status, |
|
|
$sql = "SELECT ue.userid, MIN(ue.status) as status, |
|
|
$mintime AS mintime, |
|
|
$mintime AS mintime, |
|
|
$maxtime AS maxtime |
|
|
$maxtime AS maxtime |
|
@ -1040,7 +1041,7 @@ class attendance { |
|
|
|
|
|
|
|
|
$user->type = 'standard'; |
|
|
$user->type = 'standard'; |
|
|
|
|
|
|
|
|
// CONTRIB-4868 |
|
|
// See CONTRIB-4868. |
|
|
$mintime = 'MIN(CASE WHEN (ue.timestart > :zerotime) THEN ue.timestart ELSE ue.timecreated END)'; |
|
|
$mintime = 'MIN(CASE WHEN (ue.timestart > :zerotime) THEN ue.timestart ELSE ue.timecreated END)'; |
|
|
$maxtime = 'CASE WHEN MIN(ue.timeend) = 0 THEN 0 ELSE MAX(ue.timeend) END'; |
|
|
$maxtime = 'CASE WHEN MIN(ue.timeend) = 0 THEN 0 ELSE MAX(ue.timeend) END'; |
|
|
|
|
|
|
|
@ -1134,9 +1135,12 @@ 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 (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { |
|
|
if (!empty($this->pageparams->startdate) && !empty($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); |
|
|
$this->usertakensesscount[$userid] = |
|
|
|
|
|
att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid, |
|
|
|
|
|
$this->cm, $this->pageparams->startdate, $this->pageparams->enddate); |
|
|
} else { |
|
|
} 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]; |
|
@ -1156,22 +1160,21 @@ class attendance { |
|
|
'cstartdate' => $this->course->startdate, |
|
|
'cstartdate' => $this->course->startdate, |
|
|
'uid' => $userid); |
|
|
'uid' => $userid); |
|
|
|
|
|
|
|
|
$processed_filters = array(); |
|
|
$processedfilters = array(); |
|
|
|
|
|
|
|
|
// We test for any valid filters sent. |
|
|
// We test for any valid filters sent. |
|
|
if (isset($filters['enddate'])) { |
|
|
if (isset($filters['enddate'])) { |
|
|
$processed_filters[] = 'ats.sessdate <= :enddate'; |
|
|
$processedfilters[] = 'ats.sessdate <= :enddate'; |
|
|
$params['enddate'] = $filters['enddate']; |
|
|
$params['enddate'] = $filters['enddate']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Make the filter array into a SQL string. |
|
|
// Make the filter array into a SQL string. |
|
|
if (!empty($processed_filters)) { |
|
|
if (!empty($processedfilters)) { |
|
|
$processed_filters = ' AND '.implode(' AND ', $processed_filters); |
|
|
$processedfilters = ' AND '.implode(' AND ', $processedfilters); |
|
|
} else { |
|
|
} else { |
|
|
$processed_filters = ''; |
|
|
$processedfilters = ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$period = ''; |
|
|
$period = ''; |
|
|
if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { |
|
|
if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { |
|
|
$period = ' AND ats.sessdate >= :sdate AND ats.sessdate < :edate '; |
|
|
$period = ' AND ats.sessdate >= :sdate AND ats.sessdate < :edate '; |
|
@ -1187,7 +1190,7 @@ 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)".$period.$processed_filters." |
|
|
(ats.groupid = 0 or gm.id is NOT NULL)".$period.$processedfilters." |
|
|
GROUP BY al.statusid"; |
|
|
GROUP BY al.statusid"; |
|
|
} else { |
|
|
} else { |
|
|
$qry = "SELECT al.statusid, count(al.statusid) AS stcnt |
|
|
$qry = "SELECT al.statusid, count(al.statusid) AS stcnt |
|
@ -1196,7 +1199,7 @@ 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".$period.$processed_filters." |
|
|
al.studentid = :uid".$period.$processedfilters." |
|
|
GROUP BY al.statusid"; |
|
|
GROUP BY al.statusid"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1314,10 +1317,12 @@ class attendance { |
|
|
|
|
|
|
|
|
// We need to add this concatination so that moodle will use it as the array index that is a string. |
|
|
// We need to add this concatination so that moodle will use it as the array index that is a string. |
|
|
// If the array's index is a number it will not merge entries. |
|
|
// If the array's index is a number it will not merge entries. |
|
|
// It would be better as a UNION query butunfortunatly MS SQL does not seem to support doing a DISTINCT on a the description field. |
|
|
// It would be better as a UNION query but unfortunatly MS SQL does not seem to support doing a |
|
|
|
|
|
// DISTINCT on a the description field. |
|
|
$id = $DB->sql_concat(':value', 'ats.id'); |
|
|
$id = $DB->sql_concat(':value', 'ats.id'); |
|
|
if ($this->get_group_mode()) { |
|
|
if ($this->get_group_mode()) { |
|
|
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks, ats.studentscanmark |
|
|
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, |
|
|
|
|
|
al.statusid, al.remarks, ats.studentscanmark |
|
|
FROM {attendance_sessions} ats |
|
|
FROM {attendance_sessions} ats |
|
|
RIGHT JOIN {attendance_log} al |
|
|
RIGHT JOIN {attendance_log} al |
|
|
ON ats.id = al.sessionid AND al.studentid = :uid |
|
|
ON ats.id = al.sessionid AND al.studentid = :uid |
|
@ -1325,7 +1330,8 @@ class attendance { |
|
|
WHERE $where AND (ats.groupid = 0 or gm.id is NOT NULL) |
|
|
WHERE $where AND (ats.groupid = 0 or gm.id is NOT NULL) |
|
|
ORDER BY ats.sessdate ASC"; |
|
|
ORDER BY ats.sessdate ASC"; |
|
|
} else { |
|
|
} else { |
|
|
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks, ats.studentscanmark |
|
|
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, |
|
|
|
|
|
al.statusid, al.remarks, ats.studentscanmark |
|
|
FROM {attendance_sessions} ats |
|
|
FROM {attendance_sessions} ats |
|
|
RIGHT JOIN {attendance_log} al |
|
|
RIGHT JOIN {attendance_log} al |
|
|
ON ats.id = al.sessionid AND al.studentid = :uid |
|
|
ON ats.id = al.sessionid AND al.studentid = :uid |
|
@ -1355,7 +1361,8 @@ class attendance { |
|
|
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid $gsql"; |
|
|
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid $gsql"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks, ats.studentscanmark |
|
|
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, |
|
|
|
|
|
al.statusid, al.remarks, ats.studentscanmark |
|
|
FROM {attendance_sessions} ats |
|
|
FROM {attendance_sessions} ats |
|
|
LEFT JOIN {attendance_log} al |
|
|
LEFT JOIN {attendance_log} al |
|
|
ON ats.id = al.sessionid AND al.studentid = :uid |
|
|
ON ats.id = al.sessionid AND al.studentid = :uid |
|
@ -1508,7 +1515,8 @@ class attendance { |
|
|
$event = \mod_attendance\event\status_updated::create(array( |
|
|
$event = \mod_attendance\event\status_updated::create(array( |
|
|
'objectid' => $this->id, |
|
|
'objectid' => $this->id, |
|
|
'context' => $this->context, |
|
|
'context' => $this->context, |
|
|
'other' => array('acronym' => $acronym, 'description' => $description, 'grade' => $grade, 'updated' => implode(' ', $updated)))); |
|
|
'other' => array('acronym' => $acronym, 'description' => $description, 'grade' => $grade, |
|
|
|
|
|
'updated' => implode(' ', $updated)))); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('attendance_statuses', $status); |
|
|
$event->add_record_snapshot('attendance_statuses', $status); |
|
|
$event->trigger(); |
|
|
$event->trigger(); |
|
@ -1716,9 +1724,9 @@ function att_update_all_users_grades($attid, $course, $context, $coursemodule) { |
|
|
$dbparams = array('id' => -($this->grade)); |
|
|
$dbparams = array('id' => -($this->grade)); |
|
|
$this->scale = $DB->get_record('scale', $dbparams); |
|
|
$this->scale = $DB->get_record('scale', $dbparams); |
|
|
$scalearray = explode(',', $this->scale->scale); |
|
|
$scalearray = explode(',', $this->scale->scale); |
|
|
$gradebook_maxgrade = count($scalearray); |
|
|
$gradebookmaxgrade = count($scalearray); |
|
|
} else { |
|
|
} else { |
|
|
$gradebook_maxgrade = att_get_gradebook_maxgrade($attid); |
|
|
$gradebookmaxgrade = att_get_gradebook_maxgrade($attid); |
|
|
} |
|
|
} |
|
|
foreach ($userids as $userid) { |
|
|
foreach ($userids as $userid) { |
|
|
$grade = new stdClass; |
|
|
$grade = new stdClass; |
|
@ -1727,7 +1735,7 @@ function att_update_all_users_grades($attid, $course, $context, $coursemodule) { |
|
|
$usertakensesscount = att_get_user_taken_sessions_count($attid, $course->startdate, $userid, $coursemodule); |
|
|
$usertakensesscount = att_get_user_taken_sessions_count($attid, $course->startdate, $userid, $coursemodule); |
|
|
$usergrade = att_get_user_grade($userstatusesstat, $statuses); |
|
|
$usergrade = att_get_user_grade($userstatusesstat, $statuses); |
|
|
$usermaxgrade = att_get_user_max_grade($usertakensesscount, $statuses); |
|
|
$usermaxgrade = att_get_user_max_grade($usertakensesscount, $statuses); |
|
|
$grade->rawgrade = att_calc_user_grade_fraction($usergrade, $usermaxgrade) * $gradebook_maxgrade; |
|
|
$grade->rawgrade = att_calc_user_grade_fraction($usergrade, $usermaxgrade) * $gradebookmaxgrade; |
|
|
$grades[$userid] = $grade; |
|
|
$grades[$userid] = $grade; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|