Browse Source

Fix #530 - tidy up existing session check.

MOODLE_38_STABLE
Dan Marsden 4 years ago
parent
commit
00023ae1e7
  1. 20
      classes/import/sessions.php
  2. 2
      lang/en/attendance.php

20
classes/import/sessions.php

@ -457,10 +457,11 @@ class sessions {
foreach ($sessions as $index => $sess) { foreach ($sessions as $index => $sess) {
// Check for duplicate sessions. // Check for duplicate sessions.
if ($this->session_exists($sess)) { if ($this->session_exists($sess, $att->id)) {
mod_attendance_notifyqueue::notify_message(get_string('sessionduplicate', 'attendance', (array( mod_attendance_notifyqueue::notify_message(get_string('sessionduplicate', 'attendance', (array(
'course' => $session->course, 'course' => $session->course,
'activity' => $cm->name 'activity' => $cm->name,
'date' => construct_session_full_date_time($sess->sessdate, $sess->duration)
)))); ))));
unset($sessions[$index]); unset($sessions[$index]);
} else { } else {
@ -504,19 +505,16 @@ class sessions {
* Check if an identical session exists. * Check if an identical session exists.
* *
* @param stdClass $session * @param stdClass $session
* @param int $attid
* @return boolean * @return boolean
*/ */
private function session_exists(stdClass $session) { private function session_exists(stdClass $session, $attid) {
global $DB; global $DB;
$check = clone $session; $check = ['attendanceid' => $attid,
'sessdate' => $session->sessdate,
// Remove the properties that aren't useful to check. 'duration' => $session->duration,
unset($check->description); 'groupid' => $session->groupid];
unset($check->descriptionitemid);
unset($check->timemodified);
$check = (array) $check;
if ($DB->record_exists('attendance_sessions', $check)) { if ($DB->record_exists('attendance_sessions', $check)) {
return true; return true;
} }

2
lang/en/attendance.php

@ -487,7 +487,7 @@ $string['sessionalreadyexists'] = 'Session already exists for this date';
$string['sessiondate'] = 'Date'; $string['sessiondate'] = 'Date';
$string['sessiondays'] = 'Session Days'; $string['sessiondays'] = 'Session Days';
$string['sessiondeleted'] = 'Session successfully deleted'; $string['sessiondeleted'] = 'Session successfully deleted';
$string['sessionduplicate'] = 'A duplicate session exists for course: {$a->course} in attendance: {$a->activity}'; $string['sessionduplicate'] = 'A duplicate session exists for course: {$a->course} in attendance: {$a->activity}, {$a->date}';
$string['sessionexist'] = 'Session not added (already exists)!'; $string['sessionexist'] = 'Session not added (already exists)!';
$string['sessiongenerated'] = 'One session was successfully generated'; $string['sessiongenerated'] = 'One session was successfully generated';
$string['sessions'] = 'Sessions'; $string['sessions'] = 'Sessions';

Loading…
Cancel
Save