|
@ -194,7 +194,7 @@ class att_view_page_params extends att_page_with_filter_controls { |
|
|
const MODE_THIS_COURSE = 0; |
|
|
const MODE_THIS_COURSE = 0; |
|
|
const MODE_ALL_COURSES = 1; |
|
|
const MODE_ALL_COURSES = 1; |
|
|
|
|
|
|
|
|
public $student; |
|
|
public $studentid; |
|
|
|
|
|
|
|
|
public $mode; |
|
|
public $mode; |
|
|
|
|
|
|
|
@ -205,7 +205,7 @@ class att_view_page_params extends att_page_with_filter_controls { |
|
|
public function get_significant_params() { |
|
|
public function get_significant_params() { |
|
|
$params = array(); |
|
|
$params = array(); |
|
|
|
|
|
|
|
|
if (isset($this->student)) $params['student'] = $this->student; |
|
|
if (isset($this->studentid)) $params['studentid'] = $this->studentid; |
|
|
if ($this->mode != self::MODE_THIS_COURSE) $params['mode'] = $this->mode; |
|
|
if ($this->mode != self::MODE_THIS_COURSE) $params['mode'] = $this->mode; |
|
|
|
|
|
|
|
|
return $params; |
|
|
return $params; |
|
@ -605,13 +605,13 @@ class attforblock { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$this->sessgroupslist = array(); |
|
|
$this->sessgroupslist = array(); |
|
|
if ($allowedgroups or $this->groupmode == VISIBLEGROUPS or $this->perm->can_access_all_groups()) { |
|
|
if ($allowedgroups) { |
|
|
|
|
|
if ($this->groupmode == VISIBLEGROUPS or $this->perm->can_access_all_groups()) { |
|
|
$this->sessgroupslist[self::SELECTOR_ALL] = get_string('all', 'attforblock'); |
|
|
$this->sessgroupslist[self::SELECTOR_ALL] = get_string('all', 'attforblock'); |
|
|
} |
|
|
} |
|
|
if ($this->groupmode == VISIBLEGROUPS) { |
|
|
if ($this->groupmode == VISIBLEGROUPS) { |
|
|
$this->sessgroupslist[self::SELECTOR_COMMON] = get_string('commonsessions', 'attforblock'); |
|
|
$this->sessgroupslist[self::SELECTOR_COMMON] = get_string('commonsessions', 'attforblock'); |
|
|
} |
|
|
} |
|
|
if ($allowedgroups) { |
|
|
|
|
|
foreach ($allowedgroups as $group) { |
|
|
foreach ($allowedgroups as $group) { |
|
|
$this->sessgroupslist[$group->id] = format_string($group->name); |
|
|
$this->sessgroupslist[$group->id] = format_string($group->name); |
|
|
} |
|
|
} |
|
@ -802,11 +802,7 @@ class attforblock { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
|
if (!isset($this->statuses)) { |
|
|
if (!isset($this->statuses)) { |
|
|
if ($onlyvisible) { |
|
|
$this->statuses = get_statuses($this->id, $onlyvisible); |
|
|
$this->statuses = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND visible = 1 AND deleted = 0", array('aid' => $this->id), 'grade DESC'); |
|
|
|
|
|
} else { |
|
|
|
|
|
$this->statuses = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND deleted = 0", array('aid' => $this->id), 'grade DESC'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $this->statuses; |
|
|
return $this->statuses; |
|
@ -839,24 +835,11 @@ class attforblock { |
|
|
return $ret; |
|
|
return $ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function get_user_taken_sessions_count($userid, $courseid=NULL) { |
|
|
public function get_user_taken_sessions_count($userid) { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
|
if (!isset($this->usertakensesscount)) { |
|
|
if (!isset($this->usertakensesscount)) |
|
|
$qry = "SELECT count(*) as cnt |
|
|
$this->usertakensesscount = get_user_taken_sessions_count($this->id, $this->course->startdate, $userid); |
|
|
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"; |
|
|
|
|
|
$params = array( |
|
|
|
|
|
'aid' => $this->id, |
|
|
|
|
|
'cstartdate' => $this->course->startdate, |
|
|
|
|
|
'uid' => $userid); |
|
|
|
|
|
|
|
|
|
|
|
$this->usertakensesscount = $DB->count_records_sql($qry, $params); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $this->usertakensesscount; |
|
|
return $this->usertakensesscount; |
|
|
} |
|
|
} |
|
@ -884,16 +867,8 @@ class attforblock { |
|
|
return $this->userstatusesstat; |
|
|
return $this->userstatusesstat; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function get_user_grade($userid, $courseid=NULL) { |
|
|
public function get_user_grade($userid) { |
|
|
$statistics = $this->get_user_statuses_stat($userid, $courseid); |
|
|
return get_user_grade($this->get_user_statuses_stat($userid), $this->get_statuses()); |
|
|
$statuses = $this->get_statuses($courseid); |
|
|
|
|
|
|
|
|
|
|
|
$sum = 0; |
|
|
|
|
|
foreach ($statistics as $stat) { |
|
|
|
|
|
$sum += $stat->stcnt * $statuses[$stat->statusid]->grade; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $sum; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// For getting sessions count implemented simplest method - taken sessions. |
|
|
// For getting sessions count implemented simplest method - taken sessions. |
|
@ -901,11 +876,8 @@ class attforblock { |
|
|
// In the future we can implement another methods: |
|
|
// In the future we can implement another methods: |
|
|
// * all sessions between user start enrolment date and now; |
|
|
// * all sessions between user start enrolment date and now; |
|
|
// * all sessions between user start and end enrolment date. |
|
|
// * all sessions between user start and end enrolment date. |
|
|
public function get_user_max_grade($userid, $courseid=NULL) { |
|
|
public function get_user_max_grade($userid) { |
|
|
$takensessions = $this->get_user_taken_sessions_count($userid, $courseid); |
|
|
return get_user_max_grade($this->get_user_taken_sessions_count($userid), $this->get_statuses()); |
|
|
$statuses = $this->get_statuses($courseid); |
|
|
|
|
|
|
|
|
|
|
|
return current($statuses)->grade * $takensessions; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function get_user_filtered_sessions_log($userid) { |
|
|
public function get_user_filtered_sessions_log($userid) { |
|
@ -938,31 +910,90 @@ class attforblock { |
|
|
|
|
|
|
|
|
return $sessions; |
|
|
return $sessions; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get_statuses($attid, $onlyvisible=true) { |
|
|
|
|
|
global $DB; |
|
|
|
|
|
|
|
|
|
|
|
if ($onlyvisible) { |
|
|
|
|
|
$statuses = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND visible = 1 AND deleted = 0", array('aid' => $attid), 'grade DESC'); |
|
|
|
|
|
} else { |
|
|
|
|
|
$statuses = $DB->get_records_select('attendance_statuses', "attendanceid = :aid AND deleted = 0", array('aid' => $attid), 'grade DESC'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $statuses; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_user_taken_sessions_count($attid, $coursestartdate, $userid) { |
|
|
|
|
|
global $DB; |
|
|
|
|
|
|
|
|
|
|
|
$qry = "SELECT count(*) as cnt |
|
|
|
|
|
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"; |
|
|
|
|
|
$params = array( |
|
|
|
|
|
'aid' => $attid, |
|
|
|
|
|
'cstartdate' => $coursestartdate, |
|
|
|
|
|
'uid' => $userid); |
|
|
|
|
|
|
|
|
|
|
|
return $DB->count_records_sql($qry, $params); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function get_user_courses_with_attendance($userid) { |
|
|
function get_user_statuses_stat($attid, $coursestartdate, $userid) { |
|
|
|
|
|
global $DB; |
|
|
|
|
|
|
|
|
|
|
|
$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 |
|
|
|
|
|
GROUP BY al.statusid"; |
|
|
|
|
|
$params = array( |
|
|
|
|
|
'aid' => $attid, |
|
|
|
|
|
'cstartdate' => $coursestartdate, |
|
|
|
|
|
'uid' => $userid); |
|
|
|
|
|
|
|
|
|
|
|
return $DB->get_records_sql($qry, $params); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_user_grade($userstatusesstat, $statuses) { |
|
|
|
|
|
$sum = 0; |
|
|
|
|
|
foreach ($userstatusesstat as $stat) { |
|
|
|
|
|
$sum += $stat->stcnt * $statuses[$stat->statusid]->grade; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $sum; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_user_max_grade($sesscount, $statuses) { |
|
|
|
|
|
reset($statuses); |
|
|
|
|
|
return current($statuses)->grade * $sesscount; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_user_courses_attendances($userid) { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
|
// we can't get user courses based only on attendance_log information |
|
|
|
|
|
// because of then users will see only courses with taked attendance |
|
|
|
|
|
$usercourses = enrol_get_users_courses($userid); |
|
|
$usercourses = enrol_get_users_courses($userid); |
|
|
|
|
|
|
|
|
list($usql, $uparams) = $DB->get_in_or_equal(array_keys($usercourses), SQL_PARAMS_NAMED, 'cid0'); |
|
|
list($usql, $uparams) = $DB->get_in_or_equal(array_keys($usercourses), SQL_PARAMS_NAMED, 'cid0'); |
|
|
|
|
|
|
|
|
$sql = "SELECT ats.courseid, course.fullname |
|
|
$sql = "SELECT att.id as attid, att.course as courseid, course.fullname as coursefullname, |
|
|
FROM {attendance_sessions} ats |
|
|
course.startdate as coursestartdate, att.name as attname, att.grade as attgrade |
|
|
JOIN {attendance_log} al |
|
|
FROM {attforblock} att |
|
|
ON ats.id = al.sessionid AND al.studentid = :uid |
|
|
|
|
|
JOIN {course} course |
|
|
JOIN {course} course |
|
|
ON ats.courseid = course.id |
|
|
ON att.course = course.id |
|
|
WHERE ats.courseid $usql |
|
|
WHERE att.course $usql |
|
|
GROUP BY ats.courseid |
|
|
ORDER BY coursefullname ASC, attname ASC"; |
|
|
ORDER BY course.fullname ASC"; |
|
|
|
|
|
|
|
|
|
|
|
$params = array_merge($uparams, array('uid' => $userid)); |
|
|
$params = array_merge($uparams, array('uid' => $userid)); |
|
|
|
|
|
|
|
|
return $DB->get_records_sql($sql, $params); |
|
|
return $DB->get_records_sql($sql, $params); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?> |
|
|
?> |
|
|