diff --git a/app/Helpers/Collector/Extensions/MetaCollection.php b/app/Helpers/Collector/Extensions/MetaCollection.php index de0843fe49..98fdb9abb9 100644 --- a/app/Helpers/Collector/Extensions/MetaCollection.php +++ b/app/Helpers/Collector/Extensions/MetaCollection.php @@ -128,6 +128,78 @@ trait MetaCollection } } + /** + * @inheritDoc + */ + public function setExternalUrl(string $url): GroupCollectorInterface + { + if (false === $this->hasJoinedMetaTables) { + $this->hasJoinedMetaTables = true; + $this->query->leftJoin('journal_meta', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id'); + } + + $this->query->where('journal_meta.name', '=', 'external_url'); + $this->query->where('journal_meta.data', '=', json_encode($url)); + + return $this; + } + + /** + * @param string $url + * @return GroupCollectorInterface + */ + public function externalUrlContains(string $url): GroupCollectorInterface + { + if (false === $this->hasJoinedMetaTables) { + $this->hasJoinedMetaTables = true; + $this->query->leftJoin('journal_meta', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id'); + } + $url = json_encode($url); + $url = str_replace('\\', '\\\\', trim($url, '"')); + $this->query->where('journal_meta.name', '=', 'external_url'); + $this->query->where('journal_meta.data', 'LIKE', sprintf('%%%s%%', $url)); + + return $this; + } + + /** + * @param string $url + * @return GroupCollectorInterface + */ + public function externalUrlEnds(string $url): GroupCollectorInterface + { + if (false === $this->hasJoinedMetaTables) { + $this->hasJoinedMetaTables = true; + $this->query->leftJoin('journal_meta', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id'); + } + $url = json_encode($url); + $url = str_replace('\\', '\\\\', ltrim($url, '"')); + $this->query->where('journal_meta.name', '=', 'external_url'); + $this->query->where('journal_meta.data', 'LIKE', sprintf('%%%s', $url)); + + return $this; + } + + /** + * @param string $url + * @return GroupCollectorInterface + */ + public function externalUrlStarts(string $url): GroupCollectorInterface + { + if (false === $this->hasJoinedMetaTables) { + $this->hasJoinedMetaTables = true; + $this->query->leftJoin('journal_meta', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id'); + } + $url = json_encode($url); + $url = str_replace('\\', '\\\\', rtrim($url, '"')); + //var_dump($url); + + $this->query->where('journal_meta.name', '=', 'external_url'); + $this->query->where('journal_meta.data', 'LIKE', sprintf('%s%%', $url)); + + return $this; + } + /** * @inheritDoc */ diff --git a/app/Helpers/Collector/GroupCollectorInterface.php b/app/Helpers/Collector/GroupCollectorInterface.php index 03e4a457d5..82dfcfb992 100644 --- a/app/Helpers/Collector/GroupCollectorInterface.php +++ b/app/Helpers/Collector/GroupCollectorInterface.php @@ -147,6 +147,24 @@ interface GroupCollectorInterface */ public function externalIdStarts(string $externalId): GroupCollectorInterface; + /** + * @param string $url + * @return GroupCollectorInterface + */ + public function externalUrlContains(string $url): GroupCollectorInterface; + + /** + * @param string $url + * @return GroupCollectorInterface + */ + public function externalUrlEnds(string $url): GroupCollectorInterface; + + /** + * @param string $url + * @return GroupCollectorInterface + */ + public function externalUrlStarts(string $url): GroupCollectorInterface; + /** * Ensure the search will find nothing at all, zero results. * @@ -608,6 +626,12 @@ interface GroupCollectorInterface */ public function withExternalUrl(): GroupCollectorInterface; + /** + * @param string $url + * @return GroupCollectorInterface + */ + public function setExternalUrl(string $url): GroupCollectorInterface; + /** * Will include notes. * diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index 10de656277..2f45c8986a 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -742,6 +742,18 @@ class OperatorQuerySearch implements SearchInterface case 'any_external_url': $this->collector->withExternalUrl(); break; + case 'external_url_is': + $this->collector->setExternalUrl($value); + break; + case 'external_url_contains': + $this->collector->externalUrlContains($value); + break; + case 'external_url_starts': + $this->collector->externalUrlStarts($value); + break; + case 'external_url_ends': + $this->collector->externalUrlEnds($value); + break; // // other fields // diff --git a/config/search.php b/config/search.php index 14b04aee37..c48e433bbd 100644 --- a/config/search.php +++ b/config/search.php @@ -92,7 +92,6 @@ return [ 'internal_reference_ends' => ['alias' => false, 'needs_context' => true,], 'internal_reference_starts' => ['alias' => false, 'needs_context' => true,], - // TODO here we are. 'external_url_is' => ['alias' => false, 'needs_context' => true,], 'external_url_contains' => ['alias' => false, 'needs_context' => true,], 'external_url' => ['alias' => true, 'alias_for' => 'external_url_contains', 'needs_context' => true,], @@ -100,6 +99,7 @@ return [ 'external_url_starts' => ['alias' => false, 'needs_context' => true,], 'has_attachments' => ['alias' => false, 'needs_context' => false,], 'has_any_category' => ['alias' => false, 'needs_context' => false,], + // TODO here we are 'has_any_budget' => ['alias' => false, 'needs_context' => false,], 'has_any_bill' => ['alias' => false, 'needs_context' => false,], 'has_any_tag' => ['alias' => false, 'needs_context' => false,],