2017-09-15 14:36:37 +03:00
|
|
|
<?php
|
2016-07-10 17:26:02 +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
|
2016-07-10 17:26:02 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.2.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
namespace EA\Engine\Api\V1\Parsers;
|
2016-07-10 17:26:02 +03:00
|
|
|
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Unavailabilities Parser
|
2016-07-10 17:26:02 +03:00
|
|
|
*
|
2017-09-15 14:36:37 +03:00
|
|
|
* This class will handle the encoding and decoding from the API requests.
|
2020-05-12 21:49:15 +03:00
|
|
|
*
|
|
|
|
* @deprecated
|
2016-07-10 17:26:02 +03:00
|
|
|
*/
|
|
|
|
class Unavailabilities implements ParsersInterface {
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Encode Response Array
|
|
|
|
*
|
2016-07-10 17:26:02 +03:00
|
|
|
* @param array &$response The response to be encoded.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function encode(array &$response)
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$encoded_response = [
|
2020-12-11 22:16:49 +03:00
|
|
|
'id' => array_key_exists('id', $response) ? (int)$response['id'] : NULL,
|
2016-07-10 17:26:02 +03:00
|
|
|
'book' => $response['book_datetime'],
|
|
|
|
'start' => $response['start_datetime'],
|
|
|
|
'end' => $response['end_datetime'],
|
|
|
|
'notes' => $response['notes'],
|
2020-12-11 22:16:49 +03:00
|
|
|
'providerId' => array_key_exists('id_users_provider', $response)
|
|
|
|
? (int)$response['id_users_provider']
|
|
|
|
: NULL,
|
|
|
|
'googleCalendarId' => array_key_exists('id_google_calendar', $response)
|
|
|
|
? (int)$response['id_google_calendar']
|
|
|
|
: NULL
|
2016-07-10 17:26:02 +03:00
|
|
|
];
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$response = $encoded_response;
|
2016-07-10 17:26:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Decode Request
|
|
|
|
*
|
|
|
|
* @param array &$request The request to be decoded.
|
|
|
|
* @param array $base Optional (null), if provided it will be used as a base array.
|
2016-07-10 17:26:02 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function decode(array &$request, array $base = NULL)
|
|
|
|
{
|
|
|
|
$decodedRequest = $base ?: [];
|
2016-07-10 17:26:02 +03:00
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('id', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
$decodedRequest['id'] = $request['id'];
|
2016-07-10 17:26:02 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('book', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
$decodedRequest['book_datetime'] = $request['book'];
|
2016-07-10 17:26:02 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('start', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
$decodedRequest['start_datetime'] = $request['start'];
|
2016-07-10 17:26:02 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('end', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
$decodedRequest['end_datetime'] = $request['end'];
|
2016-07-10 17:26:02 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('notes', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
$decodedRequest['notes'] = $request['notes'];
|
2016-07-10 17:26:02 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('providerId', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
$decodedRequest['id_users_provider'] = $request['providerId'];
|
2016-07-10 17:26:02 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('googleCalendarId', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
|
|
|
$decodedRequest['id_google_calendar'] = $request['googleCalendarId'];
|
2016-07-10 17:26:02 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$decodedRequest['is_unavailable'] = TRUE;
|
2016-07-10 17:26:02 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$request = $decodedRequest;
|
2016-07-10 17:26:02 +03:00
|
|
|
}
|
|
|
|
}
|