2021-11-18 09:29:41 +03:00
|
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2023-12-31 21:46:27 +03:00
|
|
|
|
* IFLRandevu - İzmir Fen Lisesi Randevu Portalı
|
2021-11-18 09:29:41 +03:00
|
|
|
|
*
|
|
|
|
|
* @package EasyAppointments
|
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2021-11-18 09:29:41 +03:00
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
|
* @since v1.0.0
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unavailabilities controller.
|
|
|
|
|
*
|
|
|
|
|
* Handles the unavailabilities related operations.
|
|
|
|
|
*
|
|
|
|
|
* @package Controllers
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
class Unavailabilities extends EA_Controller
|
|
|
|
|
{
|
2021-11-18 09:29:41 +03:00
|
|
|
|
/**
|
|
|
|
|
* Unavailabilities constructor.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
|
|
$this->load->model('unavailabilities_model');
|
|
|
|
|
$this->load->model('roles_model');
|
|
|
|
|
|
|
|
|
|
$this->load->library('accounts');
|
|
|
|
|
$this->load->library('timezones');
|
2022-06-19 20:05:45 +03:00
|
|
|
|
$this->load->library('webhooks_client');
|
2021-11-18 09:29:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Filter unavailabilities by the provided keyword.
|
|
|
|
|
*/
|
|
|
|
|
public function search()
|
|
|
|
|
{
|
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');
|
2021-11-18 09:29:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$keyword = request('keyword', '');
|
|
|
|
|
|
2022-10-16 18:07:01 +03:00
|
|
|
|
$order_by = 'update_datetime DESC';
|
2021-11-18 09:29:41 +03:00
|
|
|
|
|
|
|
|
|
$limit = request('limit', 1000);
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
2021-11-18 09:29:41 +03:00
|
|
|
|
$offset = 0;
|
|
|
|
|
|
|
|
|
|
$unavailabilities = $this->unavailabilities_model->search($keyword, $limit, $offset, $order_by);
|
|
|
|
|
|
|
|
|
|
json_response($unavailabilities);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-18 09:29:41 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-26 06:41:25 +03:00
|
|
|
|
* Store a new unavailability.
|
2021-11-18 09:29:41 +03:00
|
|
|
|
*/
|
2023-10-26 06:41:25 +03:00
|
|
|
|
public function store()
|
2021-11-18 09:29:41 +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');
|
2021-11-18 09:29:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
|
$unavailability = request('unavailability');
|
2022-03-25 14:50:40 +03:00
|
|
|
|
|
2023-01-21 14:51:06 +03:00
|
|
|
|
$this->unavailabilities_model->only($unavailability, [
|
|
|
|
|
'first_name',
|
|
|
|
|
'last_name',
|
|
|
|
|
'email',
|
|
|
|
|
'phone_number',
|
|
|
|
|
'address',
|
|
|
|
|
'city',
|
|
|
|
|
'state',
|
|
|
|
|
'zip_code',
|
|
|
|
|
'notes',
|
|
|
|
|
'timezone',
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'language',
|
2023-01-21 14:51:06 +03:00
|
|
|
|
]);
|
|
|
|
|
|
2021-11-18 09:29:41 +03:00
|
|
|
|
$unavailability_id = $this->unavailabilities_model->save($unavailability);
|
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
|
$unavailability = $this->unavailabilities_model->find($unavailability_id);
|
|
|
|
|
|
|
|
|
|
$provider = $this->providers_model->find($unavailability['id_users_provider']);
|
|
|
|
|
|
|
|
|
|
$this->synchronization->sync_unavailability_saved($unavailability, $provider);
|
|
|
|
|
|
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_UNAVAILABILITY_SAVE, $unavailability);
|
|
|
|
|
|
2021-11-18 09:29:41 +03:00
|
|
|
|
json_response([
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'success' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'id' => $unavailability_id,
|
2021-11-18 09:29:41 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
json_exception($e);
|
2021-11-18 09:29:41 +03:00
|
|
|
|
}
|
2023-11-29 12:24:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Find an unavailability.
|
|
|
|
|
*/
|
|
|
|
|
public function find()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if (cannot('view', PRIV_APPOINTMENTS)) {
|
|
|
|
|
abort(403, 'Forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$unavailability_id = request('unavailability_id');
|
|
|
|
|
|
|
|
|
|
$unavailability = $this->unavailabilities_model->find($unavailability_id);
|
|
|
|
|
|
|
|
|
|
json_response($unavailability);
|
|
|
|
|
} catch (Throwable $e) {
|
2021-11-18 09:29:41 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update a unavailability.
|
|
|
|
|
*/
|
|
|
|
|
public function update()
|
|
|
|
|
{
|
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');
|
2021-11-18 09:29:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
|
$unavailability = request('unavailability');
|
2022-03-25 14:50:40 +03:00
|
|
|
|
|
2021-11-18 09:29:41 +03:00
|
|
|
|
$unavailability_id = $this->unavailabilities_model->save($unavailability);
|
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
|
$unavailability = $this->unavailabilities_model->find($unavailability_id);
|
|
|
|
|
|
|
|
|
|
$provider = $this->providers_model->find($unavailability['id_users_provider']);
|
|
|
|
|
|
|
|
|
|
$this->synchronization->sync_unavailability_saved($unavailability, $provider);
|
|
|
|
|
|
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_UNAVAILABILITY_SAVE, $unavailability);
|
|
|
|
|
|
2021-11-18 09:29:41 +03:00
|
|
|
|
json_response([
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'success' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'id' => $unavailability_id,
|
2021-11-18 09:29:41 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-18 09:29:41 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove a unavailability.
|
|
|
|
|
*/
|
|
|
|
|
public function destroy()
|
|
|
|
|
{
|
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');
|
2021-11-18 09:29:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$unavailability_id = request('unavailability_id');
|
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
|
$unavailability = $this->unavailabilities_model->find($unavailability_id);
|
|
|
|
|
|
2021-11-18 09:29:41 +03:00
|
|
|
|
$this->unavailabilities_model->delete($unavailability_id);
|
|
|
|
|
|
2022-06-19 20:05:45 +03:00
|
|
|
|
$this->webhooks_client->trigger(WEBHOOK_UNAVAILABILITY_DELETE, $unavailability);
|
|
|
|
|
|
2021-11-18 09:29:41 +03:00
|
|
|
|
json_response([
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'success' => true,
|
2021-11-18 09:29:41 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-12-14 09:18:46 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-18 09:29:41 +03:00
|
|
|
|
}
|