From 98226d55afea2ff81ff678e3624767bd870c6409 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Fri, 2 Jul 2021 20:39:41 +1200 Subject: [PATCH] Fix #530 - tidy up existing session check. --- classes/import/sessions.php | 20 +++++++++----------- lang/en/attendance.php | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/classes/import/sessions.php b/classes/import/sessions.php index 5b13b61..4ea8cff 100644 --- a/classes/import/sessions.php +++ b/classes/import/sessions.php @@ -457,10 +457,11 @@ class sessions { foreach ($sessions as $index => $sess) { // 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( 'course' => $session->course, - 'activity' => $cm->name + 'activity' => $cm->name, + 'date' => construct_session_full_date_time($sess->sessdate, $sess->duration) )))); unset($sessions[$index]); } else { @@ -504,19 +505,16 @@ class sessions { * Check if an identical session exists. * * @param stdClass $session + * @param int $attid * @return boolean */ - private function session_exists(stdClass $session) { + private function session_exists(stdClass $session, $attid) { global $DB; - $check = clone $session; - - // Remove the properties that aren't useful to check. - unset($check->description); - unset($check->descriptionitemid); - unset($check->timemodified); - $check = (array) $check; - + $check = ['attendanceid' => $attid, + 'sessdate' => $session->sessdate, + 'duration' => $session->duration, + 'groupid' => $session->groupid]; if ($DB->record_exists('attendance_sessions', $check)) { return true; } diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 80debd0..df0b275 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -487,7 +487,7 @@ $string['sessionalreadyexists'] = 'Session already exists for this date'; $string['sessiondate'] = 'Date'; $string['sessiondays'] = 'Session Days'; $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['sessiongenerated'] = 'One session was successfully generated'; $string['sessions'] = 'Sessions';