Search for non-existing values now returns nothing.

This commit is contained in:
James Cole
2021-09-17 08:46:03 +02:00
parent 0e5256c8ce
commit 6691062747
3 changed files with 53 additions and 14 deletions

View File

@@ -767,4 +767,14 @@ class GroupCollector implements GroupCollectorInterface
return $groups; return $groups;
} }
/**
* @inheritDoc
*/
public function findNothing(): GroupCollectorInterface
{
$this->query->where('transaction_groups.id', -1);
return $this;
}
} }

View File

@@ -57,6 +57,13 @@ interface GroupCollectorInterface
*/ */
public function amountLess(string $amount): GroupCollectorInterface; public function amountLess(string $amount): GroupCollectorInterface;
/**
* Ensure the search will find nothing at all, zero results.
*
* @return GroupCollectorInterface
*/
public function findNothing(): GroupCollectorInterface;
/** /**
* Get transactions where the amount is more than. * Get transactions where the amount is more than.
* *

View File

@@ -345,6 +345,10 @@ class OperatorQuerySearch implements SearchInterface
if (null !== $account) { if (null !== $account) {
$this->collector->setSourceAccounts(new Collection([$account])); $this->collector->setSourceAccounts(new Collection([$account]));
} }
if (null === $account) {
// since the source does not exist, cannot return results:
$this->collector->findNothing();
}
break; break;
case 'journal_id': case 'journal_id':
$parts = explode(',', $value); $parts = explode(',', $value);
@@ -383,6 +387,9 @@ class OperatorQuerySearch implements SearchInterface
if (null !== $account) { if (null !== $account) {
$this->collector->setDestinationAccounts(new Collection([$account])); $this->collector->setDestinationAccounts(new Collection([$account]));
} }
if (null === $account) {
$this->collector->findNothing();
}
break; break;
case 'account_id': case 'account_id':
$parts = explode(',', $value); $parts = explode(',', $value);
@@ -396,6 +403,9 @@ class OperatorQuerySearch implements SearchInterface
if ($collection->count() > 0) { if ($collection->count() > 0) {
$this->collector->setAccounts($collection); $this->collector->setAccounts($collection);
} }
if (0 === $collection->count()) {
$this->collector->findNothing();
}
break; break;
// //
// cash account // cash account
@@ -436,12 +446,18 @@ class OperatorQuerySearch implements SearchInterface
if (null !== $currency) { if (null !== $currency) {
$this->collector->setCurrency($currency); $this->collector->setCurrency($currency);
} }
if (null === $currency) {
$this->collector->findNothing();
}
break; break;
case 'foreign_currency_is': case 'foreign_currency_is':
$currency = $this->findCurrency($value); $currency = $this->findCurrency($value);
if (null !== $currency) { if (null !== $currency) {
$this->collector->setForeignCurrency($currency); $this->collector->setForeignCurrency($currency);
} }
if (null === $currency) {
$this->collector->findNothing();
}
break; break;
// //
// attachments // attachments
@@ -463,6 +479,9 @@ class OperatorQuerySearch implements SearchInterface
if ($result->count() > 0) { if ($result->count() > 0) {
$this->collector->setCategories($result); $this->collector->setCategories($result);
} }
if (0 === $result->count()) {
$this->collector->findNothing();
}
break; break;
// //
// budgets // budgets
@@ -478,6 +497,9 @@ class OperatorQuerySearch implements SearchInterface
if ($result->count() > 0) { if ($result->count() > 0) {
$this->collector->setBudgets($result); $this->collector->setBudgets($result);
} }
if (0 === $result->count()) {
$this->collector->findNothing();
}
break; break;
// //
// bill // bill
@@ -493,6 +515,9 @@ class OperatorQuerySearch implements SearchInterface
if ($result->count() > 0) { if ($result->count() > 0) {
$this->collector->setBills($result); $this->collector->setBills($result);
} }
if (0 === $result->count()) {
$this->collector->findNothing();
}
break; break;
// //
// tags // tags
@@ -508,6 +533,11 @@ class OperatorQuerySearch implements SearchInterface
if ($result->count() > 0) { if ($result->count() > 0) {
$this->collector->setTags($result); $this->collector->setTags($result);
} }
// no tags found means search must result in nothing.
if (0 === $result->count()) {
Log::info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
$this->collector->findNothing();
}
break; break;
// //
// notes // notes
@@ -698,10 +728,8 @@ class OperatorQuerySearch implements SearchInterface
// get accounts: // get accounts:
$accounts = $this->accountRepository->searchAccount($value, $searchTypes, 25); $accounts = $this->accountRepository->searchAccount($value, $searchTypes, 25);
if (0 === $accounts->count()) { if (0 === $accounts->count()) {
Log::debug('Found zero accounts, search for invalid account.'); Log::debug('Found zero accounts, search for non existing account, NO results will be returned.');
$account = new Account; $this->collector->findNothing();
$account->id = 0;
$this->collector->$collectorMethod(new Collection([$account]));
return; return;
} }
@@ -713,10 +741,8 @@ class OperatorQuerySearch implements SearchInterface
); );
if (0 === $filtered->count()) { if (0 === $filtered->count()) {
Log::debug('Left with zero accounts, search for invalid account.'); Log::debug('Left with zero accounts, so cannot find anything, NO results will be returned.');
$account = new Account; $this->collector->findNothing();
$account->id = 0;
$this->collector->$collectorMethod(new Collection([$account]));
return; return;
} }
@@ -764,9 +790,7 @@ class OperatorQuerySearch implements SearchInterface
$accounts = $this->accountRepository->searchAccountNr($value, $searchTypes, 25); $accounts = $this->accountRepository->searchAccountNr($value, $searchTypes, 25);
if (0 === $accounts->count()) { if (0 === $accounts->count()) {
Log::debug('Found zero accounts, search for invalid account.'); Log::debug('Found zero accounts, search for invalid account.');
$account = new Account; $this->collector->findNothing();
$account->id = 0;
$this->collector->$collectorMethod(new Collection([$account]));
return; return;
} }
@@ -791,9 +815,7 @@ class OperatorQuerySearch implements SearchInterface
if (0 === $filtered->count()) { if (0 === $filtered->count()) {
Log::debug('Left with zero, search for invalid account'); Log::debug('Left with zero, search for invalid account');
$account = new Account; $this->collector->findNothing();
$account->id = 0;
$this->collector->$collectorMethod(new Collection([$account]));
return; return;
} }