From cb125545c716ce61cc2f5ee050e32e35944d578e Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 11 Nov 2025 18:22:17 +0000 Subject: [PATCH] - WIP on search request handling of operators --- src/Adapter/SqlFieldMapper.php | 3 +- src/Entity/Mariadb/Column.php | 14 +++++++++ src/Entity/Mysql/Column.php | 8 ++--- src/SearchRequest/SearchRequest.php | 24 --------------- .../SearchRequestFromRequestTrait.php | 30 +++++++++++++++++++ src/SearchRequest/SearchRequestInterface.php | 10 +++++++ 6 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 src/Entity/Mariadb/Column.php diff --git a/src/Adapter/SqlFieldMapper.php b/src/Adapter/SqlFieldMapper.php index b1e45cd..e59efcb 100644 --- a/src/Adapter/SqlFieldMapper.php +++ b/src/Adapter/SqlFieldMapper.php @@ -47,7 +47,8 @@ class SqlFieldMapper break; case "array": - $this->type = "JSON"; + # Was set at JSON, but for now LONGTEXT is an alias of it (with additional constraints) + $this->type = "LONGTEXT"; break; case "string": diff --git a/src/Entity/Mariadb/Column.php b/src/Entity/Mariadb/Column.php new file mode 100644 index 0000000..a5ffce2 --- /dev/null +++ b/src/Entity/Mariadb/Column.php @@ -0,0 +1,14 @@ +wheres + [ - ], fn($i) => ! is_null($i) ) + [ ]; - } - - public function likes(): iterable - { - return array_filter($this->likes + [ - ], fn($i) => ! is_null($i) ) + []; - } - - public function groups(): iterable - { - return array_filter($this->groups + [ - ], fn($e) => ! is_null($e) && $e !== "" ); - } - - public function orders(): iterable - { - return array_filter($this->orders + [ - ], fn($e) => ! is_null($e) && $e !== "" ); - } - } \ No newline at end of file diff --git a/src/SearchRequest/SearchRequestFromRequestTrait.php b/src/SearchRequest/SearchRequestFromRequestTrait.php index 60fb46b..ad16b6c 100644 --- a/src/SearchRequest/SearchRequestFromRequestTrait.php +++ b/src/SearchRequest/SearchRequestFromRequestTrait.php @@ -199,6 +199,36 @@ trait SearchRequestFromRequestTrait return $this; } + /* [[ Boilerplates which are ready to be copied */ + public function wheres() : iterable + { + return array_filter($this->wheres + [ + + ], fn($i) => ! is_null($i) ) + [ ]; + } + + public function likes(): iterable + { + return array_filter($this->likes + [ + + ], fn($i) => ! is_null($i) ) + []; + } + + public function groups(): iterable + { + return array_filter($this->groups + [ + + ], fn($e) => ! is_null($e) && $e !== "" ); + } + + public function orders(): iterable + { + return array_filter($this->orders + [ + + ], fn($e) => ! is_null($e) && $e !== "" ); + } + /* ]] */ + protected function getValueFromSource(RequestInterface $request, string $propertyName, SearchParameter $attribute) : mixed { $queryParamName = $attribute->getParameters() ?: [ $propertyName ]; diff --git a/src/SearchRequest/SearchRequestInterface.php b/src/SearchRequest/SearchRequestInterface.php index b2ab579..afb597b 100644 --- a/src/SearchRequest/SearchRequestInterface.php +++ b/src/SearchRequest/SearchRequestInterface.php @@ -5,6 +5,16 @@ namespace Ulmus\SearchRequest; use Ulmus\Repository; interface SearchRequestInterface { + + /* HOW TO IMPLEMENT THIS !!? */ + public const SEARCH_REQUEST_OPERATORS = "searchRequest:operators"; + public const SEARCH_REQUEST_OPERATOR_EQUAL = "="; + public const SEARCH_REQUEST_OPERATOR_NOT_EQUAL = "!="; + public const SEARCH_REQUEST_OPERATOR_GREATER_THAN = ">"; + public const SEARCH_REQUEST_OPERATOR_GREATER_OR_EQUAL_THAN = ">="; + public const SEARCH_REQUEST_OPERATOR_SMALLER_THAN = "<"; + public const SEARCH_REQUEST_OPERATOR_SMALLER_OR_EQUAL_THAN = "<="; + public function filter(Repository $repository) : Repository; public function wheres() : iterable;