Improve the structure of the email notifications

This commit is contained in:
Alex Tselegidis 2023-02-21 07:58:21 +01:00
parent c3aca37591
commit 4d79e1d3cf
4 changed files with 96 additions and 165 deletions

View file

@ -53,7 +53,7 @@ class Email_messages {
* @param array $settings App settings. * @param array $settings App settings.
* @param string $subject Email subject. * @param string $subject Email subject.
* @param string $message Email message. * @param string $message Email message.
* @param string $appointment_link_address Appointment unique URL. * @param string $appointment_link Appointment unique URL.
* @param string $recipient_email Recipient email address. * @param string $recipient_email Recipient email address.
* @param string $ics_stream ICS file contents. * @param string $ics_stream ICS file contents.
* @param string|null $timezone Custom timezone. * @param string|null $timezone Custom timezone.
@ -68,41 +68,12 @@ class Email_messages {
array $settings, array $settings,
string $subject, string $subject,
string $message, string $message,
string $appointment_link_address, string $appointment_link,
string $recipient_email, string $recipient_email,
string $ics_stream, string $ics_stream,
string $timezone = NULL string $timezone = NULL
) ): void
{ {
$timezones = $this->CI->timezones->to_array();
switch ($settings['date_format'])
{
case 'DMY':
$date_format = 'd/m/Y';
break;
case 'MDY':
$date_format = 'm/d/Y';
break;
case 'YMD':
$date_format = 'Y/m/d';
break;
default:
throw new RuntimeException('Invalid date_format value: ' . $settings['date_format']);
}
switch ($settings['time_format'])
{
case 'military':
$time_format = 'H:i';
break;
case 'regular':
$time_format = 'g:i a';
break;
default:
throw new RuntimeException('Invalid time_format value: ' . $settings['time_format']);
}
$appointment_timezone = new DateTimeZone($provider['timezone']); $appointment_timezone = new DateTimeZone($provider['timezone']);
$appointment_start = new DateTime($appointment['start_datetime'], $appointment_timezone); $appointment_start = new DateTime($appointment['start_datetime'], $appointment_timezone);
@ -119,20 +90,15 @@ class Email_messages {
} }
$html = $this->CI->load->view('emails/appointment_saved_email', [ $html = $this->CI->load->view('emails/appointment_saved_email', [
'email_title' => $subject, 'subject' => $subject,
'email_message' => $message, 'message' => $message,
'appointment_service' => $service['name'], 'appointment' => $appointment,
'appointment_provider' => $provider['first_name'] . ' ' . $provider['last_name'], 'service' => $service,
'appointment_start_date' => $appointment_start->format($date_format . ' ' . $time_format), 'provider' => $provider,
'appointment_end_date' => $appointment_end->format($date_format . ' ' . $time_format), 'customer' => $customer,
'appointment_timezone' => $timezones[empty($timezone) ? $provider['timezone'] : $timezone], 'settings' => $settings,
'appointment_link' => $appointment_link_address, 'timezone' => $timezone,
'company_link' => $settings['company_link'], 'appointment_link' => $appointment_link,
'company_name' => $settings['company_name'],
'customer_name' => $customer['first_name'] . ' ' . $customer['last_name'],
'customer_email' => $customer['email'],
'customer_phone' => $customer['phone_number'],
'customer_address' => $customer['address'],
], TRUE); ], TRUE);
$this->CI->email->from($settings['company_email'], $settings['company_email']); $this->CI->email->from($settings['company_email'], $settings['company_email']);
@ -174,37 +140,8 @@ class Email_messages {
string $recipient_email, string $recipient_email,
string $reason = NULL, string $reason = NULL,
string $timezone = NULL string $timezone = NULL
) ): void
{ {
$timezones = $this->CI->timezones->to_array();
switch ($settings['date_format'])
{
case 'DMY':
$date_format = 'd/m/Y';
break;
case 'MDY':
$date_format = 'm/d/Y';
break;
case 'YMD':
$date_format = 'Y/m/d';
break;
default:
throw new InvalidArgumentException('Invalid date_format value: ' . $settings['date_format']);
}
switch ($settings['time_format'])
{
case 'military':
$time_format = 'H:i';
break;
case 'regular':
$time_format = 'g:i a';
break;
default:
throw new InvalidArgumentException('Invalid time_format value: ' . $settings['time_format']);
}
$appointment_timezone = new DateTimeZone($provider['timezone']); $appointment_timezone = new DateTimeZone($provider['timezone']);
$appointment_start = new DateTime($appointment['start_datetime'], $appointment_timezone); $appointment_start = new DateTime($appointment['start_datetime'], $appointment_timezone);
@ -217,17 +154,12 @@ class Email_messages {
} }
$html = $this->CI->load->view('emails/appointment_deleted_email', [ $html = $this->CI->load->view('emails/appointment_deleted_email', [
'appointment_service' => $service['name'], 'appointment' => $appointment,
'appointment_provider' => $provider['first_name'] . ' ' . $provider['last_name'], 'service' => $service,
'appointment_date' => $appointment_start->format($date_format . ' ' . $time_format), 'provider' => $provider,
'appointment_duration' => $service['duration'] . ' ' . lang('minutes'), 'customer' => $customer,
'appointment_timezone' => $timezones[empty($timezone) ? $provider['timezone'] : $timezone], 'settings' => $settings,
'company_link' => $settings['company_link'], 'timezone' => $timezone,
'company_name' => $settings['company_name'],
'customer_name' => $customer['first_name'] . ' ' . $customer['last_name'],
'customer_email' => $customer['email'],
'customer_phone' => $customer['phone_number'],
'customer_address' => $customer['address'],
'reason' => $reason, 'reason' => $reason,
], TRUE); ], TRUE);
@ -256,14 +188,12 @@ class Email_messages {
string $password, string $password,
string $recipient_email, string $recipient_email,
array $settings array $settings
) ): void
{ {
$html = $this->CI->load->view('emails/account_recovery_email', [ $html = $this->CI->load->view('emails/account_recovery_email', [
'email_title' => lang('new_account_password'), 'subject' => lang('new_account_password'),
'email_message' => str_replace('$password', '<strong>' . $password . '</strong>', lang('new_password_is')), 'message' => str_replace('$password', '<strong>' . $password . '</strong>', lang('new_password_is')),
'company_name' => $settings['company_name'], 'settings' => $settings,
'company_email' => $settings['company_email'],
'company_link' => $settings['company_link'],
], TRUE); ], TRUE);
$this->CI->email->from($settings['company_email'], $settings['company_email']); $this->CI->email->from($settings['company_email'], $settings['company_email']);

View file

@ -1,31 +1,31 @@
<?php <?php
/** /**
* Local variables. * Local variables.
* *
* @var string $company_name * @var string $subject
* @var string $email_title * @var string $message
* @var string $email_message * @var array $settings
* @var string $company_link
*/ */
?> ?>
<html lang="en"> <html lang="en">
<head> <head>
<title>New Password | Easy!Appointments</title> <title><?= $subject ?> | Easy!Appointments</title>
</head> </head>
<body style="font: 13px arial, helvetica, tahoma;"> <body style="font: 13px arial, helvetica, tahoma;">
<div class="email-container" style="width: 650px; border: 1px solid #eee;"> <div class="email-container" style="width: 650px; border: 1px solid #eee;">
<div id="header" style="background-color: #429a82; height: 45px; padding: 10px 15px;"> <div id="header" style="background-color: #429a82; height: 45px; padding: 10px 15px;">
<strong id="logo" style="color: white; font-size: 20px; margin-top: 10px; display: inline-block"> <strong id="logo" style="color: white; font-size: 20px; margin-top: 10px; display: inline-block">
<?= $company_name ?> <?= $settings['company_name'] ?>
</strong> </strong>
</div> </div>
<div id="content" style="padding: 10px 15px;"> <div id="content" style="padding: 10px 15px;">
<h2> <h2>
<?= $email_title ?> <?= $subject ?>
</h2> </h2>
<p> <p>
<?= $email_message ?> <?= $message ?>
</p> </p>
</div> </div>
@ -36,10 +36,11 @@
Easy!Appointments Easy!Appointments
</a> </a>
| |
<a href="<?= $company_link ?>" style="text-decoration: none;"> <a href="<?= $settings['company_link'] ?>" style="text-decoration: none;">
<?= $company_name ?> <?= $settings['company_name'] ?>
</a> </a>
</div> </div>
</div> </div>
</body> </body>
</html> </html>

View file

@ -1,18 +1,14 @@
<?php <?php
/** /**
* Local variables. * Local variables.
* *
* @var string $company_name * @var array $appointment
* @var string $appointment_service * @var array $service
* @var string $appointment_provider * @var array $provider
* @var string $appointment_duration * @var array $customer
* @var string $appointment_timezone * @var array $settings
* @var string $customer_name * @var array $timezone
* @var string $customer_email
* @var string $customer_phone
* @var string $customer_address
* @var string $reason * @var string $reason
* @var string $company_link
*/ */
?> ?>
@ -21,10 +17,11 @@
<title><?= lang('appointment_cancelled_title') ?> | Easy!Appointments</title> <title><?= lang('appointment_cancelled_title') ?> | Easy!Appointments</title>
</head> </head>
<body style="font: 13px arial, helvetica, tahoma;"> <body style="font: 13px arial, helvetica, tahoma;">
<div class="email-container" style="width: 650px; border: 1px solid #eee;"> <div class="email-container" style="width: 650px; border: 1px solid #eee;">
<div id="header" style="background-color: #429a82; height: 45px; padding: 10px 15px;"> <div id="header" style="background-color: #429a82; height: 45px; padding: 10px 15px;">
<strong id="logo" style="color: white; font-size: 20px; margin-top: 10px; display: inline-block"> <strong id="logo" style="color: white; font-size: 20px; margin-top: 10px; display: inline-block">
<?= $company_name ?> <?= $settings['company_name'] ?>
</strong> </strong>
</div> </div>
@ -40,14 +37,14 @@
<h2> <h2>
<?= lang('appointment_details_title') ?> <?= lang('appointment_details_title') ?>
</h2> </h2>
<table id="appointment-details"> <table id="appointment-details">
<tr> <tr>
<td class="label" style="padding: 3px;font-weight: bold;"> <td class="label" style="padding: 3px;font-weight: bold;">
<?= lang('service') ?> <?= lang('service') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_service ?> <?= $service['name'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -55,7 +52,7 @@
<?= lang('provider') ?> <?= lang('provider') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_provider ?> <?= $provider['first_name'] . ' ' . $provider['last_name'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -63,15 +60,16 @@
<?= lang('start') ?> <?= lang('start') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_date ?> <?= format_date_time($appointment['start_datetime']) ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="label" style="padding: 3px;font-weight: bold;"> <td class="label" style="padding: 3px;font-weight: bold;">
<?= lang('duration') ?> <?= lang('end') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_duration ?> <?= format_date_time($appointment['end_datetime']) ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -79,19 +77,22 @@
<?= lang('timezone') ?> <?= lang('timezone') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_timezone ?> <?= format_timezone($timezone) ?>
</td> </td>
</tr> </tr>
</table> </table>
<h2><?= lang('customer_details_title') ?></h2> <h2>
<?= lang('customer_details_title') ?>
</h2>
<table id="customer-details"> <table id="customer-details">
<tr> <tr>
<td class="label" style="padding: 3px;font-weight: bold;"> <td class="label" style="padding: 3px;font-weight: bold;">
<?= lang('name') ?> <?= lang('name') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $customer_name ?> <?= $customer['first_name'] . ' ' . $customer['last_name'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -99,7 +100,7 @@
<?= lang('email') ?> <?= lang('email') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $customer_email ?> <?= $customer['email'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -107,7 +108,7 @@
<?= lang('phone_number') ?> <?= lang('phone_number') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $customer_phone ?> <?= $customer['phone_number'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -115,7 +116,7 @@
<?= lang('address') ?> <?= lang('address') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $customer_address ?> <?= $customer['address'] ?>
</td> </td>
</tr> </tr>
</table> </table>
@ -136,10 +137,11 @@
Easy!Appointments Easy!Appointments
</a> </a>
| |
<a href="<?= $company_link ?>" style="text-decoration: none;"> <a href="<?= $settings['company_link'] ?>" style="text-decoration: none;">
<?= $company_name ?> <?= $settings['company_name'] ?>
</a> </a>
</div> </div>
</div> </div>
</body> </body>
</html> </html>

View file

@ -1,56 +1,54 @@
<?php <?php
/** /**
* Local variables. * Local variables.
* *
* @var string $company_name * @var string $subject
* @var string $email_title * @var string $message
* @var string $email_message * @var array $appointment
* @var array $appointment_service * @var array $service
* @var string $appointment_provider * @var array $provider
* @var string $appointment_start_date * @var array $customer
* @var string $appointment_end_date * @var array $settings
* @var string $appointment_timezone * @var array $timezone
* @var string $customer_name
* @var string $customer_email
* @var string $customer_phone
* @var string $customer_address
* @var string $appointment_link * @var string $appointment_link
* @var string $company_link
*/ */
?> ?>
<html lang="en"> <html lang="en">
<head> <head>
<title><?= lang('appointment_details_title') ?> | Easy!Appointments</title> <title>
<?= lang('appointment_details_title') ?> | Easy!Appointments
</title>
</head> </head>
<body style="font: 13px arial, helvetica, tahoma;"> <body style="font: 13px arial, helvetica, tahoma;">
<div class="email-container" style="width: 650px; border: 1px solid #eee;"> <div class="email-container" style="width: 650px; border: 1px solid #eee;">
<div id="header" style="background-color: #429a82; height: 45px; padding: 10px 15px;"> <div id="header" style="background-color: #429a82; height: 45px; padding: 10px 15px;">
<strong id="logo" style="color: white; font-size: 20px; margin-top: 10px; display: inline-block"> <strong id="logo" style="color: white; font-size: 20px; margin-top: 10px; display: inline-block">
<?= $company_name ?> <?= $settings['company_name'] ?>
</strong> </strong>
</div> </div>
<div id="content" style="padding: 10px 15px;"> <div id="content" style="padding: 10px 15px;">
<h2> <h2>
<?= $email_title ?> <?= $subject ?>
</h2> </h2>
<p> <p>
<?= $email_message ?> <?= $message ?>
</p> </p>
<h2> <h2>
<?= lang('appointment_details_title') ?> <?= lang('appointment_details_title') ?>
</h2> </h2>
<table id="appointment-details"> <table id="appointment-details">
<tr> <tr>
<td class="label" style="padding: 3px;font-weight: bold;"> <td class="label" style="padding: 3px;font-weight: bold;">
<?= lang('service') ?> <?= lang('service') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_service ?> <?= $service['name'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -58,8 +56,7 @@
<?= lang('provider') ?> <?= lang('provider') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_provider ?> <?= $provider['first_name'] . ' ' . $provider['last_name'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -67,7 +64,7 @@
<?= lang('start') ?> <?= lang('start') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_start_date ?> <?= format_date_time($appointment['start_datetime']) ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -75,8 +72,8 @@
<?= lang('end') ?> <?= lang('end') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_end_date ?> <?= format_date_time($appointment['end_datetime']) ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -84,7 +81,7 @@
<?= lang('timezone') ?> <?= lang('timezone') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $appointment_timezone ?> <?= format_timezone($timezone) ?>
</td> </td>
</tr> </tr>
</table> </table>
@ -92,14 +89,14 @@
<h2> <h2>
<?= lang('customer_details_title') ?> <?= lang('customer_details_title') ?>
</h2> </h2>
<table id="customer-details"> <table id="customer-details">
<tr> <tr>
<td class="label" style="padding: 3px;font-weight: bold;"> <td class="label" style="padding: 3px;font-weight: bold;">
<?= lang('name') ?> <?= lang('name') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $customer_name ?> <?= $customer['first_name'] . ' ' . $customer['last_name'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -107,7 +104,7 @@
<?= lang('email') ?> <?= lang('email') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $customer_email ?> <?= $customer['email'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -115,7 +112,7 @@
<?= lang('phone_number') ?> <?= lang('phone_number') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $customer_phone ?> <?= $customer['phone_number'] ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -123,7 +120,7 @@
<?= lang('address') ?> <?= lang('address') ?>
</td> </td>
<td style="padding: 3px;"> <td style="padding: 3px;">
<?= $customer_address ?> <?= $customer['address'] ?>
</td> </td>
</tr> </tr>
</table> </table>
@ -131,7 +128,7 @@
<h2> <h2>
<?= lang('appointment_link_title') ?> <?= lang('appointment_link_title') ?>
</h2> </h2>
<a href="<?= $appointment_link ?>" style="width: 600px;"> <a href="<?= $appointment_link ?>" style="width: 600px;">
<?= $appointment_link ?> <?= $appointment_link ?>
</a> </a>
@ -144,10 +141,11 @@
Easy!Appointments Easy!Appointments
</a> </a>
| |
<a href="<?= $company_link ?>" style="text-decoration: none;"> <a href="<?= $settings['company_link'] ?>" style="text-decoration: none;">
<?= $company_name ?> <?= $settings['company_name'] ?>
</a> </a>
</div> </div>
</div> </div>
</body> </body>
</html> </html>