2017-09-15 14:36:37 +03:00
|
|
|
<?php
|
2016-07-10 15:17:29 +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 15:17:29 +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 15:17:29 +03:00
|
|
|
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Providers Parser
|
2016-07-10 15:17:29 +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 15:17:29 +03:00
|
|
|
*/
|
|
|
|
class Providers implements ParsersInterface {
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Encode Response Array
|
|
|
|
*
|
2016-07-10 15:17:29 +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-11-06 20:30:03 +03:00
|
|
|
'firstName' => $response['first_name'],
|
|
|
|
'lastName' => $response['last_name'],
|
2016-07-10 15:17:29 +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'],
|
2017-12-01 11:12:09 +03:00
|
|
|
];
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
if (array_key_exists('services', $response))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$encoded_response['services'] = $response['services'];
|
2017-12-01 11:12:09 +03:00
|
|
|
}
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
if (array_key_exists('settings', $response))
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$encoded_response['settings'] = [
|
2016-07-10 15:17:29 +03:00
|
|
|
'username' => $response['settings']['username'],
|
|
|
|
'notifications' => filter_var($response['settings']['notifications'], FILTER_VALIDATE_BOOLEAN),
|
2016-07-19 00:51:15 +03:00
|
|
|
'calendarView' => $response['settings']['calendar_view'],
|
2020-12-11 22:16:49 +03:00
|
|
|
'googleSync' => array_key_exists('google_sync', $response['settings'])
|
|
|
|
? filter_var($response['settings']['google_sync'], FILTER_VALIDATE_BOOLEAN)
|
|
|
|
: NULL,
|
|
|
|
'googleCalendar' => array_key_exists('google_calendar', $response['settings'])
|
|
|
|
? $response['settings']['google_calendar']
|
|
|
|
: NULL,
|
|
|
|
'googleToken' => array_key_exists('google_token', $response['settings'])
|
|
|
|
? $response['settings']['google_token']
|
|
|
|
: NULL,
|
|
|
|
'syncFutureDays' => array_key_exists('sync_future_days', $response['settings'])
|
|
|
|
? (int)$response['settings']['sync_future_days']
|
|
|
|
: NULL,
|
|
|
|
'syncPastDays' => array_key_exists('sync_past_days', $response['settings'])
|
|
|
|
? (int)$response['settings']['sync_past_days']
|
|
|
|
: NULL,
|
|
|
|
'workingPlan' => array_key_exists('working_plan', $response['settings'])
|
|
|
|
? json_decode($response['settings']['working_plan'], TRUE)
|
|
|
|
: NULL,
|
|
|
|
'workingPlanExceptions' => array_key_exists('working_plan_exceptions', $response['settings'])
|
|
|
|
? json_decode($response['settings']['working_plan_exceptions'], TRUE)
|
|
|
|
: NULL,
|
2017-12-01 11:12:09 +03:00
|
|
|
];
|
|
|
|
}
|
2016-07-10 15:17:29 +03:00
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$response = $encoded_response;
|
2016-07-10 15:17:29 +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 15:17:29 +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 15:17:29 +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 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('firstName', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['first_name'] = $request['firstName'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('lastName', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['last_name'] = $request['lastName'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('email', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['email'] = $request['email'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('mobile', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['mobile_number'] = $request['mobile'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('phone', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['phone_number'] = $request['phone'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('address', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['address'] = $request['address'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('city', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['city'] = $request['city'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('state', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['state'] = $request['state'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('zip', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['zip_code'] = $request['zip'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('notes', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['notes'] = $request['notes'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('timezone', $request))
|
2020-12-11 13:49:27 +03:00
|
|
|
{
|
|
|
|
$decoded_request['timezone'] = $request['timezone'];
|
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('services', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['services'] = $request['services'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('settings', $request))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
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 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('username', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['username'] = $request['settings']['username'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('password', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['password'] = $request['settings']['password'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('calendarView', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['calendar_view'] = $request['settings']['calendarView'];
|
2016-07-19 00:51:15 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('notifications', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
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 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('googleSync', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['google_sync'] = filter_var($request['settings']['googleSync'],
|
2017-09-15 14:36:37 +03:00
|
|
|
FILTER_VALIDATE_BOOLEAN);
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('googleCalendar', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['google_calendar'] = $request['settings']['googleCalendar'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('googleToken', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['google_token'] = $request['settings']['googleToken'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('syncFutureDays', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['sync_future_days'] = $request['settings']['syncFutureDays'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('syncPastDays', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['sync_past_days'] = $request['settings']['syncPastDays'];
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('workingPlan', $request['settings']))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['working_plan'] = json_encode($request['settings']['workingPlan']);
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2020-12-11 22:16:49 +03:00
|
|
|
if (array_key_exists('workingPlanExceptions', $request['settings']))
|
2020-10-20 16:03:48 +03:00
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$decoded_request['settings']['working_plan_exceptions'] = json_encode($request['settings']['workingPlanExceptions']);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$request = $decoded_request;
|
2016-07-10 15:17:29 +03:00
|
|
|
}
|
|
|
|
}
|