mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-12 01:18:19 +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;
|
$fieldName = is_array($orderBy) ? key($orderBy) : $orderBy;
|
||||||
$order = is_array($orderBy) ? $orderBy[$fieldName] : 'ASC';
|
$order = is_array($orderBy) ? $orderBy[$fieldName] : 'ASC';
|
||||||
|
|
||||||
if (in_array($fieldName, [
|
if (in_array($fieldName, ['visits', 'visitsCount', 'visitCount'], true)) {
|
||||||
'visits',
|
|
||||||
'visitsCount',
|
|
||||||
'visitCount',
|
|
||||||
], true)) {
|
|
||||||
$qb->addSelect('COUNT(v) AS totalVisits')
|
$qb->addSelect('COUNT(v) AS totalVisits')
|
||||||
->leftJoin('s.visits', 'v')
|
->leftJoin('s.visits', 'v')
|
||||||
->groupBy('s')
|
->groupBy('s')
|
||||||
->orderBy('totalVisits', $order);
|
->orderBy('totalVisits', $order);
|
||||||
|
|
||||||
return array_column($qb->getQuery()->getResult(), 0);
|
return array_column($qb->getQuery()->getResult(), 0);
|
||||||
} elseif (in_array($fieldName, [
|
} elseif (in_array($fieldName, ['originalUrl', 'shortCode', 'dateCreated'], true)) {
|
||||||
'originalUrl',
|
|
||||||
'shortCode',
|
|
||||||
'dateCreated',
|
|
||||||
], true)) {
|
|
||||||
$qb->orderBy('s.' . $fieldName, $order);
|
$qb->orderBy('s.' . $fieldName, $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue