2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2016-07-19 10:52:20 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2016-07-19 10:52:20 +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
|
2021-11-06 17:03:08 +03:00
|
|
|
* @since v1.5.0
|
2016-07-19 10:52:20 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2021-11-06 17:03:08 +03:00
|
|
|
* Availabilities API v1 controller.
|
2016-07-19 10:52:20 +03:00
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
class Availabilities_api_v1 extends EA_Controller
|
|
|
|
{
|
2016-07-19 10:52:20 +03:00
|
|
|
/**
|
2021-11-06 17:03:08 +03:00
|
|
|
* Availabilities_api_v1 constructor.
|
2016-07-19 10:52:20 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-07-19 10:52:20 +03:00
|
|
|
parent::__construct();
|
2021-11-06 17:03:08 +03:00
|
|
|
|
2023-04-24 14:22:49 +03:00
|
|
|
$this->load->library('api');
|
|
|
|
|
|
|
|
$this->api->auth();
|
2023-11-29 12:24:09 +03:00
|
|
|
|
2016-07-19 10:52:20 +03:00
|
|
|
$this->load->model('appointments_model');
|
|
|
|
$this->load->model('providers_model');
|
2016-07-21 23:36:17 +03:00
|
|
|
$this->load->model('services_model');
|
2016-07-19 10:52:20 +03:00
|
|
|
$this->load->model('settings_model');
|
2021-11-06 17:03:08 +03:00
|
|
|
|
2021-01-27 15:40:01 +03:00
|
|
|
$this->load->library('availability');
|
2016-07-19 10:52:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-06 17:03:08 +03:00
|
|
|
* 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.
|
2016-07-19 10:52:20 +03:00
|
|
|
*
|
2021-11-06 17:03:08 +03:00
|
|
|
* If no date parameter is provided then the current date will be used.
|
2016-07-19 10:52:20 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function get()
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
try {
|
2021-10-28 15:01:27 +03:00
|
|
|
$provider_id = request('providerId');
|
2016-07-19 10:52:20 +03:00
|
|
|
|
2021-10-28 15:01:27 +03:00
|
|
|
$service_id = request('serviceId');
|
2016-07-19 10:52:20 +03:00
|
|
|
|
2021-10-28 15:01:27 +03:00
|
|
|
$date = request('date');
|
2016-07-19 10:52:20 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!$date) {
|
2021-01-27 15:40:01 +03:00
|
|
|
$date = date('Y-m-d');
|
2016-07-21 23:36:17 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:27 +03:00
|
|
|
$provider = $this->providers_model->find($provider_id);
|
2018-01-02 14:55:52 +03:00
|
|
|
|
2021-10-28 15:01:27 +03:00
|
|
|
$service = $this->services_model->find($service_id);
|
2018-01-02 14:55:52 +03:00
|
|
|
|
2021-01-27 15:40:01 +03:00
|
|
|
$available_hours = $this->availability->get_available_hours($date, $service, $provider);
|
2018-01-02 14:55:52 +03:00
|
|
|
|
2021-11-06 17:03:08 +03:00
|
|
|
json_response($available_hours);
|
2023-11-29 12:24:09 +03:00
|
|
|
} catch (Throwable $e) {
|
2021-11-06 17:03:08 +03:00
|
|
|
json_exception($e);
|
2016-07-19 10:52:20 +03:00
|
|
|
}
|
2016-07-21 23:36:17 +03:00
|
|
|
}
|
2016-07-19 10:52:20 +03:00
|
|
|
}
|