Render emails with the framework

This commit is contained in:
Alex Tselegidis 2020-12-02 22:08:49 +02:00
parent 1571a01f1d
commit d465e05652
2 changed files with 49 additions and 62 deletions

View File

@ -19,15 +19,14 @@
*/ */
function render_timezone_dropdown($attributes = '') function render_timezone_dropdown($attributes = '')
{ {
$framework = get_instance(); $CI = get_instance();
$framework->load->library('timezones'); $CI->load->library('timezones');
$timezones = $framework->timezones->to_grouped_array(); $timezones = $CI->timezones->to_grouped_array();
ob_start(); return $CI->load->view('partial/timezone_dropdown', [
'timezones' => $timezones,
require __DIR__ . '/../views/partial/timezone_dropdown.php'; 'attributes' => $attributes
], TRUE);
return ob_get_clean();
} }

View File

@ -138,25 +138,22 @@ class Email {
$appointment_end->setTimezone($appointment_timezone); $appointment_end->setTimezone($appointment_timezone);
} }
// Prepare template replace array. $html = $this->framework->load->view('emails/appointment_details', [
$email_title = $title->get(); 'email_title' => $title->get(),
$email_message = $message->get(); 'email_message' => $message->get(),
$appointment_service = $service['name']; 'appointment_service' => $service['name'],
$appointment_provider = $provider['first_name'] . ' ' . $provider['last_name']; 'appointment_provider' => $provider['first_name'] . ' ' . $provider['last_name'],
$appointment_start_date = $appointment_start->format($date_format . ' ' . $time_format); 'appointment_start_date' => $appointment_start->format($date_format . ' ' . $time_format),
$appointment_end_date = $appointment_end->format($date_format . ' ' . $time_format); 'appointment_end_date' => $appointment_end->format($date_format . ' ' . $time_format),
$appointment_timezone = $timezones[empty($timezone) ? $provider['timezone'] : $timezone]; 'appointment_timezone' => $timezones[empty($timezone) ? $provider['timezone'] : $timezone],
$appointment_link = $appointment_link_address->get(); 'appointment_link' => $appointment_link_address->get(),
$company_link = $settings['company_link']; 'company_link' => $settings['company_link'],
$company_name = $settings['company_name']; 'company_name' => $settings['company_name'],
$customer_name = $customer['first_name'] . ' ' . $customer['last_name']; 'customer_name' => $customer['first_name'] . ' ' . $customer['last_name'],
$customer_email = $customer['email']; 'customer_email' => $customer['email'],
$customer_phone = $customer['phone_number']; 'customer_phone' => $customer['phone_number'],
$customer_address = $customer['address']; 'customer_address' => $customer['address'],
], TRUE);
ob_start();
require __DIR__ . '/../../application/views/emails/appointment_details.php';
$html = ob_get_clean();
$mailer = $this->create_mailer(); $mailer = $this->create_mailer();
$mailer->From = $settings['company_email']; $mailer->From = $settings['company_email'];
@ -205,10 +202,7 @@ class Email {
$timezone = NULL $timezone = NULL
) )
{ {
$framework = get_instance(); $timezones = $this->framework->timezones->to_array();
$timezones = $framework->timezones->to_array();
switch ($settings['date_format']) switch ($settings['date_format'])
{ {
@ -246,23 +240,20 @@ class Email {
$appointment_start->setTimezone($appointment_timezone); $appointment_start->setTimezone($appointment_timezone);
} }
// Prepare email template data. $html = $this->framework->load->view('emails/delete_appointment', [
$appointment_service = $service['name']; 'appointment_service' => $service['name'],
$appointment_provider = $provider['first_name'] . ' ' . $provider['last_name']; 'appointment_provider' => $provider['first_name'] . ' ' . $provider['last_name'],
$appointment_date = $appointment_start->format($date_format . ' ' . $time_format); 'appointment_date' => $appointment_start->format($date_format . ' ' . $time_format),
$appointment_duration = $service['duration'] . ' ' . $this->framework->lang->line('minutes'); 'appointment_duration' => $service['duration'] . ' ' . $this->framework->lang->line('minutes'),
$appointment_timezone = $timezones[empty($timezone) ? $provider['timezone'] : $timezone]; 'appointment_timezone' => $timezones[empty($timezone) ? $provider['timezone'] : $timezone],
$company_link = $settings['company_link']; 'company_link' => $settings['company_link'],
$company_name = $settings['company_name']; 'company_name' => $settings['company_name'],
$customer_name = $customer['first_name'] . ' ' . $customer['last_name']; 'customer_name' => $customer['first_name'] . ' ' . $customer['last_name'],
$customer_email = $customer['email']; 'customer_email' => $customer['email'],
$customer_phone = $customer['phone_number']; 'customer_phone' => $customer['phone_number'],
$customer_address = $customer['address']; 'customer_address' => $customer['address'],
$reason = $reason->get(); 'reason' => $reason->get(),
], TRUE);
ob_start();
require __DIR__ . '/../../application/views/emails/delete_appointment.php';
$html = ob_get_clean();
$mailer = $this->create_mailer(); $mailer = $this->create_mailer();
@ -285,27 +276,24 @@ class Email {
* *
* @param \EA\Engine\Types\NonEmptyText $password Contains the new password. * @param \EA\Engine\Types\NonEmptyText $password Contains the new password.
* @param \EA\Engine\Types\Email $recipientEmail The receiver's email address. * @param \EA\Engine\Types\Email $recipientEmail The receiver's email address.
* @param array $company The company settings to be included in the email. * @param array $settings The company settings to be included in the email.
* *
* @throws \PHPMailer\PHPMailer\Exception * @throws \PHPMailer\PHPMailer\Exception
*/ */
public function send_password(NonEmptyText $password, EmailAddress $recipientEmail, array $company) public function send_password(NonEmptyText $password, EmailAddress $recipientEmail, array $settings)
{ {
$email_title = $this->framework->lang->line('new_account_password'); $html = $this->framework->load->view('emails/new_password', [
$password = '<strong>' . $password->get() . '</strong>'; 'email_title' => lang('new_account_password'),
$email_message = str_replace('$password', $password, $this->framework->lang->line('new_password_is')); 'email_message' => str_replace('$password', '<strong>' . $password->get() . '</strong>', lang('new_password_is')),
$company_name = $company['company_name']; 'company_name' => $settings['company_name'],
$company_email = $company['company_email']; 'company_email' => $settings['company_email'],
$company_link = $company['company_link']; 'company_link' => $settings['company_link'],
], TRUE);
ob_start();
require __DIR__ . '/../../application/views/emails/new_password.php';
$html = ob_get_clean();
$mailer = $this->create_mailer(); $mailer = $this->create_mailer();
$mailer->From = $company['company_email']; $mailer->From = $settings['company_email'];
$mailer->FromName = $company['company_name']; $mailer->FromName = $settings['company_name'];
$mailer->AddAddress($recipientEmail->get()); // "Name" argument crushes the phpmailer class. $mailer->AddAddress($recipientEmail->get()); // "Name" argument crushes the phpmailer class.
$mailer->Subject = $this->framework->lang->line('new_account_password'); $mailer->Subject = $this->framework->lang->line('new_account_password');
$mailer->Body = $html; $mailer->Body = $html;