Replaced the old engine class use with the new Email_messages library

This commit is contained in:
Alex Tselegidis 2021-11-06 16:11:55 +01:00
parent 130adf88c3
commit 245fc43ec1
2 changed files with 54 additions and 55 deletions

View File

@ -96,14 +96,14 @@ class User extends EA_Controller {
if (empty($username)) if (empty($username))
{ {
throw new InvalidArgumentException('Empty username provided.'); throw new InvalidArgumentException('No username value provided.');
} }
$password = request('password'); $password = request('password');
if (empty($password)) if (empty($password))
{ {
throw new InvalidArgumentException('Empty password provided.'); throw new InvalidArgumentException('No password value provided.');
} }
$user_data = $this->accounts->check_login($username, $password); $user_data = $this->accounts->check_login($username, $password);
@ -153,15 +153,13 @@ class User extends EA_Controller {
if ($new_password) if ($new_password)
{ {
$email = new EmailClient($this, $this->config->config);
$settings = [ $settings = [
'company_name' => setting('company_name'), 'company_name' => setting('company_name'),
'company_link' => setting('company_link'), 'company_link' => setting('company_link'),
'company_email' => setting('company_email') 'company_email' => setting('company_email')
]; ];
$email->send_password(new NonEmptyText($new_password), new Email(request('email')), $settings); $this->email_messages->send_password($new_password, $email, $settings);
} }
json_response([ json_response([

View File

@ -11,11 +11,6 @@
* @since v1.4.0 * @since v1.4.0
* ---------------------------------------------------------------------------- */ * ---------------------------------------------------------------------------- */
use EA\Engine\Notifications\Email as EmailClient;
use EA\Engine\Types\Email;
use EA\Engine\Types\Text;
use EA\Engine\Types\Url;
/** /**
* Notifications library * Notifications library
* *
@ -43,6 +38,7 @@ class Notifications {
$this->CI->load->model('secretaries_model'); $this->CI->load->model('secretaries_model');
$this->CI->load->model('settings_model'); $this->CI->load->model('settings_model');
$this->CI->load->library('email_messages');
$this->CI->load->library('ics_file'); $this->CI->load->library('ics_file');
$this->CI->load->library('timezones'); $this->CI->load->library('timezones');
} }
@ -61,25 +57,30 @@ class Notifications {
{ {
try try
{ {
$email = new EmailClient($this->CI, $this->CI->config->config);
if ($manage_mode) if ($manage_mode)
{ {
$customer_title = new Text(lang('appointment_changes_saved')); $customer_subject = lang('appointment_changes_saved');
$customer_message = new Text('');
$provider_title = new Text(lang('appointment_details_changed')); $customer_message = '';
$provider_message = new Text('');
$provider_subject = lang('appointment_details_changed');
$provider_message = '';
} }
else else
{ {
$customer_title = new Text(lang('appointment_booked')); $customer_subject = lang('appointment_booked');
$customer_message = new Text(lang('thank_you_for_appointment'));
$provider_title = new Text(lang('appointment_added_to_your_plan')); $customer_message = lang('thank_you_for_appointment');
$provider_message = new Text(lang('appointment_link_description'));
$provider_subject = lang('appointment_added_to_your_plan');
$provider_message = lang('appointment_link_description');
} }
$customer_link = new Url(site_url('appointments/index/' . $appointment['hash'])); $customer_link = site_url('appointments/index/' . $appointment['hash']);
$provider_link = new Url(site_url('backend/index/' . $appointment['hash']));
$provider_link = site_url('backend/index/' . $appointment['hash']);
$ics_stream = $this->CI->ics_file->get_stream($appointment, $service, $provider, $customer); $ics_stream = $this->CI->ics_file->get_stream($appointment, $service, $provider, $customer);
@ -91,17 +92,17 @@ class Notifications {
if ($send_customer === TRUE) if ($send_customer === TRUE)
{ {
$email->send_appointment_details( $this->CI->email_messages->send_appointment_details(
$appointment, $appointment,
$provider, $provider,
$service, $service,
$customer, $customer,
$settings, $settings,
$customer_title, $customer_subject,
$customer_message, $customer_message,
$customer_link, $customer_link,
new Email($customer['email']), $customer['email'],
new Text($ics_stream), $ics_stream,
$customer['timezone'] $customer['timezone']
); );
} }
@ -114,17 +115,17 @@ class Notifications {
if ($send_provider === TRUE) if ($send_provider === TRUE)
{ {
$email->send_appointment_details( $this->CI->email_messages->send_appointment_details(
$appointment, $appointment,
$provider, $provider,
$service, $service,
$customer, $customer,
$settings, $settings,
$provider_title, $provider_subject,
$provider_message, $provider_message,
$provider_link, $provider_link,
new Email($provider['email']), $provider['email'],
new Text($ics_stream), $ics_stream,
$provider['timezone'] $provider['timezone']
); );
} }
@ -139,17 +140,17 @@ class Notifications {
continue; continue;
} }
$email->send_appointment_details( $this->CI->email_messages->send_appointment_details(
$appointment, $appointment,
$provider, $provider,
$service, $service,
$customer, $customer,
$settings, $settings,
$provider_title, $provider_subject,
$provider_message, $provider_message,
$provider_link, $provider_link,
new Email($admin['email']), $admin['email'],
new Text($ics_stream), $ics_stream,
$admin['timezone'] $admin['timezone']
); );
} }
@ -169,17 +170,17 @@ class Notifications {
continue; continue;
} }
$email->send_appointment_details( $this->CI->email_messages->send_appointment_details(
$appointment, $appointment,
$provider, $provider,
$service, $service,
$customer, $customer,
$settings, $settings,
$provider_title, $provider_subject,
$provider_message, $provider_message,
$provider_link, $provider_link,
new Email($secretary['email']), $secretary['email'],
new Text($ics_stream), $ics_stream,
$secretary['timezone'] $secretary['timezone']
); );
} }
@ -204,8 +205,6 @@ class Notifications {
{ {
try try
{ {
$email = new EmailClient($this->CI, $this->CI->config->config);
$delete_reason = (string)request('delete_reason'); $delete_reason = (string)request('delete_reason');
if (empty($delete_reason)) if (empty($delete_reason))
@ -214,19 +213,21 @@ class Notifications {
} }
// Notify provider. // Notify provider.
$send_provider = filter_var($this->CI->providers_model->get_setting('notifications', $provider['id']), $send_provider = filter_var(
FILTER_VALIDATE_BOOLEAN); $this->CI->providers_model->get_setting($provider['id'], 'notifications'),
FILTER_VALIDATE_BOOLEAN
);
if ($send_provider === TRUE) if ($send_provider === TRUE)
{ {
$email->send_delete_appointment( $this->CI->email_messages->send_delete_appointment(
$appointment, $appointment,
$provider, $provider,
$service, $service,
$customer, $customer,
$settings, $settings,
new Email($provider['email']), $provider['email'],
new Text($delete_reason) $delete_reason
); );
} }
@ -238,14 +239,14 @@ class Notifications {
if ($send_customer === TRUE) if ($send_customer === TRUE)
{ {
$email->send_delete_appointment( $this->CI->email_messages->send_delete_appointment(
$appointment, $appointment,
$provider, $provider,
$service, $service,
$customer, $customer,
$settings, $settings,
new Email($customer['email']), $customer['email'],
new Text($delete_reason) $delete_reason
); );
} }
@ -259,14 +260,14 @@ class Notifications {
continue; continue;
} }
$email->send_delete_appointment( $this->CI->email_messages->send_delete_appointment(
$appointment, $appointment,
$provider, $provider,
$service, $service,
$customer, $customer,
$settings, $settings,
new Email($admin['email']), $admin['email'],
new Text($delete_reason) $delete_reason
); );
} }
@ -285,14 +286,14 @@ class Notifications {
continue; continue;
} }
$email->send_delete_appointment( $this->CI->email_messages->send_delete_appointment(
$appointment, $appointment,
$provider, $provider,
$service, $service,
$customer, $customer,
$settings, $settings,
new Email($secretary['email']), $secretary['email'],
new Text($delete_reason) $delete_reason
); );
} }
} }