2017-09-15 14:36:37 +03:00
|
|
|
<?php
|
2016-07-09 10:02:25 +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 10:02:25 +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\Processors;
|
2016-07-09 10:02:25 +03:00
|
|
|
|
2016-07-10 11:59:39 +03:00
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Minimize Processor
|
2016-07-10 11:59:39 +03:00
|
|
|
*
|
|
|
|
* This processor will check for the "fields" GET parameters and provide only the required fields in
|
|
|
|
* every response entry. This might come in handy when the client needs specific information and not
|
2017-09-15 14:36:37 +03:00
|
|
|
* the whole objects.
|
2016-07-10 11:59:39 +03:00
|
|
|
*
|
2017-09-15 14:36:37 +03:00
|
|
|
* Make sure that the response parameter is a sequential array and not a single entry by the time this
|
2016-07-10 11:59:39 +03:00
|
|
|
* processor is executed.
|
|
|
|
*/
|
2016-07-09 14:14:08 +03:00
|
|
|
class Minimize implements ProcessorsInterface {
|
2016-07-10 11:59:39 +03:00
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Process Response Array
|
2016-07-10 11:59:39 +03:00
|
|
|
*
|
2017-09-15 14:36:37 +03:00
|
|
|
* Example:
|
2016-07-10 11:59:39 +03:00
|
|
|
* http://ea-installation.com/api/v1/appointments?fields=id,book,start,end
|
2017-09-15 14:36:37 +03:00
|
|
|
*
|
|
|
|
*
|
2016-07-10 11:59:39 +03:00
|
|
|
* @param array &$response The response array to be processed.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public static function process(array &$response)
|
|
|
|
{
|
|
|
|
if ( ! isset($_GET['fields']) || empty($response))
|
|
|
|
{
|
|
|
|
return;
|
2016-07-09 23:27:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$fields = explode(',', $_GET['fields']);
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$temporaryResponse = [];
|
2016-07-09 23:27:24 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($response as &$entry)
|
|
|
|
{
|
|
|
|
$temporaryEntry = [];
|
|
|
|
|
|
|
|
foreach ($fields as $field)
|
|
|
|
{
|
|
|
|
$field = trim($field);
|
|
|
|
if (isset($entry[$field]))
|
|
|
|
{
|
|
|
|
$temporaryEntry[$field] = $entry[$field];
|
2016-07-09 23:27:24 +03:00
|
|
|
}
|
2017-09-15 14:36:37 +03:00
|
|
|
}
|
|
|
|
|
2016-07-09 23:27:24 +03:00
|
|
|
$temporaryResponse[] = $temporaryEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $temporaryResponse;
|
2016-07-09 14:14:08 +03:00
|
|
|
}
|
2016-07-09 10:02:25 +03:00
|
|
|
}
|