2017-09-15 14:36:37 +03:00
|
|
|
<?php
|
2016-07-10 14:23:04 +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 14:23:04 +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 14:23:04 +03:00
|
|
|
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Services Parser
|
2016-07-10 14:23:04 +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 14:23:04 +03:00
|
|
|
*/
|
|
|
|
class Services implements ParsersInterface {
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Encode Response Array
|
|
|
|
*
|
2016-07-10 14:23:04 +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 14:23:04 +03:00
|
|
|
'name' => $response['name'],
|
2016-07-21 22:00:38 +03:00
|
|
|
'duration' => (int)$response['duration'],
|
|
|
|
'price' => (float)$response['price'],
|
2016-07-10 14:23:04 +03:00
|
|
|
'currency' => $response['currency'],
|
|
|
|
'description' => $response['description'],
|
2019-06-08 18:03:32 +03:00
|
|
|
'location' => $response['location'],
|
2016-07-20 22:24:00 +03:00
|
|
|
'availabilitiesType' => $response['availabilities_type'],
|
2016-07-21 22:00:38 +03:00
|
|
|
'attendantsNumber' => (int)$response['attendants_number'],
|
2017-09-15 14:36:37 +03:00
|
|
|
'categoryId' => $response['id_service_categories'] !== NULL ? (int)$response['id_service_categories'] : NULL
|
2016-07-10 14:23:04 +03:00
|
|
|
];
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$response = $encoded_response;
|
2016-07-10 14:23:04 +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 14:23:04 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function decode(array &$request, array $base = NULL)
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request = $base ?: [];
|
2016-07-10 14:23:04 +03:00
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('id', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['id'] = $request['id'];
|
2016-07-10 14:23:04 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('name', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['name'] = $request['name'];
|
2016-07-10 14:23:04 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('duration', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['duration'] = $request['duration'];
|
2016-07-10 14:23:04 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('price', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['price'] = $request['price'];
|
2016-07-10 14:23:04 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('currency', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['currency'] = $request['currency'];
|
2016-07-10 14:23:04 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('description', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['description'] = $request['description'];
|
2016-07-10 14:23:04 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('location', $request))
|
2019-06-08 18:03:32 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['location'] = $request['location'];
|
2019-06-08 18:03:32 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('availabilitiesType', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['availabilities_type'] = $request['availabilitiesType'];
|
2016-07-20 22:24:00 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('attendantsNumber', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['attendants_number'] = $request['attendantsNumber'];
|
2016-07-21 22:00:38 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('categoryId', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['id_service_categories'] = $request['categoryId'];
|
2016-07-10 14:23:04 +03:00
|
|
|
}
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$request = $decoded_request;
|
2016-07-10 14:23:04 +03:00
|
|
|
}
|
|
|
|
}
|