2017-09-15 14:36:37 +03:00
|
|
|
<?php
|
2016-07-09 22:53:28 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2018-03-27 10:23:09 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
2016-07-09 22:53:28 +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-09 22:53:28 +03:00
|
|
|
|
2016-07-10 11:59:39 +03:00
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Appointments Parser
|
2016-07-10 11:59:39 +03:00
|
|
|
*
|
2017-09-15 14:36:37 +03:00
|
|
|
* This class will handle the encoding and decoding from the API requests.
|
2016-07-10 11:59:39 +03:00
|
|
|
*/
|
2016-07-09 22:53:28 +03:00
|
|
|
class Appointments implements ParsersInterface {
|
2016-07-10 11:59:39 +03:00
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Encode Response Array
|
|
|
|
*
|
2016-07-10 11:59:39 +03:00
|
|
|
* @param array &$response The response to be encoded.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function encode(array &$response)
|
|
|
|
{
|
2016-07-09 22:53:28 +03:00
|
|
|
$encodedResponse = [
|
2017-09-15 14:36:37 +03:00
|
|
|
'id' => $response['id'] !== NULL ? (int)$response['id'] : NULL,
|
2016-07-09 22:53:28 +03:00
|
|
|
'book' => $response['book_datetime'],
|
|
|
|
'start' => $response['start_datetime'],
|
|
|
|
'end' => $response['end_datetime'],
|
|
|
|
'hash' => $response['hash'],
|
|
|
|
'notes' => $response['notes'],
|
2017-09-15 14:36:37 +03:00
|
|
|
'customerId' => $response['id_users_customer'] !== NULL ? (int)$response['id_users_customer'] : NULL,
|
|
|
|
'providerId' => $response['id_users_provider'] !== NULL ? (int)$response['id_users_provider'] : NULL,
|
|
|
|
'serviceId' => $response['id_services'] !== NULL ? (int)$response['id_services'] : NULL,
|
|
|
|
'googleCalendarId' => $response['id_google_calendar'] !== NULL ? (int)$response['id_google_calendar'] : NULL
|
2016-07-09 22:53:28 +03:00
|
|
|
];
|
|
|
|
|
2018-04-09 13:06:48 +03:00
|
|
|
if (isset($response['provider']))
|
2018-01-23 12:08:37 +03:00
|
|
|
{
|
2017-12-01 11:12:09 +03:00
|
|
|
$providerParser = new Providers();
|
|
|
|
$providerParser->encode($response['provider']);
|
2018-01-23 12:08:37 +03:00
|
|
|
$encodedResponse['provider'] = $response['provider'];
|
2017-12-01 11:12:09 +03:00
|
|
|
}
|
|
|
|
|
2018-04-09 13:06:48 +03:00
|
|
|
if (isset($response['customer']))
|
2018-01-23 12:08:37 +03:00
|
|
|
{
|
2017-12-01 11:12:09 +03:00
|
|
|
$customerParser = new Customers();
|
|
|
|
$customerParser->encode($response['customer']);
|
2018-01-23 12:08:37 +03:00
|
|
|
$encodedResponse['customer'] = $response['customer'];
|
2017-12-01 11:12:09 +03:00
|
|
|
}
|
|
|
|
|
2018-04-09 13:06:48 +03:00
|
|
|
if (isset($response['service']))
|
2018-01-23 12:08:37 +03:00
|
|
|
{
|
2017-12-01 11:12:09 +03:00
|
|
|
$serviceParser = new Services();
|
|
|
|
$serviceParser->encode($response['service']);
|
2018-01-23 12:08:37 +03:00
|
|
|
$encodedResponse['service'] = $response['service'];
|
2017-12-01 11:12:09 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$response = $encodedResponse;
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2016-07-10 11:59:39 +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 11:59:39 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function decode(array &$request, array $base = NULL)
|
|
|
|
{
|
|
|
|
$decodedRequest = $base ?: [];
|
2016-07-09 22:53:28 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['id']))
|
|
|
|
{
|
|
|
|
$decodedRequest['id'] = $request['id'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['book']))
|
|
|
|
{
|
|
|
|
$decodedRequest['book_datetime'] = $request['book'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['start']))
|
|
|
|
{
|
|
|
|
$decodedRequest['start_datetime'] = $request['start'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['end']))
|
|
|
|
{
|
|
|
|
$decodedRequest['end_datetime'] = $request['end'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['hash']))
|
|
|
|
{
|
|
|
|
$decodedRequest['hash'] = $request['hash'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['notes']))
|
|
|
|
{
|
|
|
|
$decodedRequest['notes'] = $request['notes'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['customerId']))
|
|
|
|
{
|
|
|
|
$decodedRequest['id_users_customer'] = $request['customerId'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['providerId']))
|
|
|
|
{
|
|
|
|
$decodedRequest['id_users_provider'] = $request['providerId'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['serviceId']))
|
|
|
|
{
|
|
|
|
$decodedRequest['id_services'] = $request['serviceId'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['googleCalendarId']))
|
|
|
|
{
|
|
|
|
$decodedRequest['id_google_calendar'] = $request['googleCalendarId'];
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$decodedRequest['is_unavailable'] = FALSE;
|
2016-07-09 22:53:28 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$request = $decodedRequest;
|
2016-07-09 22:53:28 +03:00
|
|
|
}
|
|
|
|
}
|