From fa4bf5a425446a9ce8fad976e012348c192a75b3 Mon Sep 17 00:00:00 2001 From: Bernhard Fischer Date: Thu, 11 Apr 2024 13:25:28 +0200 Subject: [PATCH] Improvement: Separate string params from placeholder param {changes}. --- classes/message_controller.php | 36 ++++++++++++++-------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/classes/message_controller.php b/classes/message_controller.php index 480b273cd..3e4a14690 100644 --- a/classes/message_controller.php +++ b/classes/message_controller.php @@ -97,6 +97,9 @@ class message_controller { /** @var stdClass $params email params */ private $params; + /** @var stdClass $params for strings */ + private $stringparams; + /** @var string $customsubject for custom messages */ private $customsubject; @@ -170,6 +173,7 @@ public function __construct(int $msgcontrparam, int $messageparam, int $cmid, in $this->userid = $userid; $this->optiondateid = $optiondateid; $this->changes = $changes; + $this->params = new stdClass(); // For custom messages only. if ($this->messageparam == MOD_BOOKING_MSGPARAM_CUSTOM_MESSAGE) { @@ -191,14 +195,14 @@ public function __construct(int $msgcontrparam, int $messageparam, int $cmid, in } // We need these for some strings! - $this->params = new stdClass(); - $this->params->title = $settings->get_title_with_prefix(); - $this->params->participant = $this->user->firstname . " " . $this->user->lastname; + $this->stringparams = new stdClass(); + $this->stringparams->title = $settings->get_title_with_prefix(); + $this->stringparams->participant = $this->user->firstname . " " . $this->user->lastname; // Param sessiondescription is only needed for session reminders. // It's used as string param {$a->sessionreminder} in the default message string 'sessionremindermailmessage'. if ($this->messageparam == MOD_BOOKING_MSGPARAM_SESSIONREMINDER) { // Rendered session description. - $this->params->sessiondescription = get_rendered_eventdescription( + $this->stringparams->sessiondescription = get_rendered_eventdescription( $this->optionid, $this->cmid, MOD_BOOKING_DESCRIPTION_CALENDAR); } @@ -266,11 +270,11 @@ private function get_email_body(): string { $text = $this->bookingsettings->{$this->messagefieldname}; } else { // Use default message if none is specified. - $text = get_string($this->messagefieldname . 'message', 'booking', $this->params); + $text = get_string($this->messagefieldname . 'message', 'booking', $this->stringparams); } - // Replace ADDITIONAL placeholders which have been defined here in message_controller. - // TODO: We will have to migrate these additional placeholders to the new placeholders in a future release. + // NOTE: The only param that has not yet been migrated is {changes}. + // So we still have to keep this. foreach ($this->params as $name => $value) { if (!is_null($value)) { // Since php 8.1. $value = strval($value); @@ -278,7 +282,7 @@ private function get_email_body(): string { } } - // Only now, we apply the default placeholders. + // We apply the default placeholders. $text = placeholders_info::render_text($text, $this->optionsettings->cmid, $this->optionid, $this->userid, $this->descriptionparam ?? MOD_BOOKING_DESCRIPTION_WEBSITE); @@ -309,7 +313,7 @@ private function get_message_data_send_now(): message { $messagedata->subject = $this->customsubject; } else { // Else use the localized lang string for the correspondent message type. - $messagedata->subject = get_string($this->messagefieldname . 'subject', 'booking', $this->params); + $messagedata->subject = get_string($this->messagefieldname . 'subject', 'booking', $this->stringparams); } $messagedata->fullmessage = strip_tags(preg_replace('##i', "\n", $this->messagebody)); @@ -347,7 +351,7 @@ private function get_message_data_queue_adhoc(): stdClass { $messagedata->subject = $this->customsubject; } else { // Else use the localized lang string for the correspondent message type. - $messagedata->subject = get_string($this->messagefieldname . 'subject', 'booking', $this->params); + $messagedata->subject = get_string($this->messagefieldname . 'subject', 'booking', $this->stringparams); } $messagedata->messagetext = format_text_email($this->messagebody, FORMAT_HTML); @@ -458,7 +462,7 @@ private function send_mail_with_adhoc_task() { if ($this->messageparam == MOD_BOOKING_MSGPARAM_CONFIRMATION || $this->messageparam == MOD_BOOKING_MSGPARAM_WAITINGLIST) { $this->messagedata->subject = get_string($this->messagefieldname . 'subjectbookingmanager', - 'mod_booking', $this->params); + 'mod_booking', $this->stringparams); } $sendtask = new send_confirmation_mails(); @@ -512,16 +516,6 @@ public function get_messagebody(): string { } - /** - * Public getter function for the email params. - * @return stdClass email params - */ - public function get_params(): stdClass { - - return $this->params; - - } - /** * Helper function to get the fieldname for the message type. * @return string the field name