mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-18 07:38:29 +00:00
Remove various sort routines.
This commit is contained in:
@@ -226,17 +226,12 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
/** @var Collection $result */
|
||||
$query = $this->user->accounts();
|
||||
|
||||
if (\count($accountIds) > 0) {
|
||||
if (count($accountIds) > 0) {
|
||||
$query->whereIn('accounts.id', $accountIds);
|
||||
}
|
||||
$query->orderBy('accounts.name','ASC');
|
||||
|
||||
$result = $query->get(['accounts.*']);
|
||||
$result = $result->sortBy(
|
||||
function (Account $account) {
|
||||
return strtolower($account->name);
|
||||
}
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -252,13 +247,9 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
if (\count($types) > 0) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
|
||||
$query->orderBy('accounts.name','ASC');
|
||||
$result = $query->get(['accounts.*']);
|
||||
$result = $result->sortBy(
|
||||
function (Account $account) {
|
||||
return strtolower($account->name);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -280,12 +271,9 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
$query->where('active', 1);
|
||||
$query->orderBy('accounts.account_type_id','ASC');
|
||||
$query->orderBy('accounts.name','ASC');
|
||||
$result = $query->get(['accounts.*']);
|
||||
$result = $result->sortBy(
|
||||
function (Account $account) {
|
||||
return sprintf('%02d', $account->account_type_id) . strtolower($account->name);
|
||||
}
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -564,13 +552,15 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function searchAccount(string $query, array $types): Collection
|
||||
{
|
||||
$dbQuery = $this->user->accounts();
|
||||
$search = sprintf('%%%s%%', $query);
|
||||
if (\count($types) > 0) {
|
||||
$dbQuery = $this->user->accounts()->with(['accountType']);
|
||||
if ('' !== $query) {
|
||||
$search = sprintf('%%%s%%', $query);
|
||||
$dbQuery->where('name', 'LIKE', $search);
|
||||
}
|
||||
if (count($types) > 0) {
|
||||
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$dbQuery->whereIn('account_types.type', $types);
|
||||
}
|
||||
$dbQuery->where('name', 'LIKE', $search);
|
||||
|
||||
return $dbQuery->get(['accounts.*']);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
public function findBill( ?int $billId, ?string $billName): ?Bill
|
||||
public function findBill(?int $billId, ?string $billName): ?Bill
|
||||
{
|
||||
if (null !== $billId) {
|
||||
$searchResult = $this->find((int)$billId);
|
||||
@@ -146,8 +146,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->bills()
|
||||
->where('active', 1)
|
||||
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),])
|
||||
->sortBy('name');
|
||||
->orderBy('bills.name', 'ASC')
|
||||
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]);
|
||||
|
||||
return $set;
|
||||
}
|
||||
@@ -170,15 +170,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
public function getBills(): Collection
|
||||
{
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->bills()->orderBy('name', 'ASC')->get();
|
||||
|
||||
$set = $set->sortBy(
|
||||
function (Bill $bill) {
|
||||
$int = $bill->active ? 0 : 1;
|
||||
|
||||
return $int . strtolower($bill->name);
|
||||
}
|
||||
);
|
||||
$set = $this->user->bills()->orderBy('active', 'DESC')->orderBy('name', 'ASC')->get();
|
||||
|
||||
return $set;
|
||||
}
|
||||
@@ -210,17 +202,11 @@ class BillRepository implements BillRepositoryInterface
|
||||
)
|
||||
->whereIn('transactions.account_id', $ids)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->orderBy('bills.active', 'DESC')
|
||||
->orderBy('bills.name', 'ASC')
|
||||
->groupBy($fields)
|
||||
->get($fields);
|
||||
|
||||
$set = $set->sortBy(
|
||||
function (Bill $bill) {
|
||||
$int = $bill->active ? 0 : 1;
|
||||
|
||||
return $int . strtolower($bill->name);
|
||||
}
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
@@ -312,16 +312,10 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->budgets()->where('active', 1)
|
||||
->orderBy('order','DESC')
|
||||
->orderBy('name', 'ASC')
|
||||
->get();
|
||||
|
||||
$set = $set->sortBy(
|
||||
function (Budget $budget) {
|
||||
$str = str_pad((string)$budget->order, 4, '0', STR_PAD_LEFT) . strtolower($budget->name);
|
||||
|
||||
return $str;
|
||||
}
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
@@ -596,15 +590,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
public function getBudgets(): Collection
|
||||
{
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->budgets()->get();
|
||||
|
||||
$set = $set->sortBy(
|
||||
function (Budget $budget) {
|
||||
$str = str_pad((string)$budget->order, 4, '0', STR_PAD_LEFT) . strtolower($budget->name);
|
||||
|
||||
return $str;
|
||||
}
|
||||
);
|
||||
$set = $this->user->budgets()->orderBy('order','DESC')
|
||||
->orderBy('name', 'ASC')->get();
|
||||
|
||||
return $set;
|
||||
}
|
||||
@@ -629,15 +616,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
public function getInactiveBudgets(): Collection
|
||||
{
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->budgets()->where('active', 0)->get();
|
||||
|
||||
$set = $set->sortBy(
|
||||
function (Budget $budget) {
|
||||
$str = str_pad((string)$budget->order, 4, '0', STR_PAD_LEFT) . strtolower($budget->name);
|
||||
|
||||
return $str;
|
||||
}
|
||||
);
|
||||
$set = $this->user->budgets()->orderBy('order','DESC')
|
||||
->orderBy('name', 'ASC')->where('active', 0)->get();
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
@@ -344,11 +344,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->categories()->orderBy('name', 'ASC')->get();
|
||||
$set = $set->sortBy(
|
||||
function (Category $category) {
|
||||
return strtolower($category->name);
|
||||
}
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
@@ -117,15 +117,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
*/
|
||||
public function findByTag(string $tag): ?Tag
|
||||
{
|
||||
$tags = $this->user->tags()->get();
|
||||
/** @var Tag $databaseTag */
|
||||
foreach ($tags as $databaseTag) {
|
||||
if ($databaseTag->tag === $tag) {
|
||||
return $databaseTag;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->user->tags()->where('tag', $tag)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,12 +151,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
public function get(): Collection
|
||||
{
|
||||
/** @var Collection $tags */
|
||||
$tags = $this->user->tags()->get();
|
||||
$tags = $tags->sortBy(
|
||||
function (Tag $tag) {
|
||||
return strtolower($tag->tag);
|
||||
}
|
||||
);
|
||||
$tags = $this->user->tags()->orderBy('tag', 'ASC')->get();
|
||||
|
||||
return $tags;
|
||||
}
|
||||
@@ -219,6 +206,25 @@ class TagRepository implements TagRepositoryInterface
|
||||
return $this->user->tags()->whereNotNull('date')->orderBy('date', 'ASC')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the users tags.
|
||||
*
|
||||
* @param string $query
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchTags(string $query): Collection
|
||||
{
|
||||
/** @var Collection $tags */
|
||||
$tags = $this->user->tags()->orderBy('tag', 'ASC');
|
||||
if ('' !== $query) {
|
||||
$search = sprintf('%%%s%%', $query);
|
||||
$tags->where('tag', 'LIKE', $search);
|
||||
}
|
||||
|
||||
return $tags->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
|
||||
@@ -122,6 +122,15 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function oldestTag(): ?Tag;
|
||||
|
||||
/**
|
||||
* Search the users tags.
|
||||
*
|
||||
* @param string $query
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchTags(string $query): Collection;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user