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
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
2020-11-14 22:36:25 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2016-07-19 10:52:20 +03:00
|
|
|
* @since v1.2.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
require_once __DIR__ . '/API_V1_Controller.php';
|
|
|
|
require_once __DIR__ . '/../../Appointments.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Availabilities Controller
|
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
|
|
|
class Availabilities extends API_V1_Controller {
|
|
|
|
/**
|
|
|
|
* Class Constructor
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-07-19 10:52:20 +03:00
|
|
|
parent::__construct();
|
|
|
|
$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-01-27 15:40:01 +03:00
|
|
|
$this->load->library('availability');
|
2016-07-19 10:52:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GET API Method
|
|
|
|
*
|
|
|
|
* Provide the "providerId", "serviceId" and "date" GET parameters to get the availabilities for a specific date.
|
|
|
|
* If no "date" was provided then the current date will be used.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function get()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2021-01-27 15:40:01 +03:00
|
|
|
if ( ! $date)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
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
|
|
|
|
2016-07-19 10:52:20 +03:00
|
|
|
$this->output
|
2016-07-21 23:36:17 +03:00
|
|
|
->set_content_type('application/json')
|
2020-10-21 21:49:05 +03:00
|
|
|
->set_output(json_encode($available_hours));
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:27 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-01-27 15:40:01 +03:00
|
|
|
$this->handle_exception($exception);
|
2016-07-19 10:52:20 +03:00
|
|
|
}
|
2016-07-21 23:36:17 +03:00
|
|
|
}
|
2016-07-19 10:52:20 +03:00
|
|
|
}
|