diff --git a/lib.php b/lib.php index ed41045..5f4e8ef 100644 --- a/lib.php +++ b/lib.php @@ -2238,6 +2238,10 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, } } + $substitute = function($text, $session) use ($facetoface, $user) { + return facetoface_email_substitutions($text, format_string($facetoface->name), $facetoface->reminderperiod, $user, $session, $session->id); + }; + // Do iCal attachement stuff. $icalattachments = []; if ($notificationtype & MDL_F2F_ICAL) { @@ -2249,28 +2253,11 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, $session->sessiondates = [$sessiondate]; // One day at a time. $filename = facetoface_get_ical_attachment($notificationtype, $facetoface, $session, $user); - $subject = facetoface_email_substitutions( - $postsubject, - format_string($facetoface->name), - $facetoface->reminderperiod, - $user, - $session, - $session->id - ); - $body = facetoface_email_substitutions($posttext, format_string($facetoface->name), $facetoface->reminderperiod, - $user, $session, $session->id); - $htmlmessage = facetoface_email_substitutions( - $posttext, - $facetoface->name, - $facetoface->reminderperiod, - $user, - $session, - $session->id - ); - $htmlbody = $htmlmessage; + $subject = $substitute($postsubject, $session); + $body = $substitute($posttext, $session); $icalattachments[] = [ 'filename' => $filename, 'subject' => $subject, - 'body' => $body, 'htmlbody' => $htmlbody, + 'body' => $body, ]; } @@ -2278,42 +2265,21 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, $session->sessiondates = $sessiondates; } else { $filename = facetoface_get_ical_attachment($notificationtype, $facetoface, $session, $user); - $subject = facetoface_email_substitutions($postsubject, format_string($facetoface->name), $facetoface->reminderperiod, - $user, $session, $session->id); - $body = facetoface_email_substitutions($posttext, format_string($facetoface->name), $facetoface->reminderperiod, - $user, $session, $session->id); - $htmlmessage = facetoface_email_substitutions( - $posttext, - $facetoface->name, - $facetoface->reminderperiod, - $user, - $session, - $session->id - ); - $htmlbody = $htmlmessage; + $subject = $substitute($postsubject, $session); + // TODO we need to format as html. + $body = $substitute($posttext, $session); $icalattachments[] = [ 'filename' => $filename, 'subject' => $subject, - 'body' => $body, 'htmlbody' => $htmlbody, + 'body' => $body, ]; } } // Fill-in the email placeholders. - $postsubject = facetoface_email_substitutions($postsubject, format_string($facetoface->name), $facetoface->reminderperiod, - $user, $session, $session->id); - $posttext = facetoface_email_substitutions($posttext, format_string($facetoface->name), $facetoface->reminderperiod, - $user, $session, $session->id); - - $posttextmgrheading = facetoface_email_substitutions( - $posttextmgrheading, - format_string($facetoface->name), - $facetoface->reminderperiod, - $user, - $session, - $session->id - ); + $postsubject = $substitute($postsubject, $session); + $posttext = $substitute($posttext, $session); + $posttextmgrheading = $substitute($posttextmgrheading, $session); - $posthtml = ''; // FIXME. if ($fromaddress = get_config('facetoface', 'fromaddress')) { $from = new stdClass(); $from->maildisplay = true; @@ -2326,7 +2292,7 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, if ($notificationtype & MDL_F2F_ICAL) { foreach ($icalattachments as $attachment) { if (!email_to_user($user, $from, $attachment['subject'], $attachment['body'], - $attachment['htmlbody'], $attachment['filename'], $attachmentfilename)) { + '', $attachment['filename'], $attachmentfilename)) { return 'error:cannotsendconfirmationuser'; } unlink($CFG->dataroot . '/' . $attachment['filename']); @@ -2335,7 +2301,7 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, // Send plain text email. if ($notificationtype & MDL_F2F_TEXT - && !email_to_user($user, $from, $postsubject, $posttext, $posthtml)) { + && !email_to_user($user, $from, $postsubject, $posttext)) { return 'error:cannotsendconfirmationuser'; } @@ -2347,7 +2313,7 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, $manager->email = $manageremail; // Leave out the ical attachments in the managers notification. - if (!email_to_user($manager, $from, $postsubject, $managertext, $posthtml)) { + if (!email_to_user($manager, $from, $postsubject, $managertext)) { return 'error:cannotsendconfirmationmanager'; } } @@ -2361,7 +2327,7 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, $thirdparty->email = trim($recipient); // Leave out the ical attachments in the 3rd parties notification. - if (!email_to_user($thirdparty, $from, $postsubject, $posttext, $posthtml)) { + if (!email_to_user($thirdparty, $from, $postsubject, $posttext)) { return 'error:cannotsendconfirmationthirdparty'; } } diff --git a/tests/session_test.php b/tests/session_test.php index 83ba463..f183d62 100644 --- a/tests/session_test.php +++ b/tests/session_test.php @@ -18,6 +18,10 @@ use core_date; +defined('MOODLE_INTERNAL') || die(); +global $CFG; +require_once("$CFG->dirroot/mod/facetoface/lib.php"); + /** * Test the session helper class. * @@ -112,4 +116,185 @@ public function test_get_readable_session_time_with_users_timezone() { $expectedstring = "1 January 2030, 9:00 AM - 4 January 2030, 5:00 PM (time zone: $expectedtimezone)"; $this->assertEquals($expectedstring, session::get_readable_session_datetime($date)); } + + public static function email_notification_provider(): array { + $htmlconfirmmessage = " +
This is the confirm message
+Details:
+ [details] + "; + + $htmldetails = " +This is a html message
+This is the confirm message
Details:
This is a html message