From 513a3d9fc7919112966e84747b249833d1e4a4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20de=20la=20Pen=CC=83a?=
Date: Tue, 26 Nov 2024 10:14:42 +0000 Subject: [PATCH] feat: Provide opportunity to alter search term --- src/Common/Traits/Model/Searchable.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Common/Traits/Model/Searchable.php b/src/Common/Traits/Model/Searchable.php index 1c178bcc..8660c3a4 100644 --- a/src/Common/Traits/Model/Searchable.php +++ b/src/Common/Traits/Model/Searchable.php @@ -82,6 +82,13 @@ public function getSearchKey(): string // -------------------------------------------------------------------------- + public function getSearchTerm(array $aData): string + { + return (string) ($aData[$this->getSearchKey()] ?? ''); + } + + // -------------------------------------------------------------------------- + /** * Searches for objects, optionally paginated. * @@ -123,12 +130,14 @@ public function search($sKeywords, $iPage = null, $iPerPage = null, array $aData */ protected function applySearchConditionals(array &$aData): self { - $sKey = $this->getSearchKey(); - if (empty($aData[$sKey])) { + $sKeywords = $this->getSearchTerm($aData); + if (empty($sKeywords)) { return $this; } - $sKeywords = $aData[$sKey]; + if (empty($aData['or_like'])) { + $aData['or_like'] = []; + } if (empty($aData['or_like'])) { $aData['or_like'] = [];