Skip to content

Commit

Permalink
feat: Provide opportunity to alter search term
Browse files Browse the repository at this point in the history
  • Loading branch information
hellopablo committed Nov 26, 2024
1 parent b879580 commit 513a3d9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Common/Traits/Model/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public function getSearchKey(): string

// --------------------------------------------------------------------------

public function getSearchTerm(array $aData): string
{
return (string) ($aData[$this->getSearchKey()] ?? '');
}

// --------------------------------------------------------------------------

/**
* Searches for objects, optionally paginated.
*
Expand Down Expand Up @@ -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'] = [];
Expand Down

0 comments on commit 513a3d9

Please sign in to comment.