2021-11-18 09:29:41 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
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
|
|
|
|
*/
|
|
|
|
class Unavailabilities extends EA_Controller {
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('view', PRIV_APPOINTMENTS))
|
2021-11-18 09:29:41 +03:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a unavailability.
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('add', PRIV_APPOINTMENTS))
|
2021-11-18 09:29:41 +03:00
|
|
|
{
|
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([
|
|
|
|
'success' => TRUE,
|
|
|
|
'id' => $unavailability_id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a unavailability.
|
|
|
|
*/
|
|
|
|
public function update()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('edit', PRIV_APPOINTMENTS))
|
2021-11-18 09:29:41 +03:00
|
|
|
{
|
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([
|
|
|
|
'success' => TRUE,
|
|
|
|
'id' => $unavailability_id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a unavailability.
|
|
|
|
*/
|
|
|
|
public function destroy()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('delete', PRIV_APPOINTMENTS))
|
2021-11-18 09:29:41 +03:00
|
|
|
{
|
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([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2021-12-14 09:18:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an unavailability.
|
|
|
|
*/
|
|
|
|
public function find()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 10:05:08 +03:00
|
|
|
if (cannot('view', PRIV_APPOINTMENTS))
|
2021-12-14 09:18:46 +03:00
|
|
|
{
|
2021-12-18 19:32:05 +03:00
|
|
|
abort(403, 'Forbidden');
|
2021-12-14 09:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$unavailability_id = request('unavailability_id');
|
|
|
|
|
|
|
|
$unavailability = $this->unavailabilities_model->find($unavailability_id);
|
|
|
|
|
|
|
|
json_response($unavailability);
|
|
|
|
}
|
|
|
|
catch (Throwable $e)
|
|
|
|
{
|
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
2021-11-18 09:29:41 +03:00
|
|
|
}
|