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) {
// 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;
}

2
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';

Loading…
Cancel
Save