mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-10 10:02:33 +03:00
The backend appointment removal is using the notifications library
This commit is contained in:
parent
7526cff3bf
commit
e626e277cd
2 changed files with 11 additions and 93 deletions
|
@ -362,98 +362,9 @@ class Backend_api extends EA_Controller {
|
|||
// Delete appointment record from the database.
|
||||
$this->appointments_model->delete($this->input->post('appointment_id'));
|
||||
|
||||
// Sync removal with Google Calendar.
|
||||
if ($appointment['id_google_calendar'] != NULL)
|
||||
{
|
||||
try
|
||||
{
|
||||
$google_sync = $this->providers_model->get_setting('google_sync', $provider['id']);
|
||||
$this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings);
|
||||
|
||||
if ($google_sync == TRUE)
|
||||
{
|
||||
$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() : []
|
||||
];
|
||||
}
|
||||
$this->synchronization->sync_appointment_deleted($appointment, $provider);
|
||||
|
||||
if (empty($warnings))
|
||||
{
|
||||
|
|
|
@ -163,6 +163,13 @@ class Notifications {
|
|||
{
|
||||
$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']),
|
||||
FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
|
@ -170,7 +177,7 @@ class Notifications {
|
|||
{
|
||||
$email->send_delete_appointment($appointment, $provider,
|
||||
$service, $customer, $settings, new Email($provider['email']),
|
||||
new Text($this->CI->input->post('cancel_reason')));
|
||||
new Text($delete_reason));
|
||||
}
|
||||
|
||||
$send_customer = filter_var(
|
||||
|
@ -181,7 +188,7 @@ class Notifications {
|
|||
{
|
||||
$email->send_delete_appointment($appointment, $provider,
|
||||
$service, $customer, $settings, new Email($customer['email']),
|
||||
new Text($this->CI->input->post('cancel_reason')));
|
||||
new Text($delete_reason));
|
||||
}
|
||||
|
||||
// Notify admins
|
||||
|
|
Loading…
Reference in a new issue