mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 14:12:15 +00:00
Sort and cleanup code.
This commit is contained in:
@@ -39,6 +39,90 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
trait MetaCollection
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeBills(Collection $bills): GroupCollectorInterface
|
||||
{
|
||||
$this->withBillInformation();
|
||||
$this->query->where(static function (EloquentBuilder $q1) use ($bills) {
|
||||
$q1->whereNotIn('transaction_journals.bill_id', $bills->pluck('id')->toArray());
|
||||
$q1->orWhereNull('transaction_journals.bill_id');
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude a specific budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeBudget(Budget $budget): GroupCollectorInterface
|
||||
{
|
||||
$this->withBudgetInformation();
|
||||
|
||||
$this->query->where(static function (EloquentBuilder $q2) use ($budget) {
|
||||
$q2->where('budgets.id', '!=', $budget->id);
|
||||
$q2->orWhereNull('budgets.id');
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeBudgets(Collection $budgets): GroupCollectorInterface
|
||||
{
|
||||
if ($budgets->count() > 0) {
|
||||
$this->withBudgetInformation();
|
||||
$this->query->where(static function (EloquentBuilder $q1) use ($budgets) {
|
||||
$q1->whereNotIn('budgets.id', $budgets->pluck('id')->toArray());
|
||||
$q1->orWhereNull('budgets.id');
|
||||
});
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeCategories(Collection $categories): GroupCollectorInterface
|
||||
{
|
||||
if ($categories->count() > 0) {
|
||||
$this->withCategoryInformation();
|
||||
$this->query->where(static function (EloquentBuilder $q1) use ($categories) {
|
||||
$q1->whereNotIn('categories.id', $categories->pluck('id')->toArray());
|
||||
$q1->orWhereNull('categories.id');
|
||||
});
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude a specific category.
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeCategory(Category $category): GroupCollectorInterface
|
||||
{
|
||||
$this->withCategoryInformation();
|
||||
|
||||
$this->query->where(static function (EloquentBuilder $q2) use ($category) {
|
||||
$q2->where('categories.id', '!=', $category->id);
|
||||
$q2->orWhereNull('categories.id');
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -227,6 +311,30 @@ trait MetaCollection
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withNotes(): GroupCollectorInterface
|
||||
{
|
||||
if (false === $this->hasNotesInformation) {
|
||||
// join bill table
|
||||
$this->query->leftJoin(
|
||||
'notes',
|
||||
static function (JoinClause $join) {
|
||||
$join->on('notes.noteable_id', '=', 'transaction_journals.id');
|
||||
$join->where('notes.noteable_type', '=', 'FireflyIII\Models\TransactionJournal');
|
||||
$join->whereNull('notes.deleted_at');
|
||||
}
|
||||
);
|
||||
// add fields
|
||||
$this->fields[] = 'notes.text as notes';
|
||||
$this->hasNotesInformation = true;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
@@ -243,22 +351,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function notesDontStartWith(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
$this->query->where(static function (Builder $q) use ($value) {
|
||||
$q->whereNull('notes.text');
|
||||
$q->orWhere('notes.text', 'NOT LIKE', sprintf('%s%%', $value));
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
@@ -276,24 +368,17 @@ trait MetaCollection
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withNotes(): GroupCollectorInterface
|
||||
public function notesDontStartWith(string $value): GroupCollectorInterface
|
||||
{
|
||||
if (false === $this->hasNotesInformation) {
|
||||
// join bill table
|
||||
$this->query->leftJoin(
|
||||
'notes',
|
||||
static function (JoinClause $join) {
|
||||
$join->on('notes.noteable_id', '=', 'transaction_journals.id');
|
||||
$join->where('notes.noteable_type', '=', 'FireflyIII\Models\TransactionJournal');
|
||||
$join->whereNull('notes.deleted_at');
|
||||
}
|
||||
);
|
||||
// add fields
|
||||
$this->fields[] = 'notes.text as notes';
|
||||
$this->hasNotesInformation = true;
|
||||
}
|
||||
$this->withNotes();
|
||||
$this->query->where(static function (Builder $q) use ($value) {
|
||||
$q->whereNull('notes.text');
|
||||
$q->orWhere('notes.text', 'NOT LIKE', sprintf('%s%%', $value));
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -402,20 +487,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeBills(Collection $bills): GroupCollectorInterface
|
||||
{
|
||||
$this->withBillInformation();
|
||||
$this->query->where(static function(EloquentBuilder $q1) use ($bills) {
|
||||
$q1->whereNotIn('transaction_journals.bill_id', $bills->pluck('id')->toArray());
|
||||
$q1->orWhereNull('transaction_journals.bill_id');
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the search to a specific budget.
|
||||
*
|
||||
@@ -469,22 +540,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeBudgets(Collection $budgets): GroupCollectorInterface
|
||||
{
|
||||
if ($budgets->count() > 0) {
|
||||
$this->withBudgetInformation();
|
||||
$this->query->where(static function (EloquentBuilder $q1) use ($budgets) {
|
||||
$q1->whereNotIn('budgets.id', $budgets->pluck('id')->toArray());
|
||||
$q1->orWhereNull('budgets.id');
|
||||
});
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the search to a specific bunch of categories.
|
||||
*
|
||||
@@ -502,22 +557,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeCategories(Collection $categories): GroupCollectorInterface
|
||||
{
|
||||
if ($categories->count() > 0) {
|
||||
$this->withCategoryInformation();
|
||||
$this->query->where(static function (EloquentBuilder $q1) use ($categories) {
|
||||
$q1->whereNotIn('categories.id', $categories->pluck('id')->toArray());
|
||||
$q1->orWhereNull('categories.id');
|
||||
});
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will include category ID + name, if any.
|
||||
*
|
||||
@@ -554,44 +593,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude a specific category.
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeCategory(Category $category): GroupCollectorInterface
|
||||
{
|
||||
$this->withCategoryInformation();
|
||||
|
||||
$this->query->where(static function(EloquentBuilder $q2) use ($category) {
|
||||
$q2->where('categories.id','!=', $category->id);
|
||||
$q2->orWhereNull('categories.id');
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude a specific budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeBudget(Budget $budget): GroupCollectorInterface
|
||||
{
|
||||
$this->withBudgetInformation();
|
||||
|
||||
$this->query->where(static function(EloquentBuilder $q2) use ($budget) {
|
||||
$q2->where('budgets.id','!=', $budget->id);
|
||||
$q2->orWhereNull('budgets.id');
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user