2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2015-10-05 01:32:47 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2015-10-05 01:32:47 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2020-11-14 22:36:25 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2015-10-05 01:32:47 +03:00
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2021-11-06 18:21:27 +03:00
|
|
|
* Appointments controller.
|
2021-10-28 15:01:17 +03:00
|
|
|
*
|
2021-11-18 09:12:16 +03:00
|
|
|
* Handles the appointments related operations.
|
2022-06-19 20:05:45 +03:00
|
|
|
*
|
2021-11-18 09:12:16 +03:00
|
|
|
* Notice: This file used to have the booking page related code which since v1.5 has now moved to the Booking.php
|
|
|
|
* controller for improved consistency.
|
2015-10-05 01:32:47 +03:00
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
class Appointments extends EA_Controller
|
|
|
|
{
|
2015-10-18 21:00:01 +03:00
|
|
|
/**
|
2021-11-06 18:21:27 +03:00
|
|
|
* Appointments constructor.
|
2015-10-18 21:00:01 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2015-10-18 21:00:01 +03:00
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
$this->load->model('appointments_model');
|
2021-11-18 09:12:16 +03:00
|
|
|
$this->load->model('roles_model');
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$this->load->library('accounts');
|
2020-05-12 21:50:55 +03:00
|
|
|
$this->load->library('timezones');
|
2022-06-19 20:05:45 +03:00
|
|
|
$this->load->library('webhooks_client');
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2015-10-05 01:32:47 +03:00
|
|
|
|
|
|
|
/**
|
2022-06-19 20:05:45 +03:00
|
|
|
* Support backwards compatibility for appointment links that still point to this URL.
|
|
|
|
*
|
2021-11-18 09:12:16 +03:00
|
|
|
* @param string $appointment_hash
|
2022-06-19 20:05:45 +03:00
|
|
|
*
|
2021-11-18 09:12:16 +03:00
|
|
|
* @deprecated Since 1.5
|
2015-10-05 01:32:47 +03:00
|
|
|
*/
|
2021-10-28 15:01:17 +03:00
|
|
|
public function index(string $appointment_hash = '')
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-11-18 09:12:16 +03:00
|
|
|
redirect('booking/' . $appointment_hash);
|
2015-10-05 01:32:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-18 09:12:16 +03:00
|
|
|
* Filter appointments by the provided keyword.
|
2015-10-05 01:32:47 +03:00
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function search(): void
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
try {
|
|
|
|
if (cannot('view', PRIV_APPOINTMENTS)) {
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2015-10-05 01:32:47 +03:00
|
|
|
}
|
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$keyword = request('keyword', '');
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2022-10-16 18:07:01 +03:00
|
|
|
$order_by = 'update_datetime DESC';
|
2015-10-05 01:32:47 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$limit = request('limit', 1000);
|
2022-06-19 20:05:45 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$offset = 0;
|
2015-10-05 01:32:47 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$appointments = $this->appointments_model->search($keyword, $limit, $offset, $order_by);
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
json_response($appointments);
|
2023-11-29 12:24:09 +03:00
|
|
|
} catch (Throwable $e) {
|
2021-11-18 09:12:16 +03:00
|
|
|
json_exception($e);
|
2015-11-23 23:58:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 01:32:47 +03:00
|
|
|
/**
|
2023-10-26 06:41:25 +03:00
|
|
|
* Store a new appointment.
|
2015-10-05 01:32:47 +03:00
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function store(): void
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
try {
|
|
|
|
if (cannot('add', PRIV_APPOINTMENTS)) {
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
2022-03-25 14:50:40 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$appointment = json_decode(request('appointment'), true);
|
2022-03-25 14:50:40 +03:00
|
|
|
|
2022-03-25 14:29:17 +03:00
|
|
|
$this->appointments_model->only($appointment, [
|
2023-11-29 12:24:09 +03:00
|
|
|
'start_datetime',
|
|
|
|
'end_datetime',
|
|
|
|
'location',
|
|
|
|
'notes',
|
|
|
|
'color',
|
|
|
|
'is_unavailability',
|
|
|
|
'id_users_provider',
|
|
|
|
'id_users_customer',
|
2023-12-22 13:35:41 +03:00
|
|
|
'id_services',
|
2022-03-25 14:29:17 +03:00
|
|
|
]);
|
2015-12-11 00:29:15 +02:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$appointment_id = $this->appointments_model->save($appointment);
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
$appointment = $this->appointments_model->find($appointment);
|
|
|
|
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_SAVE, $appointment);
|
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
json_response([
|
2023-11-29 12:24:09 +03:00
|
|
|
'success' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
'id' => $appointment_id,
|
2021-11-18 09:12:16 +03:00
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
} catch (Throwable $e) {
|
|
|
|
json_exception($e);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2023-11-29 12:24:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an appointment.
|
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function find(): void
|
2023-11-29 12:24:09 +03:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (cannot('view', PRIV_APPOINTMENTS)) {
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
}
|
|
|
|
|
|
|
|
$appointment_id = request('appointment_id');
|
|
|
|
|
|
|
|
$appointment = $this->appointments_model->find($appointment_id);
|
|
|
|
|
|
|
|
json_response($appointment);
|
|
|
|
} catch (Throwable $e) {
|
2021-11-12 19:23:43 +03:00
|
|
|
json_exception($e);
|
2015-10-05 01:32:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 21:00:01 +03:00
|
|
|
/**
|
2021-11-18 09:12:16 +03:00
|
|
|
* Update a appointment.
|
2020-04-22 22:48:56 +03:00
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function update(): void
|
2020-04-22 22:48:56 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
try {
|
|
|
|
if (cannot('edit', PRIV_APPOINTMENTS)) {
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2020-09-21 14:26:15 +03:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$appointment = json_decode(request('appointment'), true);
|
2022-03-25 14:50:40 +03:00
|
|
|
|
2022-03-25 14:29:17 +03:00
|
|
|
$this->appointments_model->only($appointment, [
|
|
|
|
'id',
|
|
|
|
'start_datetime',
|
|
|
|
'end_datetime',
|
|
|
|
'location',
|
|
|
|
'notes',
|
|
|
|
'color',
|
|
|
|
'is_unavailability',
|
|
|
|
'id_users_provider',
|
|
|
|
'id_users_customer',
|
2023-12-22 13:35:41 +03:00
|
|
|
'id_services',
|
2022-03-25 14:29:17 +03:00
|
|
|
]);
|
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$appointment_id = $this->appointments_model->save($appointment);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
json_response([
|
2023-11-29 12:24:09 +03:00
|
|
|
'success' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
'id' => $appointment_id,
|
2021-11-18 09:12:16 +03:00
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
} catch (Throwable $e) {
|
2021-11-12 19:23:43 +03:00
|
|
|
json_exception($e);
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-18 09:12:16 +03:00
|
|
|
* Remove a appointment.
|
2020-04-22 22:48:56 +03:00
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function destroy(): void
|
2020-04-22 22:48:56 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
try {
|
|
|
|
if (cannot('delete', PRIV_APPOINTMENTS)) {
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2020-04-22 22:48:56 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$appointment_id = request('appointment_id');
|
2023-11-29 12:24:09 +03:00
|
|
|
|
|
|
|
$appointment = $this->appointments_model->find($appointment_id);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
$this->appointments_model->delete($appointment_id);
|
2020-10-21 21:37:47 +03:00
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_DELETE, $appointment);
|
|
|
|
|
2021-11-18 09:12:16 +03:00
|
|
|
json_response([
|
2023-12-22 13:35:41 +03:00
|
|
|
'success' => true,
|
2021-11-18 09:12:16 +03:00
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
} catch (Throwable $e) {
|
2021-12-14 09:18:46 +03:00
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 01:32:47 +03:00
|
|
|
}
|