mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 10:39:28 +00:00
Updated search modifiers.
This commit is contained in:
@@ -12,6 +12,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Support\Search;
|
namespace FireflyIII\Support\Search;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use Log;
|
use Log;
|
||||||
use Steam;
|
use Steam;
|
||||||
@@ -36,59 +37,40 @@ class Modifier
|
|||||||
return $compare === $expected;
|
return $compare === $expected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function apply(array $modifier, Transaction $transaction): bool
|
||||||
* @param Transaction $transaction
|
|
||||||
* @param string $amount
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function amountIs(Transaction $transaction, string $amount): bool
|
|
||||||
{
|
{
|
||||||
return self::amountCompare($transaction, $amount, 0);
|
switch ($modifier['type']) {
|
||||||
}
|
default:
|
||||||
|
throw new FireflyException(sprintf('Search modifier "%s" is not (yet) supported. Sorry!', $modifier['type']));
|
||||||
|
break;
|
||||||
|
case 'amount_is':
|
||||||
|
$res = Modifier::amountCompare($transaction, $modifier['value'], 0);
|
||||||
|
Log::debug(sprintf('Amount is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
case 'amount_less':
|
||||||
|
$res = Modifier::amountCompare($transaction, $modifier['value'], 1);
|
||||||
|
Log::debug(sprintf('Amount less than %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
case 'amount_more':
|
||||||
|
$res = Modifier::amountCompare($transaction, $modifier['value'], -1);
|
||||||
|
Log::debug(sprintf('Amount more than %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
case 'source':
|
||||||
|
$res = Modifier::stringCompare($transaction->account_name, $modifier['value']);
|
||||||
|
Log::debug(sprintf('Source is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
case 'destination':
|
||||||
|
$res = Modifier::stringCompare($transaction->opposing_account_name, $modifier['value']);
|
||||||
|
Log::debug(sprintf('Destination is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
case 'category':
|
||||||
|
$res = Modifier::category($transaction, $modifier['value']);
|
||||||
|
Log::debug(sprintf('Category is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
|
||||||
/**
|
}
|
||||||
* @param Transaction $transaction
|
|
||||||
* @param string $amount
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function amountLess(Transaction $transaction, string $amount): bool
|
|
||||||
{
|
|
||||||
return self::amountCompare($transaction, $amount, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return $res;
|
||||||
* @param Transaction $transaction
|
|
||||||
* @param string $amount
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function amountMore(Transaction $transaction, string $amount): bool
|
|
||||||
{
|
|
||||||
return self::amountCompare($transaction, $amount, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Transaction $transaction
|
|
||||||
* @param string $destination
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function destination(Transaction $transaction, string $destination): bool
|
|
||||||
{
|
|
||||||
return self::stringCompare($transaction->opposing_account_name, $destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Transaction $transaction
|
|
||||||
* @param string $source
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function source(Transaction $transaction, string $source): bool
|
|
||||||
{
|
|
||||||
return self::stringCompare($transaction->account_name, $source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,4 +87,24 @@ class Modifier
|
|||||||
return $res;
|
return $res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Transaction $transaction
|
||||||
|
* @param string $search
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private static function category(Transaction $transaction, string $search): bool
|
||||||
|
{
|
||||||
|
$journalCategory = '';
|
||||||
|
if (!is_null($transaction->transaction_journal_category_name)) {
|
||||||
|
$journalCategory = Steam::decrypt(intval($transaction->transaction_journal_category_encrypted), $transaction->transaction_journal_category_name);
|
||||||
|
}
|
||||||
|
$transactionCategory = '';
|
||||||
|
if (!is_null($transaction->transaction_category_name)) {
|
||||||
|
$journalCategory = Steam::decrypt(intval($transaction->transaction_category_encrypted), $transaction->transaction_category_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::stringCompare($journalCategory, $search) || self::stringCompare($transactionCategory, $search);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -193,8 +193,9 @@ class Search implements SearchInterface
|
|||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setUser($this->user);
|
$collector->setUser($this->user);
|
||||||
$collector->setAllAssetAccounts()->setLimit($pageSize)->setPage($page)->withOpposingAccount();
|
$collector->setAllAssetAccounts()->setLimit($pageSize)->setPage($page)
|
||||||
$set = $collector->getPaginatedJournals();
|
->withOpposingAccount()->withCategoryInformation();
|
||||||
|
$set = $collector->getPaginatedJournals()->getCollection();
|
||||||
$words = $this->words;
|
$words = $this->words;
|
||||||
|
|
||||||
Log::debug(sprintf('Found %d journals to check. ', $set->count()));
|
Log::debug(sprintf('Found %d journals to check. ', $set->count()));
|
||||||
@@ -292,35 +293,9 @@ class Search implements SearchInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// then a for-each and a switch for every possible other thingie.
|
// then a for-each and a switch for every possible other thingie.
|
||||||
foreach ($this->modifiers as $modifier) {
|
foreach ($this->modifiers as $modifier) {
|
||||||
switch ($modifier['type']) {
|
$res = Modifier::apply($modifier, $transaction);
|
||||||
default:
|
|
||||||
throw new FireflyException(sprintf('Search modifier "%s" is not (yet) supported. Sorry!', $modifier['type']));
|
|
||||||
break;
|
|
||||||
case 'amount_is':
|
|
||||||
$res = Modifier::amountIs($transaction, $modifier['value']);
|
|
||||||
Log::debug(sprintf('Amount is %s? %s', $modifier['value'], var_export($res, true)));
|
|
||||||
break;
|
|
||||||
case 'amount_less':
|
|
||||||
$res = Modifier::amountLess($transaction, $modifier['value']);
|
|
||||||
Log::debug(sprintf('Amount less than %s? %s', $modifier['value'], var_export($res, true)));
|
|
||||||
break;
|
|
||||||
case 'amount_more':
|
|
||||||
$res = Modifier::amountMore($transaction, $modifier['value']);
|
|
||||||
Log::debug(sprintf('Amount more than %s? %s', $modifier['value'], var_export($res, true)));
|
|
||||||
break;
|
|
||||||
case 'source':
|
|
||||||
$res = Modifier::source($transaction, $modifier['value']);
|
|
||||||
Log::debug(sprintf('Source is %s? %s', $modifier['value'], var_export($res, true)));
|
|
||||||
break;
|
|
||||||
case 'destination':
|
|
||||||
$res = Modifier::destination($transaction, $modifier['value']);
|
|
||||||
Log::debug(sprintf('Destination is %s? %s', $modifier['value'], var_export($res, true)));
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user