mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-03 17:22:32 +03:00
Refactored ShortUrlRepository to make it more readable
This commit is contained in:
parent
a24688b92a
commit
9577a4da4b
1 changed files with 2 additions and 10 deletions
|
@ -50,22 +50,14 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
|
|||
$fieldName = is_array($orderBy) ? key($orderBy) : $orderBy;
|
||||
$order = is_array($orderBy) ? $orderBy[$fieldName] : 'ASC';
|
||||
|
||||
if (in_array($fieldName, [
|
||||
'visits',
|
||||
'visitsCount',
|
||||
'visitCount',
|
||||
], true)) {
|
||||
if (in_array($fieldName, ['visits', 'visitsCount', 'visitCount'], true)) {
|
||||
$qb->addSelect('COUNT(v) AS totalVisits')
|
||||
->leftJoin('s.visits', 'v')
|
||||
->groupBy('s')
|
||||
->orderBy('totalVisits', $order);
|
||||
|
||||
return array_column($qb->getQuery()->getResult(), 0);
|
||||
} elseif (in_array($fieldName, [
|
||||
'originalUrl',
|
||||
'shortCode',
|
||||
'dateCreated',
|
||||
], true)) {
|
||||
} elseif (in_array($fieldName, ['originalUrl', 'shortCode', 'dateCreated'], true)) {
|
||||
$qb->orderBy('s.' . $fieldName, $order);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue