|
@ -795,32 +795,24 @@ class attendance { |
|
|
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), |
|
|
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), |
|
|
$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(); |
|
|
$info_array = array(); |
|
|
$maxlog = 7; // Only log first 10 sessions and last session in the log info. as we can only store 255 chars. |
|
|
$info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration); |
|
|
$i = 0; |
|
|
|
|
|
foreach ($sessions as $sess) { |
|
|
|
|
|
if ($i > $maxlog) { |
|
|
|
|
|
$lastsession = end($sessions); |
|
|
|
|
|
$info_array[] = '...'; |
|
|
|
|
|
$info_array[] = construct_session_full_date_time($lastsession->sessdate, $lastsession->duration); |
|
|
|
|
|
break; |
|
|
|
|
|
} else { |
|
|
|
|
|
$info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration); |
|
|
|
|
|
} |
|
|
|
|
|
$i++; |
|
|
|
|
|
} |
|
|
|
|
|
// Trigger a report viewed event. |
|
|
|
|
|
$event = \mod_attendance\event\session_added::create(array( |
|
|
|
|
|
'objectid' => $this->id, |
|
|
|
|
|
'context' => $this->context, |
|
|
|
|
|
'other' => array('info' => implode(',', $info_array)) |
|
|
|
|
|
)); |
|
|
|
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
|
|
|
$event->add_record_snapshot('attendance', $this); |
|
|
|
|
|
$event->trigger(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Trigger a session added event. |
|
|
|
|
|
$event = \mod_attendance\event\session_added::create(array( |
|
|
|
|
|
'objectid' => $this->id, |
|
|
|
|
|
'context' => $this->context, |
|
|
|
|
|
'other' => array('info' => implode(',', $info_array)) |
|
|
|
|
|
)); |
|
|
|
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
|
|
|
$sess->description = $description; |
|
|
|
|
|
$sess->lasttaken = 0; |
|
|
|
|
|
$sess->lasttakenby = 0; |
|
|
|
|
|
$sess->studentscanmark = 0; |
|
|
|
|
|
$event->add_record_snapshot('attendance_sessions', $sess); |
|
|
|
|
|
$event->trigger(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function update_session_from_form_data($formdata, $sessionid) { |
|
|
public function update_session_from_form_data($formdata, $sessionid) { |
|
@ -846,7 +838,7 @@ class attendance { |
|
|
'context' => $this->context, |
|
|
'context' => $this->context, |
|
|
'other' => array('info' => $info, 'sessionid' => $sessionid, 'action' => att_sessions_page_params::ACTION_UPDATE))); |
|
|
'other' => array('info' => $info, 'sessionid' => $sessionid, 'action' => att_sessions_page_params::ACTION_UPDATE))); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('attendance', $this); |
|
|
$event->add_record_snapshot('attendance_sessions', $sess); |
|
|
$event->trigger(); |
|
|
$event->trigger(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -883,11 +875,10 @@ class attendance { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Update the session to show that a register has been taken, or staff may overwrite records. |
|
|
// Update the session to show that a register has been taken, or staff may overwrite records. |
|
|
$rec = new object(); |
|
|
$session = $this->get_session_info($mformdata->sessid); |
|
|
$rec->id = $mformdata->sessid; |
|
|
$session->lasttaken = $now; |
|
|
$rec->lasttaken = $now; |
|
|
$session->lasttakenby = $USER->id; |
|
|
$rec->lasttakenby = $USER->id; |
|
|
$DB->update_record('attendance_sessions', $session); |
|
|
$DB->update_record('attendance_sessions', $rec); |
|
|
|
|
|
|
|
|
|
|
|
// Update the users grade. |
|
|
// Update the users grade. |
|
|
$this->update_users_grade(array($USER->id)); |
|
|
$this->update_users_grade(array($USER->id)); |
|
@ -895,18 +886,19 @@ class attendance { |
|
|
/* create url for link in log screen |
|
|
/* create url for link in log screen |
|
|
* need to set grouptype to 0 to allow take attendance page to be called |
|
|
* need to set grouptype to 0 to allow take attendance page to be called |
|
|
* from report/log page */ |
|
|
* from report/log page */ |
|
|
|
|
|
|
|
|
$params = array( |
|
|
$params = array( |
|
|
'sessionid' => $this->pageparams->sessionid, |
|
|
'sessionid' => $this->pageparams->sessionid, |
|
|
'grouptype' => 0); |
|
|
'grouptype' => 0); |
|
|
|
|
|
|
|
|
// Log the change. |
|
|
// Log the change. |
|
|
$event = \mod_attendance\event\attendance_taken_by_student::create(array( |
|
|
$event = \mod_attendance\event\attendance_taken_by_student::create(array( |
|
|
'objectid' => $this->id, |
|
|
'objectid' => $this->id, |
|
|
'context' => $this->context, |
|
|
'context' => $this->context, |
|
|
'other' => $params)); |
|
|
'other' => $params)); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('attendance', $this); |
|
|
$event->add_record_snapshot('attendance_sessions', $session); |
|
|
|
|
|
$event->add_record_snapshot('attendance_log', $record); |
|
|
$event->trigger(); |
|
|
$event->trigger(); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
@ -949,11 +941,10 @@ class attendance { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$rec = new stdClass(); |
|
|
$session = $this->get_session_info($this->pageparams->sessionid); |
|
|
$rec->id = $this->pageparams->sessionid; |
|
|
$session->lasttaken = $now; |
|
|
$rec->lasttaken = $now; |
|
|
$session->lasttakenby = $USER->id; |
|
|
$rec->lasttakenby = $USER->id; |
|
|
$DB->update_record('attendance_sessions', $session); |
|
|
$DB->update_record('attendance_sessions', $rec); |
|
|
|
|
|
|
|
|
|
|
|
if ($this->grade != 0) { |
|
|
if ($this->grade != 0) { |
|
|
$this->update_users_grade(array_keys($sesslog)); |
|
|
$this->update_users_grade(array_keys($sesslog)); |
|
@ -968,7 +959,7 @@ class attendance { |
|
|
'context' => $this->context, |
|
|
'context' => $this->context, |
|
|
'other' => $params)); |
|
|
'other' => $params)); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('attendance', $this); |
|
|
$event->add_record_snapshot('attendance_sessions', $session); |
|
|
$event->trigger(); |
|
|
$event->trigger(); |
|
|
|
|
|
|
|
|
$group = 0; |
|
|
$group = 0; |
|
@ -1403,7 +1394,6 @@ class attendance { |
|
|
'context' => $this->context, |
|
|
'context' => $this->context, |
|
|
'other' => array('info' => implode(', ', $sessionsids)))); |
|
|
'other' => array('info' => implode(', ', $sessionsids)))); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('attendance', $this); |
|
|
|
|
|
$event->trigger(); |
|
|
$event->trigger(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1416,23 +1406,47 @@ class attendance { |
|
|
$sess->duration = $duration; |
|
|
$sess->duration = $duration; |
|
|
$sess->timemodified = $now; |
|
|
$sess->timemodified = $now; |
|
|
$DB->update_record('attendance_sessions', $sess); |
|
|
$DB->update_record('attendance_sessions', $sess); |
|
|
|
|
|
$event = \mod_attendance\event\session_duration_updated::create(array( |
|
|
|
|
|
'objectid' => $this->id, |
|
|
|
|
|
'context' => $this->context, |
|
|
|
|
|
'other' => array('info' => implode(', ', $sessionsids)))); |
|
|
|
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
|
|
|
$event->add_record_snapshot('attendance_sessions', $sess); |
|
|
|
|
|
$event->trigger(); |
|
|
} |
|
|
} |
|
|
$sessions->close(); |
|
|
$sessions->close(); |
|
|
$event = \mod_attendance\event\session_duration_updated::create(array( |
|
|
|
|
|
'objectid' => $this->id, |
|
|
|
|
|
'context' => $this->context, |
|
|
|
|
|
'other' => array('info' => implode(', ', $sessionsids)))); |
|
|
|
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
|
|
|
$event->add_record_snapshot('attendance', $this); |
|
|
|
|
|
$event->trigger(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function remove_status($statusid) { |
|
|
/** |
|
|
|
|
|
* Remove a status variable from an attendance instance |
|
|
|
|
|
* |
|
|
|
|
|
* @global moodle_database $DB |
|
|
|
|
|
* @param stdClass $status |
|
|
|
|
|
*/ |
|
|
|
|
|
public function remove_status($status) { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
|
$DB->set_field('attendance_statuses', 'deleted', 1, array('id' => $statusid)); |
|
|
$DB->set_field('attendance_statuses', 'deleted', 1, array('id' => $status->id)); |
|
|
|
|
|
$event = \mod_attendance\event\status_removed::create(array( |
|
|
|
|
|
'objectid' => $status->id, |
|
|
|
|
|
'context' => $this->context, |
|
|
|
|
|
'other' => array( |
|
|
|
|
|
'acronym' => $status->acronym, |
|
|
|
|
|
'description' => $status->description |
|
|
|
|
|
))); |
|
|
|
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
|
|
|
$event->add_record_snapshot('attendance_statuses', $status); |
|
|
|
|
|
$event->trigger(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Add an attendance status variable |
|
|
|
|
|
* |
|
|
|
|
|
* @global moodle_database $DB |
|
|
|
|
|
* @param string $acronym |
|
|
|
|
|
* @param string $description |
|
|
|
|
|
* @param int $grade |
|
|
|
|
|
*/ |
|
|
public function add_status($acronym, $description, $grade) { |
|
|
public function add_status($acronym, $description, $grade) { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
@ -1443,27 +1457,38 @@ class attendance { |
|
|
$rec->acronym = $acronym; |
|
|
$rec->acronym = $acronym; |
|
|
$rec->description = $description; |
|
|
$rec->description = $description; |
|
|
$rec->grade = $grade; |
|
|
$rec->grade = $grade; |
|
|
$DB->insert_record('attendance_statuses', $rec); |
|
|
$rec->deleted = 0; |
|
|
|
|
|
$rec->visible = 1; |
|
|
|
|
|
$id = $DB->insert_record('attendance_statuses', $rec); |
|
|
|
|
|
$rec->id = $id; |
|
|
|
|
|
|
|
|
$event = \mod_attendance\event\status_added::create(array( |
|
|
$event = \mod_attendance\event\status_added::create(array( |
|
|
'objectid' => $this->id, |
|
|
'objectid' => $this->id, |
|
|
'context' => $this->context, |
|
|
'context' => $this->context, |
|
|
'other' => array('acronym' => $acronym, 'description' => $description, 'grade' => $grade))); |
|
|
'other' => array('acronym' => $acronym, 'description' => $description, 'grade' => $grade))); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('course_modules', $this->cm); |
|
|
$event->add_record_snapshot('attendance', $this); |
|
|
$event->add_record_snapshot('attendance_statuses', $rec); |
|
|
$event->trigger(); |
|
|
$event->trigger(); |
|
|
} else { |
|
|
} else { |
|
|
print_error('cantaddstatus', 'attendance', $this->url_preferences()); |
|
|
print_error('cantaddstatus', 'attendance', $this->url_preferences()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function update_status($statusid, $acronym, $description, $grade, $visible) { |
|
|
/** |
|
|
|
|
|
* Update status variable for a particular Attendance module instance |
|
|
|
|
|
* |
|
|
|
|
|
* @global moodle_database $DB |
|
|
|
|
|
* @param stdClass $status |
|
|
|
|
|
* @param string $acronym |
|
|
|
|
|
* @param string $description |
|
|
|
|
|
* @param int $grade |
|
|
|
|
|
* @param bool $visible |
|
|
|
|
|
*/ |
|
|
|
|
|
public function update_status($status, $acronym, $description, $grade, $visible) { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
|
$updated = array(); |
|
|
$updated = array(); |
|
|
|
|
|
|
|
|
$status = new stdClass(); |
|
|
|
|
|
$status->id = $statusid; |
|
|
|
|
|
if ($acronym) { |
|
|
if ($acronym) { |
|
|
$status->acronym = $acronym; |
|
|
$status->acronym = $acronym; |
|
|
$updated[] = $acronym; |
|
|
$updated[] = $acronym; |
|
@ -1487,10 +1512,10 @@ class attendance { |
|
|
'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', $this); |
|
|
$event->add_record_snapshot('attendance_statuses', $status); |
|
|
$event->trigger(); |
|
|
$event->trigger(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function att_get_statuses($attid, $onlyvisible=true) { |
|
|
function att_get_statuses($attid, $onlyvisible=true) { |
|
|