2017-09-15 14:36:37 +03:00
|
|
|
<?php
|
2016-07-10 13:52:21 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2017-01-31 09:35:34 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2017, Alex Tselegidis
|
2016-07-10 13:52:21 +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 13:52:21 +03:00
|
|
|
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Customers Parser
|
2016-07-10 13:52:21 +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 13:52:21 +03:00
|
|
|
*/
|
|
|
|
class Customers implements ParsersInterface {
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Encode Response Array
|
|
|
|
*
|
2016-07-10 13:52:21 +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-10 13:52:21 +03:00
|
|
|
$encodedResponse = [
|
2017-09-15 14:36:37 +03:00
|
|
|
'id' => $response['id'] !== NULL ? (int)$response['id'] : NULL,
|
2016-11-06 20:30:03 +03:00
|
|
|
'firstName' => $response['first_name'],
|
|
|
|
'lastName' => $response['last_name'],
|
2016-07-10 13:52:21 +03:00
|
|
|
'email' => $response['email'],
|
|
|
|
'phone' => $response['phone_number'],
|
|
|
|
'address' => $response['address'],
|
|
|
|
'city' => $response['city'],
|
|
|
|
'zip' => $response['zip_code'],
|
|
|
|
'notes' => $response['notes']
|
|
|
|
];
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$response = $encodedResponse;
|
2016-07-10 13:52:21 +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 13:52:21 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function decode(array &$request, array $base = NULL)
|
|
|
|
{
|
|
|
|
$decodedRequest = $base ?: [];
|
2016-07-10 13:52:21 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['id']))
|
|
|
|
{
|
|
|
|
$decodedRequest['id'] = $request['id'];
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['firstName']))
|
|
|
|
{
|
2016-11-06 20:30:03 +03:00
|
|
|
$decodedRequest['first_name'] = $request['firstName'];
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['lastName']))
|
|
|
|
{
|
2016-11-06 20:30:03 +03:00
|
|
|
$decodedRequest['last_name'] = $request['lastName'];
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['email']))
|
|
|
|
{
|
|
|
|
$decodedRequest['email'] = $request['email'];
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['phone']))
|
|
|
|
{
|
|
|
|
$decodedRequest['phone_number'] = $request['phone'];
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['address']))
|
|
|
|
{
|
|
|
|
$decodedRequest['address'] = $request['address'];
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['city']))
|
|
|
|
{
|
|
|
|
$decodedRequest['city'] = $request['city'];
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['zip']))
|
|
|
|
{
|
|
|
|
$decodedRequest['zip_code'] = $request['zip'];
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['notes']))
|
|
|
|
{
|
|
|
|
$decodedRequest['notes'] = $request['notes'];
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$request = $decodedRequest;
|
2016-07-10 13:52:21 +03:00
|
|
|
}
|
|
|
|
}
|