Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed Oct 22, 2020
2 parents 39b2363 + e3089ae commit 6bf4e8b
Show file tree
Hide file tree
Showing 49 changed files with 11,080 additions and 1,544 deletions.
4 changes: 2 additions & 2 deletions application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
|
*/
$config['version'] = '1.4.0'; // This must be changed manually.
$config['release_label'] = 'Dev'; // Leave empty for no title or add Alpha, Beta etc ...
$config['release_label'] = 'Beta.1'; // Leave empty for no title or add Alpha, Beta etc ...
$config['debug'] = Config::DEBUG_MODE;

/*
Expand Down Expand Up @@ -302,7 +302,7 @@
| new release.
|
*/
$config['cache_busting_token'] = '93GX4';
$config['cache_busting_token'] = '824HX';

/*
|--------------------------------------------------------------------------
Expand Down
873 changes: 52 additions & 821 deletions application/controllers/Appointments.php

Large diffs are not rendered by default.

177 changes: 26 additions & 151 deletions application/controllers/Backend_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
* @property Customers_Model $customers_model
* @property Settings_Model $settings_model
* @property Timezones $timezones
* @property Synchronization $synchronization
* @property Notifications $notifications
* @property Roles_Model $roles_model
* @property Secretaries_Model $secretaries_model
* @property Admins_Model $admins_model
Expand Down Expand Up @@ -102,7 +104,7 @@ public function ajax_get_calendar_events()
'start_datetime >=' => $startDate,
'end_datetime <=' => $endDate
]),
'unavailabilities' => $this->appointments_model->get_batch([
'unavailability_events' => $this->appointments_model->get_batch([
'is_unavailable' => TRUE,
'start_datetime >=' => $startDate,
'end_datetime <=' => $endDate
Expand Down Expand Up @@ -130,11 +132,11 @@ public function ajax_get_calendar_events()
}
}

foreach ($response['unavailabilities'] as $index => $unavailability)
foreach ($response['unavailability_events'] as $index => $unavailability_event)
{
if ((int)$unavailability['id_users_provider'] !== (int)$userId)
if ((int)$unavailability_event['id_users_provider'] !== (int)$userId)
{
unset($response['unavailabilities'][$index]);
unset($response['unavailability_events'][$index]);
}
}
}
Expand All @@ -152,11 +154,11 @@ public function ajax_get_calendar_events()
}
}

foreach ($response['unavailabilities'] as $index => $unavailability)
foreach ($response['unavailability_events'] as $index => $unavailability_event)
{
if ( ! in_array((int)$unavailability['id_users_provider'], $providers))
if ( ! in_array((int)$unavailability_event['id_users_provider'], $providers))
{
unset($response['unavailabilities'][$index]);
unset($response['unavailability_events'][$index]);
}
}
}
Expand Down Expand Up @@ -283,17 +285,19 @@ public function ajax_save_appointment()
$this->load->model('customers_model');
$this->load->model('settings_model');
$this->load->library('timezones');
$this->load->library('synchronization');
$this->load->library('notifications');
$this->load->model('user_model');

// Save customer changes to the database.
if ($this->input->post('customer_data'))
{
$customer = json_decode($this->input->post('customer_data'), TRUE);

$required_privilegesileges = ( ! isset($customer['id']))
$required_privileges = ( ! isset($customer['id']))
? $this->privileges[PRIV_CUSTOMERS]['add']
: $this->privileges[PRIV_CUSTOMERS]['edit'];
if ($required_privilegesileges == FALSE)
if ($required_privileges == FALSE)
{
throw new Exception('You do not have the required privileges for this task.');
}
Expand All @@ -306,17 +310,17 @@ public function ajax_save_appointment()
{
$appointment = json_decode($this->input->post('appointment_data'), TRUE);

$required_privilegesileges = ( ! isset($appointment['id']))
$required_privileges = ( ! isset($appointment['id']))
? $this->privileges[PRIV_APPOINTMENTS]['add']
: $this->privileges[PRIV_APPOINTMENTS]['edit'];
if ($required_privilegesileges == FALSE)
if ($required_privileges == FALSE)
{
throw new Exception('You do not have the required privileges for this task.');
}

$manage_mode = isset($appointment['id']);
// If the appointment does not contain the customer record id, then it
// means that is is going to be inserted. Get the customer's record id.
// If the appointment does not contain the customer record id, then it means that is is going to be
// inserted. Get the customer's record ID.
if ( ! isset($appointment['id_users_customer']))
{
$appointment['id_users_customer'] = $customer['id'];
Expand Down Expand Up @@ -348,139 +352,10 @@ public function ajax_save_appointment()
'time_format' => $this->settings_model->get_setting('time_format')
];

// Sync appointment changes with Google Calendar.
try
{
$google_sync = $this->providers_model->get_setting('google_sync',
$appointment['id_users_provider']);

if ($google_sync == TRUE)
{
$google_token = json_decode($this->providers_model->get_setting('google_token',
$appointment['id_users_provider']));
$this->synchronization->sync_appointment_deleted($appointment, $provider);
$this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings);

$this->load->library('Google_sync');
$this->google_sync->refresh_token($google_token->refresh_token);

if ($appointment['id_google_calendar'] == NULL)
{
$google_event = $this->google_sync->add_appointment($appointment, $provider,
$service, $customer, $settings);
$appointment['id_google_calendar'] = $google_event->id;
$this->appointments_model->add($appointment); // Store google calendar id.
}
else
{
$this->google_sync->update_appointment($appointment, $provider,
$service, $customer, $settings);
}
}
}
catch (Exception $exception)
{
$warnings[] = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}

// Send email notifications 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 ( ! $manage_mode)
{
$customer_title = new Text(lang('appointment_booked'));
$customer_message = new Text(lang('thank_you_for_appointment'));
$provider_title = new Text(lang('appointment_added_to_your_plan'));
$provider_message = new Text(lang('appointment_link_description'));
}
else
{
$customer_title = new Text(lang('appointment_details_changed'));
$customer_message = new Text('');
$provider_title = new Text(lang('appointment_changes_saved'));
$provider_message = new Text('');
}

$customer_link = new Url(site_url('appointments/index/' . $appointment['hash']));
$provider_link = new Url(site_url('backend/index/' . $appointment['hash']));

$send_customer = $this->settings_model->get_setting('customer_notifications');

$this->load->library('ics_file');
$ics_stream = $this->ics_file->get_stream($appointment, $service, $provider, $customer);

if ((bool)$send_customer === TRUE)
{
$email->sendAppointmentDetails($appointment, $provider,
$service, $customer, $settings, $customer_title,
$customer_message, $customer_link, new Email($customer['email']), new Text($ics_stream));
}

if ($send_provider == TRUE)
{
$email->sendAppointmentDetails($appointment, $provider,
$service, $customer, $settings, $provider_title,
$provider_message, $provider_link, new Email($provider['email']), new Text($ics_stream));
}

// Notify admins
$admins = $this->admins_model->get_batch();

foreach($admins as $admin)
{
if (!$admin['settings']['notifications'] === '0')
{
continue;
}

$email->sendAppointmentDetails($appointment, $provider,
$service, $customer, $settings, $provider_title,
$provider_message, $provider_link, new Email($admin['email']), new Text($ics_stream));
}

// 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->sendAppointmentDetails($appointment, $provider,
$service, $customer, $settings, $provider_title,
$provider_message, $provider_link, new Email($secretary['email']), new Text($ics_stream));
}
}
catch (Exception $exception)
{
$warnings[] = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}

if (empty($warnings))
{
$response = AJAX_SUCCESS;
}
else
{
$response = ['warnings' => $warnings];
}
$response = AJAX_SUCCESS;
}
catch (Exception $exception)
{
Expand Down Expand Up @@ -1032,10 +907,10 @@ public function ajax_save_customer()
$this->load->model('customers_model');
$customer = json_decode($this->input->post('customer'), TRUE);

$required_privilegesileges = ( ! isset($customer['id']))
$required_privileges = ( ! isset($customer['id']))
? $this->privileges[PRIV_CUSTOMERS]['add']
: $this->privileges[PRIV_CUSTOMERS]['edit'];
if ($required_privilegesileges == FALSE)
if ($required_privileges == FALSE)
{
throw new Exception('You do not have the required privileges for this task.');
}
Expand Down Expand Up @@ -1105,10 +980,10 @@ public function ajax_save_service()
$this->load->model('services_model');
$service = json_decode($this->input->post('service'), TRUE);

$required_privilegesileges = ( ! isset($service['id']))
$required_privileges = ( ! isset($service['id']))
? $this->privileges[PRIV_SERVICES]['add']
: $this->privileges[PRIV_SERVICES]['edit'];
if ($required_privilegesileges == FALSE)
if ($required_privileges == FALSE)
{
throw new Exception('You do not have the required privileges for this task.');
}
Expand Down Expand Up @@ -1215,10 +1090,10 @@ public function ajax_save_service_category()
$this->load->model('services_model');
$category = json_decode($this->input->post('category'), TRUE);

$required_privilegesileges = ( ! isset($category['id']))
$required_privileges = ( ! isset($category['id']))
? $this->privileges[PRIV_SERVICES]['add']
: $this->privileges[PRIV_SERVICES]['edit'];
if ($required_privilegesileges == FALSE)
if ($required_privileges == FALSE)
{
throw new Exception('You do not have the required privileges for this task.');
}
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/api/v1/API_V1_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct()
}
catch (Exception $exception)
{
exit($this->_handleException($exception));
exit($this->handle_exception($exception));
}
}

Expand Down Expand Up @@ -142,7 +142,7 @@ protected function _requestAuthentication()
*
* @param Exception $exception Thrown exception to be outputted.
*/
protected function _handleException(Exception $exception)
protected function handle_exception(Exception $exception)
{
$error = [
'code' => $exception->getCode() ?: 500,
Expand All @@ -166,7 +166,7 @@ protected function _handleException(Exception $exception)
*
* @throws \EA\Engine\Api\V1\Exception
*/
protected function _throwRecordNotFound()
protected function throw_record_not_found()
{
throw new \EA\Engine\Api\V1\Exception('The requested record was not found!', 404, 'Not Found');
}
Expand Down
12 changes: 6 additions & 6 deletions application/controllers/api/v1/Admins.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function get($id = NULL)

if ($id !== NULL && count($admins) === 0)
{
$this->_throwRecordNotFound();
$this->throw_record_not_found();
}

$response = new Response($admins);
Expand All @@ -92,7 +92,7 @@ public function get($id = NULL)
}
catch (Exception $exception)
{
$this->_handleException($exception);
$this->handle_exception($exception);
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ public function post()
}
catch (Exception $exception)
{
$this->_handleException($exception);
$this->handle_exception($exception);
}
}

Expand All @@ -141,7 +141,7 @@ public function put($id)

if ($id !== NULL && count($batch) === 0)
{
$this->_throwRecordNotFound();
$this->throw_record_not_found();
}

$request = new Request();
Expand All @@ -158,7 +158,7 @@ public function put($id)
}
catch (Exception $exception)
{
$this->_handleException($exception);
$this->handle_exception($exception);
}
}

Expand All @@ -182,7 +182,7 @@ public function delete($id)
}
catch (Exception $exception)
{
$this->_handleException($exception);
$this->handle_exception($exception);
}
}
}
Loading

0 comments on commit 6bf4e8b

Please sign in to comment.