mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-01 04:12:22 +03:00
Moved the booking confirmation and cancellation code out of the booking controller
This commit is contained in:
parent
bb3665272d
commit
c49f141bbb
7 changed files with 253 additions and 122 deletions
|
@ -189,126 +189,6 @@ class Booking extends EA_Controller {
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel an existing appointment.
|
||||
*
|
||||
* This method removes an appointment from the company's schedule. In order for the appointment to be deleted, the
|
||||
* hash string must be provided. The customer can only cancel the appointment if the edit time period is not over
|
||||
* yet.
|
||||
*
|
||||
* @param string $appointment_hash This appointment hash identifier.
|
||||
*/
|
||||
public function cancel(string $appointment_hash)
|
||||
{
|
||||
try
|
||||
{
|
||||
$exceptions = [];
|
||||
|
||||
$occurrences = $this->appointments_model->get(['hash' => $appointment_hash]);
|
||||
|
||||
if (empty($occurrences))
|
||||
{
|
||||
throw new Exception('No record matches the provided hash.');
|
||||
}
|
||||
|
||||
$appointment = $occurrences[0];
|
||||
|
||||
$provider = $this->providers_model->find($appointment['id_users_provider']);
|
||||
|
||||
$customer = $this->customers_model->find($appointment['id_users_customer']);
|
||||
|
||||
$service = $this->services_model->find($appointment['id_services']);
|
||||
|
||||
$settings = [
|
||||
'company_name' => setting('company_name'),
|
||||
'company_email' => setting('company_email'),
|
||||
'company_link' => setting('company_link'),
|
||||
'date_format' => setting('date_format'),
|
||||
'time_format' => setting('time_format')
|
||||
];
|
||||
|
||||
$this->appointments_model->delete($appointment['id']);
|
||||
|
||||
$this->synchronization->sync_appointment_deleted($appointment, $provider);
|
||||
|
||||
$this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
$exceptions[] = $e;
|
||||
}
|
||||
|
||||
$this->load->view('pages/booking_message', [
|
||||
'message_title' => lang('appointment_cancelled_title'),
|
||||
'message_text' => lang('appointment_cancelled'),
|
||||
'message_icon' => base_url('assets/img/success.png'),
|
||||
'exceptions' => $exceptions
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the appointment registration success page.
|
||||
*
|
||||
* @param string $appointment_hash The appointment hash identifier.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function book_success(string $appointment_hash)
|
||||
{
|
||||
$occurrences = $this->appointments_model->get(['hash' => $appointment_hash]);
|
||||
|
||||
if (empty($occurrences))
|
||||
{
|
||||
redirect('appointments'); // The appointment does not exist.
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$appointment = $occurrences[0];
|
||||
|
||||
unset($appointment['notes']);
|
||||
|
||||
$customer = $this->customers_model->find($appointment['id_users_customer']);
|
||||
|
||||
$provider = $this->providers_model->find($appointment['id_users_provider']);
|
||||
|
||||
$service = $this->services_model->find($appointment['id_services']);
|
||||
|
||||
$company_name = setting('company_name');
|
||||
|
||||
$exceptions = $this->session->flashdata('book_success') ?? [];
|
||||
|
||||
$this->load->view('pages/booking_success', [
|
||||
'page_title' => lang('success'),
|
||||
'appointment_data' => $appointment,
|
||||
'provider_data' => [
|
||||
'id' => $provider['id'],
|
||||
'first_name' => $provider['first_name'],
|
||||
'last_name' => $provider['last_name'],
|
||||
'email' => $provider['email'],
|
||||
'timezone' => $provider['timezone'],
|
||||
],
|
||||
'customer_data' => [
|
||||
'id' => $customer['id'],
|
||||
'first_name' => $customer['first_name'],
|
||||
'last_name' => $customer['last_name'],
|
||||
'email' => $customer['email'],
|
||||
'timezone' => $customer['timezone'],
|
||||
],
|
||||
'service_data' => $service,
|
||||
'company_name' => $company_name,
|
||||
'exceptions' => $exceptions,
|
||||
'scripts' => [
|
||||
'https://apis.google.com/js/client.js',
|
||||
asset_url('assets/vendor/datejs/date.min.js'),
|
||||
asset_url('assets/vendor/moment/moment.min.js'),
|
||||
asset_url('assets/vendor/moment-timezone/moment-timezone-with-data.min.js'),
|
||||
asset_url('assets/js/frontend_book_success.js'),
|
||||
asset_url('assets/js/general_functions.js')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the available appointment hours for the selected date.
|
||||
*
|
||||
|
|
94
application/controllers/Booking_cancellation.php
Executable file
94
application/controllers/Booking_cancellation.php
Executable file
|
@ -0,0 +1,94 @@
|
|||
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
||||
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link https://easyappointments.org
|
||||
* @since v1.5.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Booking cancellation controller.
|
||||
*
|
||||
* Handles the booking cancellation related operations.
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class Booking_cancellation extends EA_Controller {
|
||||
/**
|
||||
* Booking constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('appointments_model');
|
||||
$this->load->model('providers_model');
|
||||
$this->load->model('services_model');
|
||||
$this->load->model('customers_model');
|
||||
|
||||
$this->load->library('synchronization');
|
||||
$this->load->library('notifications');
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel an existing appointment.
|
||||
*
|
||||
* This method removes an appointment from the company's schedule. In order for the appointment to be deleted, the
|
||||
* hash string must be provided. The customer can only cancel the appointment if the edit time period is not over
|
||||
* yet.
|
||||
*
|
||||
* @param string $appointment_hash This appointment hash identifier.
|
||||
*/
|
||||
public function of(string $appointment_hash)
|
||||
{
|
||||
try
|
||||
{
|
||||
$exceptions = [];
|
||||
|
||||
$occurrences = $this->appointments_model->get(['hash' => $appointment_hash]);
|
||||
|
||||
if (empty($occurrences))
|
||||
{
|
||||
throw new Exception('No record matches the provided hash.');
|
||||
}
|
||||
|
||||
$appointment = $occurrences[0];
|
||||
|
||||
$provider = $this->providers_model->find($appointment['id_users_provider']);
|
||||
|
||||
$customer = $this->customers_model->find($appointment['id_users_customer']);
|
||||
|
||||
$service = $this->services_model->find($appointment['id_services']);
|
||||
|
||||
$settings = [
|
||||
'company_name' => setting('company_name'),
|
||||
'company_email' => setting('company_email'),
|
||||
'company_link' => setting('company_link'),
|
||||
'date_format' => setting('date_format'),
|
||||
'time_format' => setting('time_format')
|
||||
];
|
||||
|
||||
$this->appointments_model->delete($appointment['id']);
|
||||
|
||||
$this->synchronization->sync_appointment_deleted($appointment, $provider);
|
||||
|
||||
$this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
$exceptions[] = $e;
|
||||
}
|
||||
|
||||
$this->load->view('pages/booking_message', [
|
||||
'message_title' => lang('appointment_cancelled_title'),
|
||||
'message_text' => lang('appointment_cancelled'),
|
||||
'message_icon' => base_url('assets/img/success.png'),
|
||||
'exceptions' => $exceptions
|
||||
]);
|
||||
}
|
||||
}
|
97
application/controllers/Booking_confirmation.php
Executable file
97
application/controllers/Booking_confirmation.php
Executable file
|
@ -0,0 +1,97 @@
|
|||
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
||||
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link https://easyappointments.org
|
||||
* @since v1.5.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Booking confirmation controller.
|
||||
*
|
||||
* Handles the booking confirmation related operations.
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class Booking_confirmation extends EA_Controller {
|
||||
/**
|
||||
* Booking constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('appointments_model');
|
||||
$this->load->model('providers_model');
|
||||
$this->load->model('services_model');
|
||||
$this->load->model('customers_model');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the appointment registration success page.
|
||||
*
|
||||
* @param string $appointment_hash The appointment hash identifier.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function of(string $appointment_hash)
|
||||
{
|
||||
$occurrences = $this->appointments_model->get(['hash' => $appointment_hash]);
|
||||
|
||||
if (empty($occurrences))
|
||||
{
|
||||
redirect('appointments'); // The appointment does not exist.
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$appointment = $occurrences[0];
|
||||
|
||||
unset($appointment['notes']);
|
||||
|
||||
$customer = $this->customers_model->find($appointment['id_users_customer']);
|
||||
|
||||
$provider = $this->providers_model->find($appointment['id_users_provider']);
|
||||
|
||||
$service = $this->services_model->find($appointment['id_services']);
|
||||
|
||||
$company_name = setting('company_name');
|
||||
|
||||
$exceptions = $this->session->flashdata('book_success') ?? [];
|
||||
|
||||
$this->load->view('pages/booking_confirmation', [
|
||||
'page_title' => lang('success'),
|
||||
'appointment_data' => $appointment,
|
||||
'provider_data' => [
|
||||
'id' => $provider['id'],
|
||||
'first_name' => $provider['first_name'],
|
||||
'last_name' => $provider['last_name'],
|
||||
'email' => $provider['email'],
|
||||
'timezone' => $provider['timezone'],
|
||||
],
|
||||
'customer_data' => [
|
||||
'id' => $customer['id'],
|
||||
'first_name' => $customer['first_name'],
|
||||
'last_name' => $customer['last_name'],
|
||||
'email' => $customer['email'],
|
||||
'timezone' => $customer['timezone'],
|
||||
],
|
||||
'service_data' => $service,
|
||||
'company_name' => $company_name,
|
||||
'exceptions' => $exceptions,
|
||||
'scripts' => [
|
||||
'https://apis.google.com/js/client.js',
|
||||
asset_url('assets/vendor/datejs/date.min.js'),
|
||||
asset_url('assets/vendor/moment/moment.min.js'),
|
||||
asset_url('assets/vendor/moment-timezone/moment-timezone-with-data.min.js'),
|
||||
asset_url('assets/js/frontend_book_success.js'),
|
||||
asset_url('assets/js/general_functions.js')
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
</div>
|
||||
<div class="col-12 col-md-2">
|
||||
<form id="cancel-appointment-form" method="post"
|
||||
action="<?= site_url('booking/cancel/' . $appointment_data['hash']) ?>">
|
||||
action="<?= site_url('booking_cancellation/of/' . $appointment_data['hash']) ?>">
|
||||
|
||||
<input type="hidden" name="csrfToken" value="<?= $this->security->get_csrf_hash() ?>"/>
|
||||
|
||||
|
|
60
application/views/pages/booking_confirmation.php
Executable file
60
application/views/pages/booking_confirmation.php
Executable file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* @var string $company_name
|
||||
* @var array $appointment_data
|
||||
* @var array $provider_data
|
||||
* @var array $customer_data
|
||||
* @var array $service_data
|
||||
*/
|
||||
?>
|
||||
|
||||
<?php extend('layouts/message_layout') ?>
|
||||
|
||||
<?php section('content') ?>
|
||||
|
||||
<div>
|
||||
<img id="success-icon" class="mt-0 mb-2" src="<?= base_url('assets/img/success.png') ?>" alt="success"/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3><?= lang('appointment_registered') ?></h3>
|
||||
|
||||
<p>
|
||||
<?= lang('appointment_details_was_sent_to_you') ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>
|
||||
<?= lang('check_spam_folder') ?>
|
||||
</strong>
|
||||
</p>
|
||||
|
||||
<a href="<?= site_url() ?>" class="btn btn-success btn-large">
|
||||
<i class="fas fa-calendar-alt"></i>
|
||||
<?= lang('go_to_booking_page') ?>
|
||||
</a>
|
||||
|
||||
<?php if (config('google_sync_feature')): ?>
|
||||
<button id="add-to-google-calendar" class="btn btn-primary">
|
||||
<i class="fas fa-plus"></i>
|
||||
<?= lang('add_to_google_calendar') ?>
|
||||
</button>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var GlobalVariables = {
|
||||
csrfToken: <?= json_encode($this->security->get_csrf_hash()) ?>,
|
||||
appointmentData: <?= json_encode($appointment_data) ?>,
|
||||
providerData: <?= json_encode($provider_data) ?>,
|
||||
customerData: <?= json_encode($customer_data) ?>,
|
||||
serviceData: <?= json_encode($service_data) ?>,
|
||||
companyName: <?= json_encode($company_name) ?>,
|
||||
googleApiKey: <?= json_encode(config('google_api_key')) ?>,
|
||||
googleClientId: <?= json_encode(config('google_client_id')) ?>,
|
||||
googleApiScope: 'https://www.googleapis.com/auth/calendar'
|
||||
};
|
||||
</script>
|
||||
|
||||
<?php section('content') ?>
|
||||
|
|
@ -207,7 +207,7 @@ window.FrontendBookApi = window.FrontendBookApi || {};
|
|||
}
|
||||
|
||||
window.location.href =
|
||||
GlobalVariables.baseUrl + '/index.php/booking/book_success/' + response.appointment_hash;
|
||||
GlobalVariables.baseUrl + '/index.php/booking_confirmation/of/' + response.appointment_hash;
|
||||
})
|
||||
.fail(function (jqxhr, textStatus, errorThrown) {
|
||||
$('.captcha-title button').trigger('click');
|
||||
|
|
Loading…
Reference in a new issue