mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Expand search
This commit is contained in:
@@ -32,33 +32,20 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
*/
|
||||
trait CollectorProperties
|
||||
{
|
||||
/** @var array The standard fields to select. */
|
||||
private $fields;
|
||||
/** @var bool Will be set to true if query result contains account information. (see function withAccountInformation). */
|
||||
private $hasAccountInfo;
|
||||
/** @var bool Will be true if query result includes bill information. */
|
||||
private $hasBillInformation;
|
||||
/** @var bool Will be true if query result contains budget info. */
|
||||
private $hasBudgetInformation;
|
||||
/** @var bool Will be true if query result contains category info. */
|
||||
private $hasCatInformation;
|
||||
/** @var bool Will be true for attachments */
|
||||
private $hasJoinedAttTables;
|
||||
private array $fields;
|
||||
private bool $hasAccountInfo;
|
||||
private bool $hasBillInformation;
|
||||
private bool $hasBudgetInformation;
|
||||
private bool $hasCatInformation;
|
||||
private bool $hasJoinedAttTables;
|
||||
private bool $hasJoinedMetaTables;
|
||||
/** @var bool Will be true of the query has the tag info tables joined. */
|
||||
private $hasJoinedTagTables;
|
||||
/** @var bool */
|
||||
private $hasNotesInformation;
|
||||
/** @var array */
|
||||
private $integerFields;
|
||||
/** @var int The maximum number of results. */
|
||||
private $limit;
|
||||
/** @var int The page to return. */
|
||||
private $page;
|
||||
/** @var HasMany The query object. */
|
||||
private $query;
|
||||
/** @var int Total number of results. */
|
||||
private $total;
|
||||
/** @var User The user object. */
|
||||
private $user;
|
||||
private bool $hasJoinedTagTables;
|
||||
private bool $hasNotesInformation;
|
||||
private array $integerFields;
|
||||
private ?int $limit;
|
||||
private ?int $page;
|
||||
private HasMany $query;
|
||||
private int $total;
|
||||
private ?User $user;
|
||||
private array $postFilters;
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ use FireflyIII\Models\Tag;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Trait MetaCollection
|
||||
@@ -295,6 +296,35 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Without tags
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setWithoutSpecificTags(Collection $tags): GroupCollectorInterface
|
||||
{
|
||||
$this->withTagInformation();
|
||||
|
||||
// this method adds a "postFilter" to the collector.
|
||||
$list = $tags->pluck('tag')->toArray();
|
||||
$filter = function (int $index, array $object) use ($list): bool {
|
||||
foreach($object['transactions'] as $transaction) {
|
||||
foreach($transaction['tags'] as $tag) {
|
||||
if(in_array($tag['name'], $list)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
@@ -307,7 +337,7 @@ trait MetaCollection
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit results to transactions without a bill..
|
||||
* Limit results to transactions without a bill.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
|
@@ -55,6 +55,11 @@ class GroupCollector implements GroupCollectorInterface
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->postFilters = [];
|
||||
$this->user = null;
|
||||
$this->limit = null;
|
||||
$this->page = null;
|
||||
|
||||
$this->hasAccountInfo = false;
|
||||
$this->hasCatInformation = false;
|
||||
$this->hasBudgetInformation = false;
|
||||
@@ -240,7 +245,12 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$result = $this->query->get($this->fields);
|
||||
|
||||
// now to parse this into an array.
|
||||
$collection = $this->parseArray($result);
|
||||
$collection = $this->parseArray($result);
|
||||
|
||||
// filter the array using all available post filters:
|
||||
$collection = $this->postFilterCollection($collection);
|
||||
|
||||
// count it and continue:
|
||||
$this->total = $collection->count();
|
||||
|
||||
// now filter the array according to the page and the limit (if necessary)
|
||||
@@ -730,7 +740,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
// also merge attachments:
|
||||
if (array_key_exists('attachment_id', $result)) {
|
||||
$uploaded = 1 === (int)$result['attachment_uploaded'];
|
||||
$uploaded = 1 === (int) $result['attachment_uploaded'];
|
||||
$attachmentId = (int) $augumentedJournal['attachment_id'];
|
||||
if (0 !== $attachmentId && $uploaded) {
|
||||
$result['attachments'][$attachmentId] = [
|
||||
@@ -738,6 +748,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
];
|
||||
}
|
||||
}
|
||||
// unset various fields:
|
||||
unset($result['tag_id'], $result['tag_name'], $result['tag_date'], $result['tag_description'], $result['tag_latitude'], $result['tag_longitude'], $result['tag_zoom_level']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -789,4 +801,27 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
* @return Collection
|
||||
*/
|
||||
private function postFilterCollection(Collection $collection): Collection
|
||||
{
|
||||
Log::debug('Now in postFilterCollection()');
|
||||
$newCollection = new Collection;
|
||||
foreach ($collection as $i => $item) {
|
||||
Log::debug(sprintf('Now working on item #%d/%d', $i + 1, $collection->count()));
|
||||
foreach ($this->postFilters as $func) {
|
||||
if (false === $func($i, $item)) {
|
||||
// skip other filters, continue to next item.
|
||||
Log::debug('Filter returns false, jump to next item.');
|
||||
continue 2;
|
||||
}
|
||||
Log::debug('Filter returns true');
|
||||
}
|
||||
$newCollection->push($item);
|
||||
}
|
||||
return $newCollection;
|
||||
}
|
||||
}
|
||||
|
@@ -419,6 +419,15 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Only when does not have these tags
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setWithoutSpecificTags(Collection $tags): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Limit the search to one specific transaction group.
|
||||
*
|
||||
|
Reference in New Issue
Block a user