first commit
Some checks failed
CI / build-test (push) Has been cancelled

This commit is contained in:
2025-05-31 18:56:37 +02:00
commit 8c4798a5fd
1240 changed files with 190468 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<html lang="en">
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,202 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Admins API v1 controller.
*
* @package Controllers
*/
class Admins_api_v1 extends EA_Controller
{
/**
* Admins_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->model('admins_model');
$this->load->library('api');
$this->api->auth();
$this->api->model('admins_model');
}
/**
* Get an admin collection.
*/
public function index(): void
{
try {
$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();
$with = $this->api->request_with();
$admins = empty($keyword)
? $this->admins_model->get(null, $limit, $offset, $order_by)
: $this->admins_model->search($keyword, $limit, $offset, $order_by);
foreach ($admins as &$admin) {
$this->admins_model->api_encode($admin);
if (!empty($fields)) {
$this->admins_model->only($admin, $fields);
}
if (!empty($with)) {
$this->admins_model->load($admin, $with);
}
}
json_response($admins);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Get a single admin.
*
* @param int|null $id Admin ID.
*/
public function show(?int $id = null): void
{
try {
$occurrences = $this->admins_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$admin = $this->admins_model->find($id);
$this->admins_model->api_encode($admin);
if (!empty($fields)) {
$this->admins_model->only($admin, $fields);
}
if (!empty($with)) {
$this->admins_model->load($admin, $with);
}
json_response($admin);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Store a new admin.
*/
public function store(): void
{
try {
$admin = request();
$this->admins_model->api_decode($admin);
if (array_key_exists('id', $admin)) {
unset($admin['id']);
}
if (!array_key_exists('settings', $admin)) {
throw new InvalidArgumentException('No settings property provided.');
}
$admin_id = $this->admins_model->save($admin);
$created_admin = $this->admins_model->find($admin_id);
$this->admins_model->api_encode($created_admin);
json_response($created_admin, 201);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Update an admin.
*
* @param int $id Admin ID.
*/
public function update(int $id): void
{
try {
$occurrences = $this->admins_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$original_admin = $occurrences[0];
$admin = request();
$this->admins_model->api_decode($admin, $original_admin);
$admin_id = $this->admins_model->save($admin);
$updated_admin = $this->admins_model->find($admin_id);
$this->admins_model->api_encode($updated_admin);
json_response($updated_admin);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete an admin.
*
* @param int $id Admin ID.
*/
public function destroy(int $id): void
{
try {
$occurrences = $this->admins_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$this->admins_model->delete($id);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,383 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Appointments API v1 controller.
*
* @package Controllers
*/
class Appointments_api_v1 extends EA_Controller
{
/**
* Appointments_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->model('appointments_model');
$this->load->model('customers_model');
$this->load->model('providers_model');
$this->load->model('services_model');
$this->load->model('settings_model');
$this->load->library('api');
$this->load->library('synchronization');
$this->load->library('notifications');
$this->api->auth();
$this->api->model('appointments_model');
}
/**
* Get an appointment collection.
*/
public function index(): void
{
try {
$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();
$with = $this->api->request_with();
$where = null;
// Date query param.
$date = request('date');
if (!empty($date)) {
$where['DATE(start_datetime)'] = new DateTime($date)->format('Y-m-d');
}
// From query param.
$from = request('from');
if (!empty($from)) {
$where['DATE(start_datetime) >='] = new DateTime($from)->format('Y-m-d');
}
// Till query param.
$till = request('till');
if (!empty($till)) {
$where['DATE(end_datetime) <='] = new DateTime($till)->format('Y-m-d');
}
// Service ID query param.
$service_id = request('serviceId');
if (!empty($service_id)) {
$where['id_services'] = $service_id;
}
// Provider ID query param.
$provider_id = request('providerId');
if (!empty($provider_id)) {
$where['id_users_provider'] = $provider_id;
}
// Customer ID query param.
$customer_id = request('customerId');
if (!empty($customer_id)) {
$where['id_users_customer'] = $customer_id;
}
$appointments = empty($keyword)
? $this->appointments_model->get($where, $limit, $offset, $order_by)
: $this->appointments_model->search($keyword, $limit, $offset, $order_by);
foreach ($appointments as &$appointment) {
$this->appointments_model->api_encode($appointment);
$this->aggregates($appointment);
if (!empty($fields)) {
$this->appointments_model->only($appointment, $fields);
}
if (!empty($with)) {
$this->appointments_model->load($appointment, $with);
}
}
json_response($appointments);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Load the relations of the current appointment if the "aggregates" query parameter is present.
*
* This is a compatibility addition to the appointment resource which was the only one to support it.
*
* Use the "attach" query parameter instead as this one will be removed.
*
* @param array $appointment Appointment data.
*
* @deprecated Since 1.5
*/
private function aggregates(array &$appointment): void
{
$aggregates = request('aggregates') !== null;
if ($aggregates) {
$appointment['service'] = $this->services_model->find(
$appointment['id_services'] ?? ($appointment['serviceId'] ?? null),
);
$appointment['provider'] = $this->providers_model->find(
$appointment['id_users_provider'] ?? ($appointment['providerId'] ?? null),
);
$appointment['customer'] = $this->customers_model->find(
$appointment['id_users_customer'] ?? ($appointment['customerId'] ?? null),
);
$this->services_model->api_encode($appointment['service']);
$this->providers_model->api_encode($appointment['provider']);
$this->customers_model->api_encode($appointment['customer']);
}
}
/**
* Get a single appointment.
*
* @param int|null $id Appointment ID.
*/
public function show(?int $id = null): void
{
try {
$occurrences = $this->appointments_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$appointment = $this->appointments_model->find($id);
$this->appointments_model->api_encode($appointment);
if (!empty($fields)) {
$this->appointments_model->only($appointment, $fields);
}
if (!empty($with)) {
$this->appointments_model->load($appointment, $with);
}
json_response($appointment);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Store a new appointment.
*/
public function store(): void
{
try {
$appointment = request();
$this->appointments_model->api_decode($appointment);
if (array_key_exists('id', $appointment)) {
unset($appointment['id']);
}
if (!array_key_exists('end_datetime', $appointment)) {
$appointment['end_datetime'] = $this->calculate_end_datetime($appointment);
}
$appointment_id = $this->appointments_model->save($appointment);
$created_appointment = $this->appointments_model->find($appointment_id);
$this->notify_and_sync_appointment($created_appointment);
$this->appointments_model->api_encode($created_appointment);
json_response($created_appointment, 201);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Calculate the end date time of an appointment based on the selected service.
*
* @param array $appointment Appointment data.
*
* @return string Returns the end date time value.
*
* @throws Exception
*/
private function calculate_end_datetime(array $appointment): string
{
$duration = $this->services_model->value($appointment['id_services'], 'duration');
$end = new DateTime($appointment['start_datetime']);
$end->add(new DateInterval('PT' . $duration . 'M'));
return $end->format('Y-m-d H:i:s');
}
/**
* Send the required notifications and trigger syncing after saving an appointment.
*
* @param array $appointment Appointment data.
* @param string $action Performed action ("store" or "update").
*/
private function notify_and_sync_appointment(array $appointment, string $action = 'store'): void
{
$manage_mode = $action === 'update';
$service = $this->services_model->find($appointment['id_services']);
$provider = $this->providers_model->find($appointment['id_users_provider']);
$customer = $this->customers_model->find($appointment['id_users_customer']);
$company_color = setting('company_color');
$settings = [
'company_name' => setting('company_name'),
'company_email' => setting('company_email'),
'company_link' => setting('company_link'),
'company_color' => !empty($company_color) && $company_color != DEFAULT_COMPANY_COLOR ? $company_color : null,
'date_format' => setting('date_format'),
'time_format' => setting('time_format'),
];
$this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings);
$this->notifications->notify_appointment_saved(
$appointment,
$service,
$provider,
$customer,
$settings,
$manage_mode,
);
}
/**
* Update an appointment.
*
* @param int $id Appointment ID.
*/
public function update(int $id): void
{
try {
$occurrences = $this->appointments_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$original_appointment = $occurrences[0];
$appointment = request();
$this->appointments_model->api_decode($appointment, $original_appointment);
$appointment_id = $this->appointments_model->save($appointment);
$updated_appointment = $this->appointments_model->find($appointment_id);
$this->notify_and_sync_appointment($updated_appointment, 'update');
$this->appointments_model->api_encode($updated_appointment);
json_response($updated_appointment);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete an appointment.
*
* @param int $id Appointment ID.
*/
public function destroy(int $id): void
{
try {
$occurrences = $this->appointments_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$deleted_appointment = $occurrences[0];
$service = $this->services_model->find($deleted_appointment['id_services']);
$provider = $this->providers_model->find($deleted_appointment['id_users_provider']);
$customer = $this->customers_model->find($deleted_appointment['id_users_customer']);
$company_color = setting('company_color');
$settings = [
'company_name' => setting('company_name'),
'company_email' => setting('company_email'),
'company_link' => setting('company_link'),
'company_color' => !empty($company_color) && $company_color != DEFAULT_COMPANY_COLOR ? $company_color : null,
'date_format' => setting('date_format'),
'time_format' => setting('time_format'),
];
$this->appointments_model->delete($id);
$this->synchronization->sync_appointment_deleted($deleted_appointment, $provider);
$this->notifications->notify_appointment_deleted(
$deleted_appointment,
$service,
$provider,
$customer,
$settings,
);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,81 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Availabilities API v1 controller.
*
* @package Controllers
*/
class Availabilities_api_v1 extends EA_Controller
{
/**
* Availabilities_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('api');
$this->api->auth();
$this->load->model('appointments_model');
$this->load->model('providers_model');
$this->load->model('services_model');
$this->load->model('settings_model');
$this->load->library('availability');
}
/**
* Generate the available hours based on the selected date, service and provider.
*
* This resource requires the following query parameters:
*
* - serviceId
* - providerI
* - date
*
* Based on those values it will generate the available hours, just like how the booking page works.
*
* You can then safely create a new appointment starting on one of the selected hours.
*
* Notice: The returned hours are in the provider's timezone.
*
* If no date parameter is provided then the current date will be used.
*/
public function get(): void
{
try {
$provider_id = request('providerId');
$service_id = request('serviceId');
$date = request('date');
if (!$date) {
$date = date('Y-m-d');
}
$provider = $this->providers_model->find($provider_id);
$service = $this->services_model->find($service_id);
$available_hours = $this->availability->get_available_hours($date, $service, $provider);
json_response($available_hours);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,190 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Customers API v1 controller.
*
* @package Controllers
*/
class Customers_api_v1 extends EA_Controller
{
/**
* Customers_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('api');
$this->api->auth();
$this->api->model('customers_model');
}
/**
* Get a customer collection.
*/
public function index(): void
{
try {
$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();
$with = $this->api->request_with();
$customers = empty($keyword)
? $this->customers_model->get(null, $limit, $offset, $order_by)
: $this->customers_model->search($keyword, $limit, $offset, $order_by);
foreach ($customers as &$customer) {
$this->customers_model->api_encode($customer);
if (!empty($fields)) {
$this->customers_model->only($customer, $fields);
}
if (!empty($with)) {
$this->customers_model->load($customer, $with);
}
}
json_response($customers);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Get a single customer.
*
* @param int|null $id Customer ID.
*/
public function show(?int $id = null): void
{
try {
$occurrences = $this->customers_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$fields = $this->api->request_fields();
$customer = $this->customers_model->find($id);
$this->customers_model->api_encode($customer);
if (!empty($fields)) {
$this->customers_model->only($customer, $fields);
}
json_response($customer);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Store a new customer.
*/
public function store(): void
{
try {
$customer = request();
$this->customers_model->api_decode($customer);
if (array_key_exists('id', $customer)) {
unset($customer['id']);
}
$customer_id = $this->customers_model->save($customer);
$created_customer = $this->customers_model->find($customer_id);
$this->customers_model->api_encode($created_customer);
json_response($created_customer, 201);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Update a customer.
*
* @param int $id Customer ID.
*/
public function update(int $id): void
{
try {
$occurrences = $this->customers_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$original_customer = $occurrences[0];
$customer = request();
$this->customers_model->api_decode($customer, $original_customer);
$customer_id = $this->customers_model->save($customer);
$updated_customer = $this->customers_model->find($customer_id);
$this->customers_model->api_encode($updated_customer);
json_response($updated_customer);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete a customer.
*
* @param int $id Customer ID.
*/
public function destroy(int $id): void
{
try {
$occurrences = $this->customers_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$this->customers_model->delete($id);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,212 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Providers API v1 controller.
*
* @package Controllers
*/
class Providers_api_v1 extends EA_Controller
{
/**
* Providers_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('api');
$this->api->auth();
$this->api->model('providers_model');
}
/**
* Get a provider collection.
*/
public function index(): void
{
try {
$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();
$with = $this->api->request_with();
$providers = empty($keyword)
? $this->providers_model->get(null, $limit, $offset, $order_by)
: $this->providers_model->search($keyword, $limit, $offset, $order_by);
foreach ($providers as &$provider) {
$this->providers_model->api_encode($provider);
if (!empty($fields)) {
$this->providers_model->only($provider, $fields);
}
if (!empty($with)) {
$this->providers_model->load($provider, $with);
}
}
json_response($providers);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Get a single provider.
*
* @param int|null $id Provider ID.
*/
public function show(?int $id = null): void
{
try {
$occurrences = $this->providers_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$provider = $this->providers_model->find($id);
$this->providers_model->api_encode($provider);
if (!empty($fields)) {
$this->providers_model->only($provider, $fields);
}
if (!empty($with)) {
$this->providers_model->load($provider, $with);
}
json_response($provider);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Store a new provider.
*/
public function store(): void
{
try {
$provider = request();
$this->providers_model->api_decode($provider);
if (array_key_exists('id', $provider)) {
unset($provider['id']);
}
if (!array_key_exists('services', $provider)) {
throw new InvalidArgumentException('No services property provided.');
}
if (!array_key_exists('settings', $provider)) {
throw new InvalidArgumentException('No settings property provided.');
}
if (!array_key_exists('working_plan', $provider['settings'])) {
$provider['settings']['working_plan'] = setting('company_working_plan');
}
if (!array_key_exists('working_plan_exceptions', $provider['settings'])) {
$provider['settings']['working_plan_exceptions'] = '{}';
}
$provider_id = $this->providers_model->save($provider);
$created_provider = $this->providers_model->find($provider_id);
$this->providers_model->api_encode($created_provider);
json_response($created_provider, 201);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Update a provider.
*
* @param int $id Provider ID.
*/
public function update(int $id): void
{
try {
$occurrences = $this->providers_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$original_provider = $occurrences[0];
$provider = request();
$this->providers_model->api_decode($provider, $original_provider);
$provider_id = $this->providers_model->save($provider);
$updated_provider = $this->providers_model->find($provider_id);
$this->providers_model->api_encode($updated_provider);
json_response($updated_provider);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete a provider.
*
* @param int $id Provider ID.
*/
public function destroy(int $id): void
{
try {
$occurrences = $this->providers_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$this->providers_model->delete($id);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,198 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Secretaries API v1 controller.
*
* @package Controllers
*/
class Secretaries_api_v1 extends EA_Controller
{
/**
* Secretaries_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('api');
$this->api->auth();
$this->api->model('secretaries_model');
}
/**
* Get a secretary collection.
*/
public function index(): void
{
try {
$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();
$with = $this->api->request_with();
$secretaries = empty($keyword)
? $this->secretaries_model->get(null, $limit, $offset, $order_by)
: $this->secretaries_model->search($keyword, $limit, $offset, $order_by);
foreach ($secretaries as &$secretary) {
$this->secretaries_model->api_encode($secretary);
if (!empty($fields)) {
$this->secretaries_model->only($secretary, $fields);
}
if (!empty($with)) {
$this->secretaries_model->load($secretary, $with);
}
}
json_response($secretaries);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Get a single secretary.
*
* @param int|null $id Secretary ID.
*/
public function show(?int $id = null): void
{
try {
$occurrences = $this->secretaries_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$fields = $this->api->request_fields();
$secretary = $this->secretaries_model->find($id);
$this->secretaries_model->api_encode($secretary);
if (!empty($fields)) {
$this->secretaries_model->only($secretary, $fields);
}
json_response($secretary);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Store a new secretary.
*/
public function store(): void
{
try {
$secretary = request();
$this->secretaries_model->api_decode($secretary);
if (array_key_exists('id', $secretary)) {
unset($secretary['id']);
}
if (!array_key_exists('providers', $secretary)) {
throw new InvalidArgumentException('No providers property provided.');
}
if (!array_key_exists('settings', $secretary)) {
throw new InvalidArgumentException('No settings property provided.');
}
$secretary_id = $this->secretaries_model->save($secretary);
$created_secretary = $this->secretaries_model->find($secretary_id);
$this->secretaries_model->api_encode($created_secretary);
json_response($created_secretary, 201);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Update a secretary.
*
* @param int $id Secretary ID.
*/
public function update(int $id): void
{
try {
$occurrences = $this->secretaries_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$original_secretary = $occurrences[0];
$secretary = request();
$this->secretaries_model->api_decode($secretary, $original_secretary);
$secretary_id = $this->secretaries_model->save($secretary);
$updated_secretary = $this->secretaries_model->find($secretary_id);
$this->secretaries_model->api_encode($updated_secretary);
json_response($updated_secretary);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete a secretary.
*
* @param int $id Secretary ID.
*/
public function destroy(int $id): void
{
try {
$occurrences = $this->secretaries_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$this->secretaries_model->delete($id);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,196 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Service-categories API v1 controller.
*
* @package Controllers
*/
class Service_categories_api_v1 extends EA_Controller
{
/**
* Service_categories_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('api');
$this->api->auth();
$this->api->model('service_categories_model');
}
/**
* Get a service-category collection.
*/
public function index(): void
{
try {
$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();
$with = $this->api->request_with();
$service_categories = empty($keyword)
? $this->service_categories_model->get(null, $limit, $offset, $order_by)
: $this->service_categories_model->search($keyword, $limit, $offset, $order_by);
foreach ($service_categories as &$service_category) {
$this->service_categories_model->api_encode($service_category);
if (!empty($fields)) {
$this->service_categories_model->only($service_category, $fields);
}
if (!empty($with)) {
$this->service_categories_model->load($service_category, $with);
}
}
json_response($service_categories);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Get a single service-category.
*
* @param int|null $id Service-category ID.
*/
public function show(?int $id = null): void
{
try {
$occurrences = $this->service_categories_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$service_category = $this->service_categories_model->find($id);
$this->service_categories_model->api_encode($service_category);
if (!empty($fields)) {
$this->service_categories_model->only($service_category, $fields);
}
if (!empty($with)) {
$this->service_categories_model->load($service_category, $with);
}
json_response($service_category);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Store a new service-category.
*/
public function store(): void
{
try {
$service_category = request();
$this->service_categories_model->api_decode($service_category);
if (array_key_exists('id', $service_category)) {
unset($service_category['id']);
}
$service_category_id = $this->service_categories_model->save($service_category);
$created_service_category = $this->service_categories_model->find($service_category_id);
$this->service_categories_model->api_encode($created_service_category);
json_response($created_service_category, 201);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Update a service-category.
*
* @param int $id Service-category ID.
*/
public function update(int $id): void
{
try {
$occurrences = $this->service_categories_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$original_category = $occurrences[0];
$service_category = request();
$this->service_categories_model->api_decode($service_category, $original_category);
$service_category_id = $this->service_categories_model->save($service_category);
$updated_service_category = $this->service_categories_model->find($service_category_id);
$this->service_categories_model->api_encode($updated_service_category);
json_response($updated_service_category);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete a service-category.
*
* @param int $id Service-category ID.
*/
public function destroy(int $id): void
{
try {
$occurrences = $this->service_categories_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$this->service_categories_model->delete($id);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,196 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Services API v1 controller.
*
* @package Controllers
*/
class Services_api_v1 extends EA_Controller
{
/**
* Services_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('api');
$this->api->auth();
$this->api->model('services_model');
}
/**
* Get a service collection.
*/
public function index(): void
{
try {
$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();
$with = $this->api->request_with();
$services = empty($keyword)
? $this->services_model->get(null, $limit, $offset, $order_by)
: $this->services_model->search($keyword, $limit, $offset, $order_by);
foreach ($services as &$service) {
$this->services_model->api_encode($service);
if (!empty($fields)) {
$this->services_model->only($service, $fields);
}
if (!empty($with)) {
$this->services_model->load($service, $with);
}
}
json_response($services);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Get a single service.
*
* @param int|null $id Service ID.
*/
public function show(?int $id = null): void
{
try {
$occurrences = $this->services_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$service = $this->services_model->find($id);
$this->services_model->api_encode($service);
if (!empty($fields)) {
$this->services_model->only($service, $fields);
}
if (!empty($with)) {
$this->services_model->load($service, $with);
}
json_response($service);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Store a new service.
*/
public function store(): void
{
try {
$service = request();
$this->services_model->api_decode($service);
if (array_key_exists('id', $service)) {
unset($service['id']);
}
$service_id = $this->services_model->save($service);
$created_service = $this->services_model->find($service_id);
$this->services_model->api_encode($created_service);
json_response($created_service, 201);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Update a service.
*
* @param int $id Service ID.
*/
public function update(int $id): void
{
try {
$occurrences = $this->services_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$original_service = $occurrences[0];
$service = request();
$this->services_model->api_decode($service, $original_service);
$service_id = $this->services_model->save($service);
$updated_service = $this->services_model->find($service_id);
$this->services_model->api_encode($updated_service);
json_response($updated_service);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete a service.
*
* @param int $id Service ID.
*/
public function destroy(int $id): void
{
try {
$occurrences = $this->services_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$this->services_model->delete($id);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,108 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Settings API v1 controller.
*
* @package Controllers
*/
class Settings_api_v1 extends EA_Controller
{
/**
* Settings_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('api');
$this->api->auth();
$this->api->model('settings_model');
}
/**
* Get a setting collection.
*/
public function index(): void
{
try {
$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();
$settings = empty($keyword)
? $this->settings_model->get(null, $limit, $offset, $order_by)
: $this->settings_model->search($keyword, $limit, $offset, $order_by);
foreach ($settings as &$setting) {
$this->settings_model->api_encode($setting);
if (!empty($fields)) {
$this->settings_model->only($setting, $fields);
}
}
json_response($settings);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Get a setting value by name.
*
* @param string $name Setting name.
*/
public function show(string $name): void
{
try {
$value = setting($name);
json_response([
'name' => $name,
'value' => $value,
]);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Set a setting value by name.
*
* @param string $name Setting name.
*/
public function update(string $name): void
{
try {
$value = request('value');
setting([$name => $value]);
json_response([
'name' => $name,
'value' => $value,
]);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,196 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Unavailabilities API v1 controller.
*
* @package Controllers
*/
class Unavailabilities_api_v1 extends EA_Controller
{
/**
* Unavailabilities_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('api');
$this->api->auth();
$this->api->model('unavailabilities_model');
}
/**
* Get an unavailability collection.
*/
public function index(): void
{
try {
$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();
$with = $this->api->request_with();
$unavailabilities = empty($keyword)
? $this->unavailabilities_model->get(null, $limit, $offset, $order_by)
: $this->unavailabilities_model->search($keyword, $limit, $offset, $order_by);
foreach ($unavailabilities as &$unavailability) {
$this->unavailabilities_model->api_encode($unavailability);
if (!empty($fields)) {
$this->unavailabilities_model->only($unavailability, $fields);
}
if (!empty($with)) {
$this->unavailabilities_model->load($unavailability, $with);
}
}
json_response($unavailabilities);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Get a single unavailability.
*
* @param int|null $id Unavailability ID.
*/
public function show(?int $id = null): void
{
try {
$occurrences = $this->unavailabilities_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$unavailability = $this->unavailabilities_model->find($id);
$this->unavailabilities_model->api_encode($unavailability);
if (!empty($fields)) {
$this->unavailabilities_model->only($unavailability, $fields);
}
if (!empty($with)) {
$this->unavailabilities_model->load($unavailability, $with);
}
json_response($unavailability);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Store a new unavailability.
*/
public function store(): void
{
try {
$unavailability = request();
$this->unavailabilities_model->api_decode($unavailability);
if (array_key_exists('id', $unavailability)) {
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);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Update an unavailability.
*
* @param int $id Unavailability ID.
*/
public function update(int $id): void
{
try {
$occurrences = $this->unavailabilities_model->get(['id' => $id]);
if (empty($occurrences)) {
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);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete an unavailability.
*
* @param int $id Unavailability ID.
*/
public function destroy(int $id): void
{
try {
$occurrences = $this->unavailabilities_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$this->unavailabilities_model->delete($id);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,196 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Webhooks API v1 controller.
*
* @package Controllers
*/
class Webhooks_api_v1 extends EA_Controller
{
/**
* Webhooks_api_v1 constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('api');
$this->api->auth();
$this->api->model('webhooks_model');
}
/**
* Get a webhook collection.
*/
public function index(): void
{
try {
$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();
$with = $this->api->request_with();
$webhooks = empty($keyword)
? $this->webhooks_model->get(null, $limit, $offset, $order_by)
: $this->webhooks_model->search($keyword, $limit, $offset, $order_by);
foreach ($webhooks as &$webhook) {
$this->webhooks_model->api_encode($webhook);
if (!empty($fields)) {
$this->webhooks_model->only($webhook, $fields);
}
if (!empty($with)) {
$this->webhooks_model->load($webhook, $with);
}
}
json_response($webhooks);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Get a single webhook.
*
* @param int|null $id Webhook ID.
*/
public function show(?int $id = null): void
{
try {
$occurrences = $this->webhooks_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$webhook = $this->webhooks_model->find($id);
$this->webhooks_model->api_encode($webhook);
if (!empty($fields)) {
$this->webhooks_model->only($webhook, $fields);
}
if (!empty($with)) {
$this->webhooks_model->load($webhook, $with);
}
json_response($webhook);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Store a new webhook.
*/
public function store(): void
{
try {
$webhook = request();
$this->webhooks_model->api_decode($webhook);
if (array_key_exists('id', $webhook)) {
unset($webhook['id']);
}
$webhook_id = $this->webhooks_model->save($webhook);
$created_webhook = $this->webhooks_model->find($webhook_id);
$this->webhooks_model->api_encode($created_webhook);
json_response($created_webhook, 201);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Update a webhook.
*
* @param int $id Webhook ID.
*/
public function update(int $id): void
{
try {
$occurrences = $this->webhooks_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$original_webhook = $occurrences[0];
$webhook = request();
$this->webhooks_model->api_decode($webhook, $original_webhook);
$webhook_id = $this->webhooks_model->save($webhook);
$updated_webhook = $this->webhooks_model->find($webhook_id);
$this->webhooks_model->api_encode($updated_webhook);
json_response($updated_webhook);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete a webhook.
*
* @param int $id Webhook ID.
*/
public function destroy(int $id): void
{
try {
$occurrences = $this->webhooks_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$this->webhooks_model->delete($id);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View File

@@ -0,0 +1,10 @@
<html lang="en">
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>