2021-11-06 17:03:08 +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-06 17:03:08 +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-06 17:03:08 +03:00
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
|
* @since v1.5.0
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unavailabilities API v1 controller.
|
|
|
|
|
*
|
|
|
|
|
* @package Controllers
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
class Unavailabilities_api_v1 extends EA_Controller
|
|
|
|
|
{
|
2021-11-06 17:03:08 +03:00
|
|
|
|
/**
|
|
|
|
|
* Unavailabilities_api_v1 constructor.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
2023-10-27 10:01:00 +03:00
|
|
|
|
$this->load->library('api');
|
|
|
|
|
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$this->api->auth();
|
|
|
|
|
|
|
|
|
|
$this->api->model('unavailabilities_model');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get an unavailability collection.
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$keyword = $this->api->request_keyword();
|
|
|
|
|
|
|
|
|
|
$limit = $this->api->request_limit();
|
|
|
|
|
|
|
|
|
|
$offset = $this->api->request_offset();
|
|
|
|
|
|
|
|
|
|
$order_by = $this->api->request_order_by();
|
|
|
|
|
|
|
|
|
|
$fields = $this->api->request_fields();
|
|
|
|
|
|
2021-11-06 17:41:11 +03:00
|
|
|
|
$with = $this->api->request_with();
|
2021-11-06 17:34:54 +03:00
|
|
|
|
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$unavailabilities = empty($keyword)
|
2023-11-29 12:24:09 +03:00
|
|
|
|
? $this->unavailabilities_model->get(null, $limit, $offset, $order_by)
|
2021-11-06 17:03:08 +03:00
|
|
|
|
: $this->unavailabilities_model->search($keyword, $limit, $offset, $order_by);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
foreach ($unavailabilities as &$unavailability) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$this->unavailabilities_model->api_encode($unavailability);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($fields)) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$this->unavailabilities_model->only($unavailability, $fields);
|
|
|
|
|
}
|
2021-11-06 17:34:54 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($with)) {
|
2021-11-06 17:41:11 +03:00
|
|
|
|
$this->unavailabilities_model->load($unavailability, $with);
|
2021-11-06 17:34:54 +03:00
|
|
|
|
}
|
2021-11-06 17:03:08 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
json_response($unavailabilities);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a single unavailability.
|
|
|
|
|
*
|
|
|
|
|
* @param int|null $id Unavailability ID.
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
public function show(int $id = null)
|
2021-11-06 17:03:08 +03:00
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$fields = $this->api->request_fields();
|
|
|
|
|
|
2021-11-06 17:41:11 +03:00
|
|
|
|
$with = $this->api->request_with();
|
2021-11-06 17:34:54 +03:00
|
|
|
|
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$unavailability = $this->unavailabilities_model->find($id);
|
|
|
|
|
|
|
|
|
|
$this->unavailabilities_model->api_encode($unavailability);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($fields)) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$this->unavailabilities_model->only($unavailability, $fields);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($with)) {
|
2021-11-06 17:41:11 +03:00
|
|
|
|
$this->unavailabilities_model->load($unavailability, $with);
|
2021-11-06 17:34:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!$unavailability) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
response('', 404);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
json_response($unavailability);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-26 06:41:25 +03:00
|
|
|
|
* Store a new unavailability.
|
2021-11-06 17:03:08 +03:00
|
|
|
|
*/
|
|
|
|
|
public function store()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$unavailability = request();
|
|
|
|
|
|
|
|
|
|
$this->unavailabilities_model->api_decode($unavailability);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (array_key_exists('id', $unavailability)) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
unset($unavailability['id']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$unavailability_id = $this->unavailabilities_model->save($unavailability);
|
|
|
|
|
|
|
|
|
|
$created_unavailability = $this->unavailabilities_model->find($unavailability_id);
|
|
|
|
|
|
|
|
|
|
$this->unavailabilities_model->api_encode($created_unavailability);
|
|
|
|
|
|
|
|
|
|
json_response($created_unavailability, 201);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update an unavailability.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id Unavailability ID.
|
|
|
|
|
*/
|
|
|
|
|
public function update(int $id)
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$occurrences = $this->unavailabilities_model->get(['id' => $id]);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (empty($occurrences)) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
response('', 404);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$original_unavailability = $occurrences[0];
|
|
|
|
|
|
|
|
|
|
$unavailability = request();
|
|
|
|
|
|
|
|
|
|
$this->unavailabilities_model->api_decode($unavailability, $original_unavailability);
|
|
|
|
|
|
|
|
|
|
$unavailability_id = $this->unavailabilities_model->save($unavailability);
|
|
|
|
|
|
|
|
|
|
$updated_unavailability = $this->unavailabilities_model->find($unavailability_id);
|
|
|
|
|
|
|
|
|
|
$this->unavailabilities_model->api_encode($updated_unavailability);
|
|
|
|
|
|
|
|
|
|
json_response($updated_unavailability);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete an unavailability.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id Unavailability ID.
|
|
|
|
|
*/
|
|
|
|
|
public function destroy(int $id)
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
try {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
$occurrences = $this->unavailabilities_model->get(['id' => $id]);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (empty($occurrences)) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
response('', 404);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->unavailabilities_model->delete($id);
|
|
|
|
|
|
|
|
|
|
response('', 204);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
|
json_exception($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|