mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-03 20:14:31 +00:00
Code cleanup.
This commit is contained in:
@@ -36,12 +36,16 @@ class AccountSearch implements GenericSearchInterface
|
||||
{
|
||||
/** @var string */
|
||||
public const string SEARCH_ALL = 'all';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_IBAN = 'iban';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_ID = 'id';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_NAME = 'name';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_NUMBER = 'number';
|
||||
private string $field;
|
||||
@@ -54,17 +58,16 @@ class AccountSearch implements GenericSearchInterface
|
||||
$this->types = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function search(): Collection
|
||||
{
|
||||
$searchQuery = $this->user->accounts()
|
||||
->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->whereIn('account_types.type', $this->types);
|
||||
->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->whereIn('account_types.type', $this->types)
|
||||
;
|
||||
$like = sprintf('%%%s%%', $this->query);
|
||||
$originalQuery = $this->query;
|
||||
|
||||
switch ($this->field) {
|
||||
default:
|
||||
case self::SEARCH_ALL:
|
||||
@@ -83,16 +86,24 @@ class AccountSearch implements GenericSearchInterface
|
||||
$q->where('account_meta.data', 'LIKE', $json);
|
||||
}
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case self::SEARCH_ID:
|
||||
$searchQuery->where('accounts.id', '=', (int)$originalQuery);
|
||||
|
||||
break;
|
||||
|
||||
case self::SEARCH_NAME:
|
||||
$searchQuery->where('accounts.name', 'LIKE', $like);
|
||||
|
||||
break;
|
||||
|
||||
case self::SEARCH_IBAN:
|
||||
$searchQuery->where('accounts.iban', 'LIKE', $like);
|
||||
|
||||
break;
|
||||
|
||||
case self::SEARCH_NUMBER:
|
||||
// meta data:
|
||||
$searchQuery->Where(
|
||||
@@ -102,42 +113,29 @@ class AccountSearch implements GenericSearchInterface
|
||||
$q->where('account_meta.data', $json);
|
||||
}
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $searchQuery->distinct()->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*/
|
||||
public function setField(string $field): void
|
||||
{
|
||||
$this->field = $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
*/
|
||||
public function setQuery(string $query): void
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*/
|
||||
public function setTypes(array $types): void
|
||||
{
|
||||
$this->types = $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
public function setUser(null|Authenticatable|User $user): void
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$this->user = $user;
|
||||
|
||||
@@ -31,8 +31,5 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface GenericSearchInterface
|
||||
{
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function search(): Collection;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -33,63 +33,27 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface SearchInterface
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getInvalidOperators(): array;
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getModifiers(): Collection;
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getOperators(): Collection;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWordsAsString(): string;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasModifiers(): bool;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
*/
|
||||
public function parseQuery(string $query): void;
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function searchTime(): float;
|
||||
|
||||
/**
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function searchTransactions(): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public function setDate(Carbon $date): void;
|
||||
|
||||
/**
|
||||
* @param int $limit
|
||||
*/
|
||||
public function setLimit(int $limit): void;
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*/
|
||||
public function setPage(int $page): void;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user