2017-09-15 14:36:37 +03:00
|
|
|
<?php
|
2016-07-10 16:53:22 +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 16:53:22 +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 16:53:22 +03:00
|
|
|
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Admins Parser
|
2016-07-10 16:53:22 +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 16:53:22 +03:00
|
|
|
*/
|
|
|
|
class Admins implements ParsersInterface {
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Encode Response Array
|
|
|
|
*
|
2016-07-10 16:53:22 +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 = [
|
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 16:53:22 +03:00
|
|
|
'email' => $response['email'],
|
|
|
|
'mobile' => $response['mobile_number'],
|
|
|
|
'phone' => $response['phone_number'],
|
|
|
|
'address' => $response['address'],
|
|
|
|
'city' => $response['city'],
|
|
|
|
'state' => $response['state'],
|
|
|
|
'zip' => $response['zip_code'],
|
|
|
|
'notes' => $response['notes'],
|
2020-12-11 13:49:27 +03:00
|
|
|
'timezone' => $response['timezone'],
|
2016-07-10 16:53:22 +03:00
|
|
|
'settings' => [
|
|
|
|
'username' => $response['settings']['username'],
|
2016-07-19 00:51:15 +03:00
|
|
|
'notifications' => filter_var($response['settings']['notifications'], FILTER_VALIDATE_BOOLEAN),
|
|
|
|
'calendarView' => $response['settings']['calendar_view']
|
2016-07-10 16:53:22 +03:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$response = $encoded_response;
|
2016-07-10 16:53:22 +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 16:53:22 +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 16:53:22 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['id']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['id'] = $request['id'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['firstName']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['first_name'] = $request['firstName'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['lastName']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['last_name'] = $request['lastName'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['email']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['email'] = $request['email'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['mobile']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['mobile_number'] = $request['mobile'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['phone']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['phone_number'] = $request['phone'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['address']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['address'] = $request['address'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['city']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['city'] = $request['city'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['state']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['state'] = $request['state'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['zip']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['zip_code'] = $request['zip'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['notes']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['notes'] = $request['notes'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 13:49:27 +03:00
|
|
|
if ( ! empty($request['timezone']))
|
|
|
|
{
|
|
|
|
$decoded_request['timezone'] = $request['timezone'];
|
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['settings']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
if (empty($decoded_request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings'] = [];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['settings']['username']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['username'] = $request['settings']['username'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['settings']['password']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['password'] = $request['settings']['password'];
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($request['settings']['notifications'] !== NULL)
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['notifications'] = filter_var($request['settings']['notifications'],
|
2017-09-15 14:36:37 +03:00
|
|
|
FILTER_VALIDATE_BOOLEAN);
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
2016-07-19 00:51:15 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! empty($request['settings']['calendarView']))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['calendar_view'] = $request['settings']['calendarView'];
|
2016-07-19 00:51:15 +03:00
|
|
|
}
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$request = $decoded_request;
|
2016-07-10 16:53:22 +03:00
|
|
|
}
|
|
|
|
}
|