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>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, 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
|
|
|
/**
|
|
|
|
* Search Processor
|
|
|
|
*
|
|
|
|
* This class will search the response with the "q" GET parameter and only provide the entries
|
2017-09-15 14:36:37 +03:00
|
|
|
* that match the keyword. Make sure that the response parameter is a sequential array and not
|
2016-07-10 11:59:39 +03:00
|
|
|
* a single entry by the time this processor is executed.
|
2020-05-12 21:49:15 +03:00
|
|
|
*
|
|
|
|
* @deprecated
|
2016-07-10 11:59:39 +03:00
|
|
|
*/
|
2016-07-09 14:14:08 +03:00
|
|
|
class Search implements ProcessorsInterface {
|
2016-07-10 11:59:39 +03:00
|
|
|
/**
|
|
|
|
* Process Response Array
|
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['q']) || empty($response))
|
|
|
|
{
|
2016-07-09 23:43:31 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$searchedResponse = [];
|
|
|
|
$keyword = (string)$_GET['q'];
|
2016-07-09 23:43:31 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($response as $entry)
|
|
|
|
{
|
|
|
|
if (self::_recursiveArraySearch($entry, $keyword) !== FALSE)
|
|
|
|
{
|
2016-07-09 23:43:31 +03:00
|
|
|
$searchedResponse[] = $entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $searchedResponse;
|
|
|
|
}
|
|
|
|
|
2016-07-10 11:59:39 +03:00
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Recursive Array Search
|
|
|
|
*
|
|
|
|
* @param array $haystack Array to search in.
|
2016-07-10 11:59:39 +03:00
|
|
|
* @param string $needle Keyword to be searched.
|
2017-09-15 14:36:37 +03:00
|
|
|
*
|
2016-11-06 20:30:03 +03:00
|
|
|
* @return int|bool Returns the index of the search occurrence or false it nothing was found.
|
2016-07-10 11:59:39 +03:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
protected static function _recursiveArraySearch(array $haystack, $needle)
|
|
|
|
{
|
|
|
|
foreach ($haystack as $key => $value)
|
|
|
|
{
|
2016-07-09 23:43:31 +03:00
|
|
|
$currentKey = $key;
|
|
|
|
|
2020-03-27 12:20:41 +03:00
|
|
|
if (is_array($value) && self::_recursiveArraySearch($value, $needle) !== FALSE)
|
|
|
|
{
|
|
|
|
return $currentKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_string($value) && stripos($value, $needle) !== FALSE)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2016-07-09 23:43:31 +03:00
|
|
|
return $currentKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
return FALSE;
|
2016-07-09 14:14:08 +03:00
|
|
|
}
|
2016-07-09 10:02:25 +03:00
|
|
|
}
|