mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-24 08:53:05 +03:00
Move the consent creation process to when the appointment gets created and not earlier
This commit is contained in:
parent
afe21e3960
commit
e4e285931f
4 changed files with 54 additions and 69 deletions
|
@ -37,6 +37,7 @@ class Booking extends EA_Controller {
|
|||
$this->load->model('services_model');
|
||||
$this->load->model('customers_model');
|
||||
$this->load->model('settings_model');
|
||||
$this->load->model('consents_model');
|
||||
|
||||
$this->load->library('timezones');
|
||||
$this->load->library('synchronization');
|
||||
|
@ -66,7 +67,7 @@ class Booking extends EA_Controller {
|
|||
$disable_booking = setting('disable_booking');
|
||||
$google_analytics_code = setting('google_analytics_code');
|
||||
$matomo_analytics_url = setting('matomo_analytics_url');
|
||||
|
||||
|
||||
if ($disable_booking)
|
||||
{
|
||||
$disable_booking_message = setting('disable_booking_message');
|
||||
|
@ -134,7 +135,7 @@ class Booking extends EA_Controller {
|
|||
|
||||
$timezones = $this->timezones->to_array();
|
||||
$grouped_timezones = $this->timezones->to_grouped_array();
|
||||
|
||||
|
||||
$appointment_hash = html_vars('appointment_hash');
|
||||
|
||||
if ( ! empty($appointment_hash))
|
||||
|
@ -271,13 +272,13 @@ class Booking extends EA_Controller {
|
|||
* Render the booking page and display the selected appointment.
|
||||
*
|
||||
* This method will call the "index" callback to handle the page rendering.
|
||||
*
|
||||
*
|
||||
* @param string $appointment_hash
|
||||
*/
|
||||
public function reschedule($appointment_hash)
|
||||
{
|
||||
html_vars(['appointment_hash' => $appointment_hash]);
|
||||
|
||||
|
||||
$this->index();
|
||||
}
|
||||
|
||||
|
@ -474,6 +475,30 @@ class Booking extends EA_Controller {
|
|||
$appointment['color'] = $service['color'];
|
||||
}
|
||||
|
||||
$customer_ip = $this->input->ip_address();
|
||||
|
||||
// Create the consents (if needed).
|
||||
$consent = [
|
||||
'first_name' => $customer['first_name'] ?? '-',
|
||||
'last_name' => $customer['last_name'] ?? '-',
|
||||
'email' => $customer['email'] ?? '-',
|
||||
'ip' => $customer_ip,
|
||||
];
|
||||
|
||||
if (setting('display_terms_and_conditions'))
|
||||
{
|
||||
$consent['type'] = 'terms-and-conditions';
|
||||
|
||||
$this->consents_model->save($consent);
|
||||
}
|
||||
|
||||
if (setting('display_privacy_policy'))
|
||||
{
|
||||
$consent['type'] = 'privacy-policy';
|
||||
|
||||
$this->consents_model->save($consent);
|
||||
}
|
||||
|
||||
// Save customer language (the language which is used to render the booking page).
|
||||
$customer['language'] = session('language') ?? config('language');
|
||||
|
||||
|
@ -495,6 +520,7 @@ class Booking extends EA_Controller {
|
|||
$customer = $this->customers_model->find($customer_id);
|
||||
|
||||
$appointment['id_users_customer'] = $customer_id;
|
||||
$appointment['is_unavailability'] = FALSE;
|
||||
|
||||
$this->appointments_model->only($appointment, [
|
||||
'start_datetime',
|
||||
|
@ -506,7 +532,7 @@ class Booking extends EA_Controller {
|
|||
'id_users_customer',
|
||||
'id_services',
|
||||
]);
|
||||
|
||||
|
||||
$appointment_id = $this->appointments_model->save($appointment);
|
||||
$appointment = $this->appointments_model->find($appointment_id);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class Consents extends EA_Controller {
|
|||
/**
|
||||
* Save (insert or update) the consent
|
||||
*/
|
||||
public function save_consent()
|
||||
public function save()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -40,6 +40,28 @@ class Consents extends EA_Controller {
|
|||
|
||||
$consent['ip'] = $this->input->ip_address();
|
||||
|
||||
$occurrences = $this->consents_model->get(['ip' => $consent['ip']], 1, 0, 'create_datetime DESC');
|
||||
|
||||
if ( ! empty($occurrences))
|
||||
{
|
||||
$last_consent = $occurrences[0];
|
||||
|
||||
$last_consent_create_datetime_instance = new DateTime($last_consent['create_datetime']);
|
||||
|
||||
$threshold_datetime_instance = new DateTime('-24 hours');
|
||||
|
||||
if ($last_consent_create_datetime_instance > $threshold_datetime_instance)
|
||||
{
|
||||
// Do not create a new consent.
|
||||
|
||||
json_response([
|
||||
'success' => TRUE,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$consent['id'] = $this->consents_model->save($consent);
|
||||
|
||||
json_response([
|
||||
|
|
|
@ -302,22 +302,6 @@ App.Http.Booking = (function () {
|
|||
processingUnavailabilities = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the user's consent.
|
||||
*
|
||||
* @param {Object} consent Contains user's consents.
|
||||
*/
|
||||
function saveConsent(consent) {
|
||||
const url = App.Utils.Url.siteUrl('consents/save_consent');
|
||||
|
||||
const data = {
|
||||
csrf_token: vars('csrf_token'),
|
||||
consent: consent
|
||||
};
|
||||
|
||||
$.post(url, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete personal information.
|
||||
*
|
||||
|
@ -341,7 +325,6 @@ App.Http.Booking = (function () {
|
|||
getAvailableHours,
|
||||
getUnavailabilityDates,
|
||||
applyPreviousUnavailabilityDates,
|
||||
saveConsent,
|
||||
deletePersonalInformation
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -35,20 +35,6 @@ App.Pages.Booking = (function () {
|
|||
const $bookAppointmentSubmit = $('#book-appointment-submit');
|
||||
const $deletePersonalInformation = $('#delete-personal-information');
|
||||
|
||||
/**
|
||||
* Contains terms and conditions consent.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
let termsAndConditionsConsent;
|
||||
|
||||
/**
|
||||
* Contains privacy policy consent.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
let privacyPolicyConsent;
|
||||
|
||||
/**
|
||||
* Determines the functionality of the page.
|
||||
*
|
||||
|
@ -365,38 +351,6 @@ App.Pages.Booking = (function () {
|
|||
return; // Validation failed, do not continue.
|
||||
} else {
|
||||
updateConfirmFrame();
|
||||
|
||||
const $acceptToTermsAndConditions = $('#accept-to-terms-and-conditions');
|
||||
if ($acceptToTermsAndConditions.length && $acceptToTermsAndConditions.prop('checked') === true) {
|
||||
const newTermsAndConditionsConsent = {
|
||||
first_name: $firstName.val(),
|
||||
last_name: $lastName.val(),
|
||||
email: $email.val(),
|
||||
type: 'terms-and-conditions'
|
||||
};
|
||||
|
||||
if (
|
||||
JSON.stringify(newTermsAndConditionsConsent) !== JSON.stringify(termsAndConditionsConsent)
|
||||
) {
|
||||
termsAndConditionsConsent = newTermsAndConditionsConsent;
|
||||
App.Http.Booking.saveConsent(termsAndConditionsConsent);
|
||||
}
|
||||
}
|
||||
|
||||
const $acceptToPrivacyPolicy = $('#accept-to-privacy-policy');
|
||||
if ($acceptToPrivacyPolicy.length && $acceptToPrivacyPolicy.prop('checked') === true) {
|
||||
const newPrivacyPolicyConsent = {
|
||||
first_name: $firstName.val(),
|
||||
last_name: $lastName.val(),
|
||||
email: $email.val(),
|
||||
type: 'privacy-policy'
|
||||
};
|
||||
|
||||
if (JSON.stringify(newPrivacyPolicyConsent) !== JSON.stringify(privacyPolicyConsent)) {
|
||||
privacyPolicyConsent = newPrivacyPolicyConsent;
|
||||
App.Http.Booking.saveConsent(privacyPolicyConsent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue