mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Rename class.
This commit is contained in:
@@ -22,7 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Providers;
|
||||
|
||||
use FireflyIII\Support\Search\BetterQuerySearch;
|
||||
use FireflyIII\Support\Search\OperatorQuerySearch;
|
||||
use FireflyIII\Support\Search\SearchInterface;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
@@ -48,8 +48,8 @@ class SearchServiceProvider extends ServiceProvider
|
||||
$this->app->bind(
|
||||
SearchInterface::class,
|
||||
function (Application $app) {
|
||||
/** @var BetterQuerySearch $search */
|
||||
$search = app(BetterQuerySearch::class);
|
||||
/** @var OperatorQuerySearch $search */
|
||||
$search = app(OperatorQuerySearch::class);
|
||||
if ($app->auth->check()) {
|
||||
$search->setUser(auth()->user());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* BetterQuerySearch.php
|
||||
* OperatorQuerySearch.php
|
||||
* Copyright (c) 2020 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
@@ -35,6 +35,7 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;
|
||||
use FireflyIII\Support\ParseDateString;
|
||||
use FireflyIII\User;
|
||||
use Gdbots\QueryParser\Node\Field;
|
||||
use Gdbots\QueryParser\Node\Node;
|
||||
@@ -47,9 +48,9 @@ use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class BetterQuerySearch
|
||||
* Class OperatorQuerySearch
|
||||
*/
|
||||
class BetterQuerySearch implements SearchInterface
|
||||
class OperatorQuerySearch implements SearchInterface
|
||||
{
|
||||
private AccountRepositoryInterface $accountRepository;
|
||||
private BillRepositoryInterface $billRepository;
|
||||
@@ -69,12 +70,12 @@ class BetterQuerySearch implements SearchInterface
|
||||
private Collection $operators;
|
||||
|
||||
/**
|
||||
* BetterQuerySearch constructor.
|
||||
* OperatorQuerySearch constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
Log::debug('Constructed BetterQuerySearch');
|
||||
Log::debug('Constructed OperatorQuerySearch');
|
||||
$this->modifiers = new Collection; // obsolete
|
||||
$this->operators = new Collection;
|
||||
$this->page = 1;
|
||||
@@ -231,7 +232,7 @@ class BetterQuerySearch implements SearchInterface
|
||||
if ($this->updateCollector($operator, $value)) {
|
||||
$this->operators->push(
|
||||
[
|
||||
'type' => $operator,
|
||||
'type' => $this->getRootOperator($operator),
|
||||
'value' => $value,
|
||||
]
|
||||
);
|
||||
@@ -291,8 +292,8 @@ class BetterQuerySearch implements SearchInterface
|
||||
$this->searchAccount($value, 1, 3);
|
||||
break;
|
||||
case 'source_account_id':
|
||||
$account = $this->accountRepository->findNull((int)$value);
|
||||
if(null !== $account) {
|
||||
$account = $this->accountRepository->findNull((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->setSourceAccounts(new Collection([$account]));
|
||||
}
|
||||
break;
|
||||
@@ -321,14 +322,14 @@ class BetterQuerySearch implements SearchInterface
|
||||
$this->searchAccount($value, 2, 3);
|
||||
break;
|
||||
case 'destination_account_id':
|
||||
$account = $this->accountRepository->findNull((int)$value);
|
||||
if(null !== $account) {
|
||||
$account = $this->accountRepository->findNull((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->setDestinationAccounts(new Collection([$account]));
|
||||
}
|
||||
break;
|
||||
case 'account_id':
|
||||
$account = $this->accountRepository->findNull((int)$value);
|
||||
if(null !== $account) {
|
||||
$account = $this->accountRepository->findNull((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->setAccounts(new Collection([$account]));
|
||||
}
|
||||
break;
|
||||
@@ -474,20 +475,35 @@ class BetterQuerySearch implements SearchInterface
|
||||
// dates
|
||||
//
|
||||
case 'date_is':
|
||||
Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$start = new Carbon($value);
|
||||
$this->collector->setRange($start, $start);
|
||||
break;
|
||||
$range = $this->parseDateRange($value);
|
||||
Log::debug(sprintf('Set "%s" using collector with value "%s" (%s - %s)', $operator, $value, $range['start']->format('Y-m-d'), $range['end']->format('Y-m-d')));
|
||||
$this->collector->setRange($range['start'], $range['end']);
|
||||
|
||||
// add to operators manually:
|
||||
$this->operators->push(['type' => 'date_before', 'value' => $range['start']->format('Y-m-d'),]);
|
||||
$this->operators->push(['type' => 'date_after', 'value' => $range['end']->format('Y-m-d'),]);
|
||||
|
||||
return false;
|
||||
case 'date_before':
|
||||
Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$before = new Carbon($value);
|
||||
$this->collector->setBefore($before);
|
||||
break;
|
||||
$range = $this->parseDateRange($value);
|
||||
Log::debug(sprintf('Set "%s" using collector with value "%s" (%s - %s)', $operator, $value, $range['start']->format('Y-m-d'), $range['end']->format('Y-m-d')));
|
||||
$this->collector->setRange($range['start'], $range['end']);
|
||||
|
||||
// add to operators manually:
|
||||
$this->operators->push(['type' => 'date_before', 'value' => $range['start']->format('Y-m-d'),]);
|
||||
$this->collector->setBefore($range['start']);
|
||||
|
||||
return false;
|
||||
case 'date_after':
|
||||
Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$after = new Carbon($value);
|
||||
$this->collector->setAfter($after);
|
||||
break;
|
||||
$range = $this->parseDateRange($value);
|
||||
Log::debug(sprintf('Set "%s" using collector with value "%s" (%s - %s)', $operator, $value, $range['start']->format('Y-m-d'), $range['end']->format('Y-m-d')));
|
||||
$this->collector->setRange($range['start'], $range['end']);
|
||||
|
||||
// add to operators manually:
|
||||
$this->operators->push(['type' => 'date_before', 'value' => $range['end']->format('Y-m-d'),]);
|
||||
$this->collector->setAfter($range['end']);
|
||||
|
||||
return false;
|
||||
case 'created_on':
|
||||
Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$createdAt = new Carbon($value);
|
||||
@@ -663,4 +679,22 @@ class BetterQuerySearch implements SearchInterface
|
||||
return $operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function parseDateRange(string $value): array
|
||||
{
|
||||
$parser = new ParseDateString;
|
||||
if ($parser->isDateRange($value)) {
|
||||
return $parser->parseRange($value, today(config('app.timezone')));
|
||||
}
|
||||
$date = $parser->parseDate($value);
|
||||
return [
|
||||
'start' => $date,
|
||||
'end' => $date,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,8 +28,25 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface RuleEngineInterface
|
||||
{
|
||||
/**
|
||||
* Add rules for the engine to execute.
|
||||
*
|
||||
* @param Collection $rules
|
||||
*/
|
||||
public function setRules(Collection $rules): void;
|
||||
|
||||
/**
|
||||
* Add entire rule groups for the engine to execute.
|
||||
*
|
||||
* @param Collection $ruleGroups
|
||||
*/
|
||||
public function setRuleGroups(Collection $ruleGroups): void;
|
||||
|
||||
/**
|
||||
* Add operators added to each search by the rule engine.
|
||||
*
|
||||
* @param array $operator
|
||||
*/
|
||||
public function addOperator(array $operator): void;
|
||||
|
||||
}
|
||||
30
app/TransactionRules/Engine/SearchRuleEngine.php
Normal file
30
app/TransactionRules/Engine/SearchRuleEngine.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/*
|
||||
* SearchRuleEngine.php
|
||||
* Copyright (c) 2020 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\TransactionRules\Engine;
|
||||
|
||||
/**
|
||||
* Class SearchRuleEngine
|
||||
*/
|
||||
class SearchRuleEngine implements RuleEngineInterface
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user