| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2021-01-29 18:50:35 +01:00
										 |  |  | /* | 
					
						
							|  |  |  |  * OperatorQuerySearch.php | 
					
						
							|  |  |  |  * Copyright (c) 2021 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/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 12:16:47 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Support\Search; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Carbon\Carbon; | 
					
						
							|  |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							|  |  |  | use FireflyIII\Helpers\Collector\GroupCollectorInterface; | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  | use FireflyIII\Models\Account; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | use FireflyIII\Models\AccountMeta; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | use FireflyIII\Models\AccountType; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | use FireflyIII\Models\TransactionCurrency; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Bill\BillRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | use FireflyIII\Repositories\Tag\TagRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  | use FireflyIII\Support\ParseDateString; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | use FireflyIII\User; | 
					
						
							| 
									
										
										
										
											2020-09-10 14:50:22 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Date; | 
					
						
							| 
									
										
										
										
											2020-09-10 14:53:35 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Emoji; | 
					
						
							|  |  |  | use Gdbots\QueryParser\Node\Emoticon; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Field; | 
					
						
							| 
									
										
										
										
											2020-09-10 14:50:49 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Hashtag; | 
					
						
							| 
									
										
										
										
											2020-09-10 14:53:35 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Mention; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Node; | 
					
						
							| 
									
										
										
										
											2020-09-09 06:10:00 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Numbr; | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Phrase; | 
					
						
							| 
									
										
										
										
											2020-12-20 06:56:27 +01:00
										 |  |  | use Gdbots\QueryParser\Node\Subquery; | 
					
						
							| 
									
										
										
										
											2020-09-10 14:48:02 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Url; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | use Gdbots\QueryParser\Node\Word; | 
					
						
							|  |  |  | use Gdbots\QueryParser\QueryParser; | 
					
						
							|  |  |  | use Illuminate\Pagination\LengthAwarePaginator; | 
					
						
							|  |  |  | use Illuminate\Support\Collection; | 
					
						
							|  |  |  | use Log; | 
					
						
							| 
									
										
										
										
											2021-10-02 18:46:26 +02:00
										 |  |  | use LogicException; | 
					
						
							| 
									
										
										
										
											2021-10-02 18:45:42 +02:00
										 |  |  | use TypeError; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |  * Class OperatorQuerySearch | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  | class OperatorQuerySearch implements SearchInterface | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-30 20:02:19 +02:00
										 |  |  |     private AccountRepositoryInterface  $accountRepository; | 
					
						
							|  |  |  |     private BillRepositoryInterface     $billRepository; | 
					
						
							|  |  |  |     private BudgetRepositoryInterface   $budgetRepository; | 
					
						
							|  |  |  |     private CategoryRepositoryInterface $categoryRepository; | 
					
						
							|  |  |  |     private GroupCollectorInterface     $collector; | 
					
						
							|  |  |  |     private CurrencyRepositoryInterface $currencyRepository; | 
					
						
							|  |  |  |     private Carbon                      $date; | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     private array                       $invalidOperators; | 
					
						
							| 
									
										
										
										
											2021-06-30 20:02:19 +02:00
										 |  |  |     private int                         $limit; | 
					
						
							|  |  |  |     private Collection                  $operators; | 
					
						
							|  |  |  |     private int                         $page; | 
					
						
							|  |  |  |     private float                       $startTime; | 
					
						
							|  |  |  |     private TagRepositoryInterface      $tagRepository; | 
					
						
							|  |  |  |     private array                       $validOperators; | 
					
						
							|  |  |  |     private array                       $words; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |      * OperatorQuerySearch constructor. | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |         Log::debug('Constructed OperatorQuerySearch'); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         $this->operators          = new Collection; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |         $this->page               = 1; | 
					
						
							|  |  |  |         $this->words              = []; | 
					
						
							| 
									
										
										
										
											2021-06-30 20:02:19 +02:00
										 |  |  |         $this->invalidOperators   = []; | 
					
						
							| 
									
										
										
										
											2020-08-22 16:55:54 +02:00
										 |  |  |         $this->limit              = 25; | 
					
						
							| 
									
										
										
										
											2021-02-03 10:41:41 +01:00
										 |  |  |         $this->date               = today(config('app.timezone')); | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |         $this->validOperators     = array_keys(config('firefly.search.operators')); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |         $this->startTime          = microtime(true); | 
					
						
							|  |  |  |         $this->accountRepository  = app(AccountRepositoryInterface::class); | 
					
						
							|  |  |  |         $this->categoryRepository = app(CategoryRepositoryInterface::class); | 
					
						
							|  |  |  |         $this->budgetRepository   = app(BudgetRepositoryInterface::class); | 
					
						
							|  |  |  |         $this->billRepository     = app(BillRepositoryInterface::class); | 
					
						
							|  |  |  |         $this->tagRepository      = app(TagRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         $this->currencyRepository = app(CurrencyRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getInvalidOperators(): array | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->invalidOperators; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function getModifiers(): Collection | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-22 12:25:00 +02:00
										 |  |  |         return $this->getOperators(); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							|  |  |  |      * @codeCoverageIgnore | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getOperators(): Collection | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->operators; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function getWordsAsString(): string | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return implode(' ', $this->words); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function hasModifiers(): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         die(__METHOD__); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @throws FireflyException | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function parseQuery(string $query) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |         Log::debug(sprintf('Now in parseQuery(%s)', $query)); | 
					
						
							| 
									
										
										
										
											2021-09-18 10:20:19 +02:00
										 |  |  |         $parser = new QueryParser(); | 
					
						
							| 
									
										
										
										
											2021-10-02 18:45:42 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $query1 = $parser->parse($query); | 
					
						
							| 
									
										
										
										
											2021-10-30 21:32:02 +02:00
										 |  |  |         } catch (TypeError | LogicException $e) { | 
					
						
							| 
									
										
										
										
											2021-10-02 18:45:42 +02:00
										 |  |  |             Log::error($e->getMessage()); | 
					
						
							|  |  |  |             Log::error(sprintf('Could not parse search: "%s".', $query)); | 
					
						
							|  |  |  |             throw new FireflyException('Invalid search value. See the logs.', 0, $e); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 10:20:19 +02:00
										 |  |  |         Log::debug(sprintf('Found %d node(s)', count($query1->getNodes()))); | 
					
						
							|  |  |  |         foreach ($query1->getNodes() as $searchNode) { | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |             $this->handleSearchNode($searchNode); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->collector->setSearchWords($this->words); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function searchTime(): float | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return microtime(true) - $this->startTime; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function searchTransactions(): LengthAwarePaginator | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-06-12 19:32:34 +02:00
										 |  |  |         if (empty($this->getWords()) && empty($this->getOperators())) { | 
					
						
							| 
									
										
										
										
											2021-05-13 05:34:49 +02:00
										 |  |  |             return new LengthAwarePaginator([], 0, 5, 1); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |         return $this->collector->getPaginatedGroups(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 09:15:40 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param Carbon $date | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setDate(Carbon $date): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->date = $date; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param int $limit | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setLimit(int $limit): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->limit = $limit; | 
					
						
							|  |  |  |         $this->collector->setLimit($this->limit); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							|  |  |  |      * @codeCoverageIgnore | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setPage(int $page): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->page = $page; | 
					
						
							|  |  |  |         $this->collector->setPage($this->page); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function setUser(User $user): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->accountRepository->setUser($user); | 
					
						
							|  |  |  |         $this->billRepository->setUser($user); | 
					
						
							|  |  |  |         $this->categoryRepository->setUser($user); | 
					
						
							|  |  |  |         $this->budgetRepository->setUser($user); | 
					
						
							| 
									
										
										
										
											2020-12-01 18:11:31 +01:00
										 |  |  |         $this->tagRepository->setUser($user); | 
					
						
							| 
									
										
										
										
											2020-10-17 08:53:32 +02:00
										 |  |  |         $this->collector = app(GroupCollectorInterface::class); | 
					
						
							| 
									
										
										
										
											2021-09-18 10:20:19 +02:00
										 |  |  |         $this->collector->setUser($user); | 
					
						
							| 
									
										
										
										
											2020-10-17 08:53:32 +02:00
										 |  |  |         $this->collector->withAccountInformation()->withCategoryInformation()->withBudgetInformation(); | 
					
						
							| 
									
										
										
										
											2020-08-22 16:55:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |         $this->setLimit((int)app('preferences')->getForUser($user, 'listPageSize', 50)->data); | 
					
						
							| 
									
										
										
										
											2020-10-17 08:53:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param Node $searchNode | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function handleSearchNode(Node $searchNode): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $class = get_class($searchNode); | 
					
						
							| 
									
										
										
										
											2021-10-30 21:32:02 +02:00
										 |  |  |         Log::debug(sprintf('Now in handleSearchNode(%s)', $class)); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |         switch ($class) { | 
					
						
							|  |  |  |             default: | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |                 Log::error(sprintf('Cannot handle node %s', $class)); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 throw new FireflyException(sprintf('Firefly III search cant handle "%s"-nodes', $class)); | 
					
						
							| 
									
										
										
										
											2020-12-20 06:56:27 +01:00
										 |  |  |             case Subquery::class: | 
					
						
							|  |  |  |                 // loop all notes in subquery:
 | 
					
						
							| 
									
										
										
										
											2021-04-06 17:00:16 +02:00
										 |  |  |                 foreach ($searchNode->getNodes() as $subNode) { // @phpstan-ignore-line
 | 
					
						
							| 
									
										
										
										
											2021-10-30 21:32:02 +02:00
										 |  |  |                     $this->handleSearchNode($subNode); // let's hope it's not too recursive!
 | 
					
						
							| 
									
										
										
										
											2020-12-20 06:56:27 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |             case Word::class: | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |             case Phrase::class: | 
					
						
							| 
									
										
										
										
											2020-09-09 06:10:00 +02:00
										 |  |  |             case Numbr::class: | 
					
						
							| 
									
										
										
										
											2020-09-10 14:48:02 +02:00
										 |  |  |             case Url::class: | 
					
						
							| 
									
										
										
										
											2020-09-10 14:50:22 +02:00
										 |  |  |             case Date::class: | 
					
						
							| 
									
										
										
										
											2020-09-10 14:50:49 +02:00
										 |  |  |             case Hashtag::class: | 
					
						
							| 
									
										
										
										
											2020-09-10 14:53:35 +02:00
										 |  |  |             case Emoticon::class: | 
					
						
							|  |  |  |             case Emoji::class: | 
					
						
							|  |  |  |             case Mention::class: | 
					
						
							| 
									
										
										
										
											2021-05-24 08:06:56 +02:00
										 |  |  |                 $allWords = (string)$searchNode->getValue(); | 
					
						
							|  |  |  |                 Log::debug(sprintf('Add words "%s" to search string, because Node class is "%s"', $allWords, $class)); | 
					
						
							|  |  |  |                 $this->words[] = $allWords; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             case Field::class: | 
					
						
							| 
									
										
										
										
											2021-05-13 05:34:49 +02:00
										 |  |  |                 Log::debug(sprintf('Now handle Node class %s', $class)); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 /** @var Field $searchNode */ | 
					
						
							|  |  |  |                 // used to search for x:y
 | 
					
						
							| 
									
										
										
										
											2020-09-11 07:11:37 +02:00
										 |  |  |                 $operator = strtolower($searchNode->getValue()); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 $value    = $searchNode->getNode()->getValue(); | 
					
						
							|  |  |  |                 // must be valid operator:
 | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |                 if (in_array($operator, $this->validOperators, true) && $this->updateCollector($operator, (string)$value)) { | 
					
						
							|  |  |  |                     $this->operators->push( | 
					
						
							|  |  |  |                         [ | 
					
						
							|  |  |  |                             'type'  => self::getRootOperator($operator), | 
					
						
							|  |  |  |                             'value' => (string)$value, | 
					
						
							|  |  |  |                         ] | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2021-10-30 21:32:02 +02:00
										 |  |  |                     Log::debug(sprintf('Added operator type "%s"', $operator)); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (!in_array($operator, $this->validOperators, true)) { | 
					
						
							|  |  |  |                     Log::debug(sprintf('Added INVALID operator type "%s"', $operator)); | 
					
						
							| 
									
										
										
										
											2021-06-30 20:02:19 +02:00
										 |  |  |                     $this->invalidOperators[] = [ | 
					
						
							|  |  |  |                         'type'  => $operator, | 
					
						
							|  |  |  |                         'value' => (string)$value, | 
					
						
							|  |  |  |                     ]; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param string $operator | 
					
						
							|  |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |      * @return bool | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @throws FireflyException | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |     private function updateCollector(string $operator, string $value): bool | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-10-30 21:32:02 +02:00
										 |  |  |         Log::debug(sprintf('Now in updateCollector("%s", "%s")', $operator, $value)); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // check if alias, replace if necessary:
 | 
					
						
							| 
									
										
										
										
											2020-08-27 06:19:16 +02:00
										 |  |  |         $operator = self::getRootOperator($operator); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |         switch ($operator) { | 
					
						
							|  |  |  |             default: | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |                 Log::error(sprintf('No such operator: %s', $operator)); | 
					
						
							|  |  |  |                 throw new FireflyException(sprintf('Unsupported search operator: "%s"', $operator)); | 
					
						
							|  |  |  |             // some search operators are ignored, basically:
 | 
					
						
							|  |  |  |             case 'user_action': | 
					
						
							|  |  |  |                 Log::info(sprintf('Ignore search operator "%s"', $operator)); | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                 return false; | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             // all account related searches:
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'source_account_starts': | 
					
						
							|  |  |  |                 $this->searchAccount($value, 1, 1); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'source_account_ends': | 
					
						
							|  |  |  |                 $this->searchAccount($value, 1, 2); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'source_account_is': | 
					
						
							|  |  |  |                 $this->searchAccount($value, 1, 4); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'source_account_nr_starts': | 
					
						
							|  |  |  |                 $this->searchAccountNr($value, 1, 1); | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             case 'source_account_nr_ends': | 
					
						
							|  |  |  |                 $this->searchAccountNr($value, 1, 2); | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             case 'source_account_nr_is': | 
					
						
							|  |  |  |                 $this->searchAccountNr($value, 1, 4); | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             case 'source_account_nr_contains': | 
					
						
							|  |  |  |                 $this->searchAccountNr($value, 1, 3); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'source_account_contains': | 
					
						
							|  |  |  |                 $this->searchAccount($value, 1, 3); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'source_account_id': | 
					
						
							| 
									
										
										
										
											2021-06-30 06:17:38 +02:00
										 |  |  |                 $account = $this->accountRepository->find((int)$value); | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |                 if (null !== $account) { | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                     $this->collector->setSourceAccounts(new Collection([$account])); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |                 if (null === $account) { | 
					
						
							|  |  |  |                     // since the source does not exist, cannot return results:
 | 
					
						
							|  |  |  |                     $this->collector->findNothing(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-24 07:03:17 +02:00
										 |  |  |             case 'journal_id': | 
					
						
							|  |  |  |                 $parts = explode(',', $value); | 
					
						
							|  |  |  |                 $this->collector->setJournalIds($parts); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2021-01-20 18:41:31 +01:00
										 |  |  |             case 'id': | 
					
						
							|  |  |  |                 $parts = explode(',', $value); | 
					
						
							|  |  |  |                 $this->collector->setIds($parts); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             case 'destination_account_starts': | 
					
						
							|  |  |  |                 $this->searchAccount($value, 2, 1); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'destination_account_ends': | 
					
						
							|  |  |  |                 $this->searchAccount($value, 2, 2); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'destination_account_nr_starts': | 
					
						
							|  |  |  |                 $this->searchAccountNr($value, 2, 1); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'destination_account_nr_ends': | 
					
						
							|  |  |  |                 $this->searchAccountNr($value, 2, 2); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'destination_account_nr_is': | 
					
						
							|  |  |  |                 $this->searchAccountNr($value, 2, 4); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'destination_account_is': | 
					
						
							|  |  |  |                 $this->searchAccount($value, 2, 4); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'destination_account_nr_contains': | 
					
						
							|  |  |  |                 $this->searchAccountNr($value, 2, 3); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'destination_account_contains': | 
					
						
							|  |  |  |                 $this->searchAccount($value, 2, 3); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'destination_account_id': | 
					
						
							| 
									
										
										
										
											2021-06-30 06:17:38 +02:00
										 |  |  |                 $account = $this->accountRepository->find((int)$value); | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |                 if (null !== $account) { | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                     $this->collector->setDestinationAccounts(new Collection([$account])); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |                 if (null === $account) { | 
					
						
							|  |  |  |                     $this->collector->findNothing(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             case 'account_id': | 
					
						
							| 
									
										
										
										
											2020-08-22 16:55:54 +02:00
										 |  |  |                 $parts      = explode(',', $value); | 
					
						
							|  |  |  |                 $collection = new Collection; | 
					
						
							|  |  |  |                 foreach ($parts as $accountId) { | 
					
						
							| 
									
										
										
										
											2021-06-30 06:17:38 +02:00
										 |  |  |                     $account = $this->accountRepository->find((int)$accountId); | 
					
						
							| 
									
										
										
										
											2020-08-22 16:55:54 +02:00
										 |  |  |                     if (null !== $account) { | 
					
						
							|  |  |  |                         $collection->push($account); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if ($collection->count() > 0) { | 
					
						
							|  |  |  |                     $this->collector->setAccounts($collection); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |                 if (0 === $collection->count()) { | 
					
						
							|  |  |  |                     $this->collector->findNothing(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             //
 | 
					
						
							| 
									
										
										
										
											2020-08-26 20:18:27 +02:00
										 |  |  |             // cash account
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'source_is_cash': | 
					
						
							|  |  |  |                 $account = $this->getCashAccount(); | 
					
						
							|  |  |  |                 $this->collector->setSourceAccounts(new Collection([$account])); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'destination_is_cash': | 
					
						
							|  |  |  |                 $account = $this->getCashAccount(); | 
					
						
							|  |  |  |                 $this->collector->setDestinationAccounts(new Collection([$account])); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'account_is_cash': | 
					
						
							|  |  |  |                 $account = $this->getCashAccount(); | 
					
						
							|  |  |  |                 $this->collector->setAccounts(new Collection([$account])); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             //
 | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             // description
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'description_starts': | 
					
						
							|  |  |  |                 $this->collector->descriptionStarts([$value]); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'description_ends': | 
					
						
							|  |  |  |                 $this->collector->descriptionEnds([$value]); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'description_contains': | 
					
						
							|  |  |  |                 $this->words[] = $value; | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                 return false; | 
					
						
							|  |  |  |             case 'description_is': | 
					
						
							|  |  |  |                 $this->collector->descriptionIs($value); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             // currency
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'currency_is': | 
					
						
							|  |  |  |                 $currency = $this->findCurrency($value); | 
					
						
							|  |  |  |                 if (null !== $currency) { | 
					
						
							|  |  |  |                     $this->collector->setCurrency($currency); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |                 if (null === $currency) { | 
					
						
							|  |  |  |                     $this->collector->findNothing(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             case 'foreign_currency_is': | 
					
						
							|  |  |  |                 $currency = $this->findCurrency($value); | 
					
						
							|  |  |  |                 if (null !== $currency) { | 
					
						
							|  |  |  |                     $this->collector->setForeignCurrency($currency); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |                 if (null === $currency) { | 
					
						
							|  |  |  |                     $this->collector->findNothing(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             // attachments
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'has_attachments': | 
					
						
							|  |  |  |                 Log::debug('Set collector to filter on attachments.'); | 
					
						
							|  |  |  |                 $this->collector->hasAttachments(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             // categories
 | 
					
						
							|  |  |  |             case 'has_no_category': | 
					
						
							|  |  |  |                 $this->collector->withoutCategory(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'has_any_category': | 
					
						
							|  |  |  |                 $this->collector->withCategory(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'category_is': | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 $result = $this->categoryRepository->searchCategory($value, 25); | 
					
						
							|  |  |  |                 if ($result->count() > 0) { | 
					
						
							|  |  |  |                     $this->collector->setCategories($result); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |                 if (0 === $result->count()) { | 
					
						
							|  |  |  |                     $this->collector->findNothing(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             //
 | 
					
						
							|  |  |  |             // budgets
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'has_no_budget': | 
					
						
							|  |  |  |                 $this->collector->withoutBudget(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'has_any_budget': | 
					
						
							|  |  |  |                 $this->collector->withBudget(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'budget_is': | 
					
						
							|  |  |  |                 $result = $this->budgetRepository->searchBudget($value, 25); | 
					
						
							|  |  |  |                 if ($result->count() > 0) { | 
					
						
							|  |  |  |                     $this->collector->setBudgets($result); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |                 if (0 === $result->count()) { | 
					
						
							|  |  |  |                     $this->collector->findNothing(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             // bill
 | 
					
						
							|  |  |  |             //
 | 
					
						
							| 
									
										
										
										
											2021-04-08 16:07:07 +02:00
										 |  |  |             case 'has_no_bill': | 
					
						
							|  |  |  |                 $this->collector->withoutBill(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'has_any_bill': | 
					
						
							|  |  |  |                 $this->collector->withBill(); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             case 'bill_is': | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 $result = $this->billRepository->searchBill($value, 25); | 
					
						
							|  |  |  |                 if ($result->count() > 0) { | 
					
						
							|  |  |  |                     $this->collector->setBills($result); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |                 if (0 === $result->count()) { | 
					
						
							|  |  |  |                     $this->collector->findNothing(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             //
 | 
					
						
							|  |  |  |             // tags
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'has_no_tag': | 
					
						
							|  |  |  |                 $this->collector->withoutTags(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'has_any_tag': | 
					
						
							|  |  |  |                 $this->collector->hasAnyTag(); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-23 18:48:40 +02:00
										 |  |  |             case 'tag_is': | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 $result = $this->tagRepository->searchTag($value); | 
					
						
							|  |  |  |                 if ($result->count() > 0) { | 
					
						
							|  |  |  |                     $this->collector->setTags($result); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |                 // 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(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             //
 | 
					
						
							|  |  |  |             // notes
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'notes_contain': | 
					
						
							|  |  |  |                 $this->collector->notesContain($value); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             case 'notes_start': | 
					
						
							|  |  |  |                 $this->collector->notesStartWith($value); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'notes_end': | 
					
						
							|  |  |  |                 $this->collector->notesEndWith($value); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'notes_are': | 
					
						
							|  |  |  |                 $this->collector->notesExactly($value); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'no_notes': | 
					
						
							|  |  |  |                 $this->collector->withoutNotes(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'any_notes': | 
					
						
							|  |  |  |                 $this->collector->withAnyNotes(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             // amount
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'amount_exactly': | 
					
						
							| 
									
										
										
										
											2020-12-01 12:24:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 // strip comma's, make dots.
 | 
					
						
							|  |  |  |                 $value = str_replace(',', '.', (string)$value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $amount = app('steam')->positive($value); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); | 
					
						
							|  |  |  |                 $this->collector->amountIs($amount); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'amount_less': | 
					
						
							| 
									
										
										
										
											2020-12-01 12:24:23 +01:00
										 |  |  |                 // strip comma's, make dots.
 | 
					
						
							|  |  |  |                 $value = str_replace(',', '.', (string)$value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $amount = app('steam')->positive($value); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); | 
					
						
							|  |  |  |                 $this->collector->amountLess($amount); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'amount_more': | 
					
						
							| 
									
										
										
										
											2021-05-13 05:34:49 +02:00
										 |  |  |                 Log::debug(sprintf('Now handling operator "%s"', $operator)); | 
					
						
							| 
									
										
										
										
											2020-12-01 12:24:23 +01:00
										 |  |  |                 // strip comma's, make dots.
 | 
					
						
							| 
									
										
										
										
											2021-05-13 05:34:49 +02:00
										 |  |  |                 $value  = str_replace(',', '.', (string)$value); | 
					
						
							| 
									
										
										
										
											2020-12-01 12:24:23 +01:00
										 |  |  |                 $amount = app('steam')->positive($value); | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); | 
					
						
							|  |  |  |                 $this->collector->amountMore($amount); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             //
 | 
					
						
							|  |  |  |             // transaction type
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'transaction_type': | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |                 $this->collector->setTypes([ucfirst($value)]); | 
					
						
							|  |  |  |                 Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value)); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             //
 | 
					
						
							|  |  |  |             // dates
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'date_is': | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |                 $range = $this->parseDateRange($value); | 
					
						
							| 
									
										
										
										
											2021-12-17 17:27:29 +01:00
										 |  |  |                 $this->setExactDateParams($range); | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |             case 'date_before': | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |                 $range = $this->parseDateRange($value); | 
					
						
							| 
									
										
										
										
											2021-12-17 17:27:29 +01:00
										 |  |  |                 $this->setDateBeforeParams($range); | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |             case 'date_after': | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |                 $range = $this->parseDateRange($value); | 
					
						
							| 
									
										
										
										
											2021-12-17 17:27:29 +01:00
										 |  |  |                 $this->setDateAfterParams($range); | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |             case 'created_on': | 
					
						
							|  |  |  |                 Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value)); | 
					
						
							|  |  |  |                 $createdAt = new Carbon($value); | 
					
						
							|  |  |  |                 $this->collector->setCreatedAt($createdAt); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'updated_on': | 
					
						
							|  |  |  |                 Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value)); | 
					
						
							|  |  |  |                 $updatedAt = new Carbon($value); | 
					
						
							|  |  |  |                 $this->collector->setUpdatedAt($updatedAt); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             //
 | 
					
						
							| 
									
										
										
										
											2022-01-24 20:20:03 -07:00
										 |  |  |             // external URL
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             case 'no_external_url': | 
					
						
							|  |  |  |                 $this->collector->withoutExternalUrl(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'any_external_url': | 
					
						
							|  |  |  |                 $this->collector->withExternalUrl(); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             //
 | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             // other fields
 | 
					
						
							|  |  |  |             //
 | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |             case 'external_id': | 
					
						
							|  |  |  |                 $this->collector->setExternalId($value); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case 'internal_reference': | 
					
						
							|  |  |  |                 $this->collector->setInternalReference($value); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2020-08-09 18:58:18 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 09:15:40 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param string $operator | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function getRootOperator(string $operator): string | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $config = config(sprintf('firefly.search.operators.%s', $operator)); | 
					
						
							|  |  |  |         if (null === $config) { | 
					
						
							|  |  |  |             throw new FireflyException(sprintf('No configuration for search operator "%s"', $operator)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (true === $config['alias']) { | 
					
						
							|  |  |  |             Log::debug(sprintf('"%s" is an alias for "%s", so return that instead.', $operator, $config['alias_for'])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return $config['alias_for']; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         Log::debug(sprintf('"%s" is not an alias.', $operator)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $operator; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |      * searchDirection: 1 = source (default), 2 = destination | 
					
						
							|  |  |  |      * stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |      * @param int    $searchDirection | 
					
						
							|  |  |  |      * @param int    $stringPosition | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |     private function searchAccount(string $value, int $searchDirection, int $stringPosition): void | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-17 08:53:32 +02:00
										 |  |  |         Log::debug(sprintf('searchAccount("%s", %d, %d)', $value, $stringPosition, $searchDirection)); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // search direction (default): for source accounts
 | 
					
						
							|  |  |  |         $searchTypes     = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::REVENUE]; | 
					
						
							|  |  |  |         $collectorMethod = 'setSourceAccounts'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // search direction: for destination accounts
 | 
					
						
							|  |  |  |         if (2 === $searchDirection) { | 
					
						
							|  |  |  |             // destination can be
 | 
					
						
							|  |  |  |             $searchTypes     = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE]; | 
					
						
							|  |  |  |             $collectorMethod = 'setDestinationAccounts'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // string position (default): starts with:
 | 
					
						
							|  |  |  |         $stringMethod = 'str_starts_with'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // string position: ends with:
 | 
					
						
							|  |  |  |         if (2 === $stringPosition) { | 
					
						
							|  |  |  |             $stringMethod = 'str_ends_with'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (3 === $stringPosition) { | 
					
						
							|  |  |  |             $stringMethod = 'str_contains'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (4 === $stringPosition) { | 
					
						
							|  |  |  |             $stringMethod = 'str_is_equal'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // get accounts:
 | 
					
						
							|  |  |  |         $accounts = $this->accountRepository->searchAccount($value, $searchTypes, 25); | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |         if (0 === $accounts->count()) { | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |             Log::debug('Found zero accounts, search for non existing account, NO results will be returned.'); | 
					
						
							|  |  |  |             $this->collector->findNothing(); | 
					
						
							| 
									
										
										
										
											2020-09-23 19:32:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         Log::debug(sprintf('Found %d accounts, will filter.', $accounts->count())); | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |         $filtered = $accounts->filter( | 
					
						
							|  |  |  |             function (Account $account) use ($value, $stringMethod) { | 
					
						
							|  |  |  |                 return $stringMethod(strtolower($account->name), strtolower($value)); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |         if (0 === $filtered->count()) { | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |             Log::debug('Left with zero accounts, so cannot find anything, NO results will be returned.'); | 
					
						
							|  |  |  |             $this->collector->findNothing(); | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         Log::debug(sprintf('Left with %d, set as %s().', $filtered->count(), $collectorMethod)); | 
					
						
							|  |  |  |         $this->collector->$collectorMethod($filtered); | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |      * searchDirection: 1 = source (default), 2 = destination | 
					
						
							|  |  |  |      * stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |      * @param int    $searchDirection | 
					
						
							|  |  |  |      * @param int    $stringPosition | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |     private function searchAccountNr(string $value, int $searchDirection, int $stringPosition): void | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         Log::debug(sprintf('searchAccountNr(%s, %d, %d)', $value, $searchDirection, $stringPosition)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // search direction (default): for source accounts
 | 
					
						
							|  |  |  |         $searchTypes     = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::REVENUE]; | 
					
						
							|  |  |  |         $collectorMethod = 'setSourceAccounts'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // search direction: for destination accounts
 | 
					
						
							|  |  |  |         if (2 === $searchDirection) { | 
					
						
							|  |  |  |             // destination can be
 | 
					
						
							|  |  |  |             $searchTypes     = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE]; | 
					
						
							|  |  |  |             $collectorMethod = 'setDestinationAccounts'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // string position (default): starts with:
 | 
					
						
							|  |  |  |         $stringMethod = 'str_starts_with'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // string position: ends with:
 | 
					
						
							|  |  |  |         if (2 === $stringPosition) { | 
					
						
							|  |  |  |             $stringMethod = 'str_ends_with'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (3 === $stringPosition) { | 
					
						
							|  |  |  |             $stringMethod = 'str_contains'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (4 === $stringPosition) { | 
					
						
							|  |  |  |             $stringMethod = 'str_is_equal'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // search for accounts:
 | 
					
						
							|  |  |  |         $accounts = $this->accountRepository->searchAccountNr($value, $searchTypes, 25); | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |         if (0 === $accounts->count()) { | 
					
						
							| 
									
										
										
										
											2020-09-23 19:32:46 +02:00
										 |  |  |             Log::debug('Found zero accounts, search for invalid account.'); | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |             $this->collector->findNothing(); | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // if found, do filter
 | 
					
						
							|  |  |  |         Log::debug(sprintf('Found %d accounts, will filter.', $accounts->count())); | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |         $filtered = $accounts->filter( | 
					
						
							|  |  |  |             function (Account $account) use ($value, $stringMethod) { | 
					
						
							|  |  |  |                 // either IBAN or account number!
 | 
					
						
							|  |  |  |                 $ibanMatch      = $stringMethod(strtolower((string)$account->iban), strtolower((string)$value)); | 
					
						
							|  |  |  |                 $accountNrMatch = false; | 
					
						
							|  |  |  |                 /** @var AccountMeta $meta */ | 
					
						
							|  |  |  |                 foreach ($account->accountMeta as $meta) { | 
					
						
							|  |  |  |                     if ('account_number' === $meta->name && $stringMethod(strtolower($meta->data), strtolower($value))) { | 
					
						
							|  |  |  |                         $accountNrMatch = true; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return $ibanMatch || $accountNrMatch; | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |         if (0 === $filtered->count()) { | 
					
						
							| 
									
										
										
										
											2020-09-23 19:32:46 +02:00
										 |  |  |             Log::debug('Left with zero, search for invalid account'); | 
					
						
							| 
									
										
										
										
											2021-09-17 08:46:03 +02:00
										 |  |  |             $this->collector->findNothing(); | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-23 19:32:46 +02:00
										 |  |  |         Log::debug(sprintf('Left with %d, set as %s().', $filtered->count(), $collectorMethod)); | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         $this->collector->$collectorMethod($filtered); | 
					
						
							| 
									
										
										
										
											2020-08-18 17:48:27 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 09:15:40 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return Account | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function getCashAccount(): Account | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->accountRepository->getCashAccount(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |      * @return TransactionCurrency|null | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function findCurrency(string $value): ?TransactionCurrency | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-09-09 06:10:00 +02:00
										 |  |  |         if (str_contains($value, '(') && str_contains($value, ')')) { | 
					
						
							| 
									
										
										
										
											2020-08-28 06:09:04 +02:00
										 |  |  |             // bad method to split and get the currency code:
 | 
					
						
							|  |  |  |             $parts = explode(' ', $value); | 
					
						
							| 
									
										
										
										
											2020-09-09 06:10:00 +02:00
										 |  |  |             $value = trim($parts[count($parts) - 1], "() \t\n\r\0\x0B"); | 
					
						
							| 
									
										
										
										
											2020-08-28 06:09:04 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         $result = $this->currencyRepository->findByCodeNull($value); | 
					
						
							|  |  |  |         if (null === $result) { | 
					
						
							|  |  |  |             $result = $this->currencyRepository->findByNameNull($value); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-22 12:24:01 +02:00
										 |  |  |         return $result; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |      * @return array | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function parseDateRange(string $value): array | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $parser = new ParseDateString; | 
					
						
							|  |  |  |         if ($parser->isDateRange($value)) { | 
					
						
							| 
									
										
										
										
											2021-12-17 17:27:29 +01:00
										 |  |  |             return $parser->parseRange($value); | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-05-24 08:06:56 +02:00
										 |  |  |         $parsedDate = $parser->parseDate($value); | 
					
						
							| 
									
										
										
										
											2020-10-24 07:40:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2021-12-17 17:27:29 +01:00
										 |  |  |             'exact' => $parsedDate, | 
					
						
							| 
									
										
										
										
											2020-08-22 13:01:37 +02:00
										 |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-22 16:55:54 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-03-21 09:15:40 +01:00
										 |  |  |      * @return array | 
					
						
							| 
									
										
										
										
											2020-08-26 20:18:27 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-03-21 09:15:40 +01:00
										 |  |  |     public function getWords(): array | 
					
						
							| 
									
										
										
										
											2020-08-26 20:18:27 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-21 09:15:40 +01:00
										 |  |  |         return $this->words; | 
					
						
							| 
									
										
										
										
											2020-08-26 20:18:27 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-17 17:27:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param array $range | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function setExactDateParams(array $range): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * @var string        $key | 
					
						
							|  |  |  |          * @var Carbon|string $value | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         foreach ($range as $key => $value) { | 
					
						
							|  |  |  |             switch ($key) { | 
					
						
							|  |  |  |                 default: | 
					
						
							|  |  |  |                     throw new FireflyException(sprintf('Cannot handle key "%s" in setExactParameters()', $key)); | 
					
						
							|  |  |  |                 case 'exact': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_exact value "%s"', $value->format('Y-m-d'))); | 
					
						
							|  |  |  |                     $this->collector->setRange($value, $value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_is', 'value' => $value->format('Y-m-d'),]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'year': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_exact YEAR value "%s"', $value)); | 
					
						
							|  |  |  |                     $this->collector->yearIs($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_is_year', 'value' => $value,]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'month': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_exact MONTH value "%s"', $value)); | 
					
						
							|  |  |  |                     $this->collector->monthIs($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_is_month', 'value' => $value,]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'day': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_exact DAY value "%s"', $value)); | 
					
						
							|  |  |  |                     $this->collector->dayIs($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_is_day', 'value' => $value,]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param array $range | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function setDateBeforeParams(array $range): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * @var string        $key | 
					
						
							|  |  |  |          * @var Carbon|string $value | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         foreach ($range as $key => $value) { | 
					
						
							|  |  |  |             switch ($key) { | 
					
						
							|  |  |  |                 default: | 
					
						
							|  |  |  |                     throw new FireflyException(sprintf('Cannot handle key "%s" in setDateBeforeParams()', $key)); | 
					
						
							|  |  |  |                 case 'exact': | 
					
						
							|  |  |  |                     $this->collector->setBefore($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_before', 'value' => $value->format('Y-m-d'),]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'year': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_before YEAR value "%s"', $value)); | 
					
						
							|  |  |  |                     $this->collector->yearBefore($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_before_year', 'value' => $value,]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'month': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_before MONTH value "%s"', $value)); | 
					
						
							|  |  |  |                     $this->collector->monthBefore($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_before_month', 'value' => $value,]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'day': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_before DAY value "%s"', $value)); | 
					
						
							|  |  |  |                     $this->collector->dayBefore($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_before_day', 'value' => $value,]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param array $range | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function setDateAfterParams(array $range) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * @var string        $key | 
					
						
							|  |  |  |          * @var Carbon|string $value | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         foreach ($range as $key => $value) { | 
					
						
							|  |  |  |             switch ($key) { | 
					
						
							|  |  |  |                 default: | 
					
						
							|  |  |  |                     throw new FireflyException(sprintf('Cannot handle key "%s" in setDateAfterParams()', $key)); | 
					
						
							|  |  |  |                 case 'exact': | 
					
						
							|  |  |  |                     $this->collector->setAfter($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_after', 'value' => $value->format('Y-m-d'),]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'year': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_after YEAR value "%s"', $value)); | 
					
						
							|  |  |  |                     $this->collector->yearAfter($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_after_year', 'value' => $value,]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'month': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_after MONTH value "%s"', $value)); | 
					
						
							|  |  |  |                     $this->collector->monthAfter($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_after_month', 'value' => $value,]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'day': | 
					
						
							|  |  |  |                     Log::debug(sprintf('Set date_is_after DAY value "%s"', $value)); | 
					
						
							|  |  |  |                     $this->collector->dayAfter($value); | 
					
						
							|  |  |  |                     $this->operators->push(['type' => 'date_after_day', 'value' => $value,]); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-12-22 05:35:06 +01:00
										 |  |  | } |