mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-26 01:43:06 +03:00
Implemented search processor.
This commit is contained in:
parent
4a8111566d
commit
f2e1af7cb4
1 changed files with 26 additions and 1 deletions
|
@ -15,6 +15,31 @@ namespace EA\Engine\Api\V1\Processors;
|
||||||
|
|
||||||
class Search implements ProcessorsInterface {
|
class Search implements ProcessorsInterface {
|
||||||
public static function process(array &$response) {
|
public static function process(array &$response) {
|
||||||
|
if (!isset($_GET['q'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$searchedResponse = [];
|
||||||
|
$keyword = (string)$_GET['q'];
|
||||||
|
|
||||||
|
foreach ($response as $entry) {
|
||||||
|
if (self::_recursiveArraySearch($entry, $keyword) !== false) {
|
||||||
|
$searchedResponse[] = $entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $searchedResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function _recursiveArraySearch(array $haystack, $needle) {
|
||||||
|
foreach ($haystack as $key => $value) {
|
||||||
|
$currentKey = $key;
|
||||||
|
|
||||||
|
if ($needle === $value || (is_array($value) && self::_recursiveArraySearch($value, $needle) !== false)) {
|
||||||
|
return $currentKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue