The backend appointment removal is using the notifications library

This commit is contained in:
Alex Tselegidis 2021-10-04 09:26:12 +02:00
parent 7526cff3bf
commit e626e277cd
2 changed files with 11 additions and 93 deletions

View file

@ -362,98 +362,9 @@ class Backend_api extends EA_Controller {
// Delete appointment record from the database. // Delete appointment record from the database.
$this->appointments_model->delete($this->input->post('appointment_id')); $this->appointments_model->delete($this->input->post('appointment_id'));
// Sync removal with Google Calendar. $this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings);
if ($appointment['id_google_calendar'] != NULL)
{
try
{
$google_sync = $this->providers_model->get_setting('google_sync', $provider['id']);
if ($google_sync == TRUE) $this->synchronization->sync_appointment_deleted($appointment, $provider);
{
$google_token = json_decode($this->providers_model
->get_setting('google_token', $provider['id']));
$this->google_sync->refresh_token($google_token->refresh_token);
$this->google_sync->delete_appointment($provider, $appointment['id_google_calendar']);
}
}
catch (Exception $exception)
{
$warnings[] = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}
}
// Send notification emails to provider and customer.
try
{
$this->config->load('email');
$email = new EmailClient($this, $this->config->config);
$send_provider = $this->providers_model
->get_setting('notifications', $provider['id']);
if ((bool)$send_provider === TRUE)
{
$email->send_delete_appointment($appointment, $provider,
$service, $customer, $settings, new Email($provider['email']),
new Text($this->input->post('delete_reason')));
}
$send_customer = $this->settings_model->get_setting('customer_notifications');
if ((bool)$send_customer === TRUE)
{
$email->send_delete_appointment($appointment, $provider,
$service, $customer, $settings, new Email($customer['email']),
new Text($this->input->post('delete_reason')));
}
// Notify admins
$admins = $this->admins_model->get_batch();
foreach ($admins as $admin)
{
if ( ! $admin['settings']['notifications'] === '0')
{
continue;
}
$email->send_delete_appointment($appointment, $provider,
$service, $customer, $settings, new Email($admin['email']),
new Text($this->input->post('cancel_reason')));
}
// Notify secretaries
$secretaries = $this->secretaries_model->get_batch();
foreach ($secretaries as $secretary)
{
if ( ! $secretary['settings']['notifications'] === '0')
{
continue;
}
if (in_array($provider['id'], $secretary['providers']))
{
continue;
}
$email->send_delete_appointment($appointment, $provider,
$service, $customer, $settings, new Email($secretary['email']),
new Text($this->input->post('cancel_reason')));
}
}
catch (Exception $exception)
{
$warnings[] = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}
if (empty($warnings)) if (empty($warnings))
{ {

View file

@ -163,6 +163,13 @@ class Notifications {
{ {
$email = new EmailClient($this->CI, $this->CI->config->config); $email = new EmailClient($this->CI, $this->CI->config->config);
$delete_reason = (string)$this->CI->input->post('delete_reason');
if ( ! $delete_reason)
{
$delete_reason = (string)$this->CI->input->post('cancel_reason');
}
$send_provider = filter_var($this->CI->providers_model->get_setting('notifications', $provider['id']), $send_provider = filter_var($this->CI->providers_model->get_setting('notifications', $provider['id']),
FILTER_VALIDATE_BOOLEAN); FILTER_VALIDATE_BOOLEAN);
@ -170,7 +177,7 @@ class Notifications {
{ {
$email->send_delete_appointment($appointment, $provider, $email->send_delete_appointment($appointment, $provider,
$service, $customer, $settings, new Email($provider['email']), $service, $customer, $settings, new Email($provider['email']),
new Text($this->CI->input->post('cancel_reason'))); new Text($delete_reason));
} }
$send_customer = filter_var( $send_customer = filter_var(
@ -181,7 +188,7 @@ class Notifications {
{ {
$email->send_delete_appointment($appointment, $provider, $email->send_delete_appointment($appointment, $provider,
$service, $customer, $settings, new Email($customer['email']), $service, $customer, $settings, new Email($customer['email']),
new Text($this->CI->input->post('cancel_reason'))); new Text($delete_reason));
} }
// Notify admins // Notify admins