diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index cf1cdb8a..aa761df3 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -24,6 +24,8 @@ class EntryRepository extends EntityRepository | |||
24 | */ | 24 | */ |
25 | public function getBuilderForAllByUser($userId, $sortBy = 'id', $direction = 'DESC') | 25 | public function getBuilderForAllByUser($userId, $sortBy = 'id', $direction = 'DESC') |
26 | { | 26 | { |
27 | $sortBy = $sortBy ?: 'id'; | ||
28 | |||
27 | return $this | 29 | return $this |
28 | ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) | 30 | ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) |
29 | ; | 31 | ; |
@@ -40,6 +42,8 @@ class EntryRepository extends EntityRepository | |||
40 | */ | 42 | */ |
41 | public function getBuilderForUnreadByUser($userId, $sortBy = 'id', $direction = 'DESC') | 43 | public function getBuilderForUnreadByUser($userId, $sortBy = 'id', $direction = 'DESC') |
42 | { | 44 | { |
45 | $sortBy = $sortBy ?: 'id'; | ||
46 | |||
43 | return $this | 47 | return $this |
44 | ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) | 48 | ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) |
45 | ->andWhere('e.isArchived = false') | 49 | ->andWhere('e.isArchived = false') |
@@ -57,6 +61,8 @@ class EntryRepository extends EntityRepository | |||
57 | */ | 61 | */ |
58 | public function getBuilderForArchiveByUser($userId, $sortBy = 'archivedAt', $direction = 'DESC') | 62 | public function getBuilderForArchiveByUser($userId, $sortBy = 'archivedAt', $direction = 'DESC') |
59 | { | 63 | { |
64 | $sortBy = $sortBy ?: 'archivedAt'; | ||
65 | |||
60 | return $this | 66 | return $this |
61 | ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) | 67 | ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) |
62 | ->andWhere('e.isArchived = true') | 68 | ->andWhere('e.isArchived = true') |
@@ -74,6 +80,8 @@ class EntryRepository extends EntityRepository | |||
74 | */ | 80 | */ |
75 | public function getBuilderForStarredByUser($userId, $sortBy = 'starredAt', $direction = 'DESC') | 81 | public function getBuilderForStarredByUser($userId, $sortBy = 'starredAt', $direction = 'DESC') |
76 | { | 82 | { |
83 | $sortBy = $sortBy ?: 'starredAt'; | ||
84 | |||
77 | return $this | 85 | return $this |
78 | ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) | 86 | ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) |
79 | ->andWhere('e.isStarred = true') | 87 | ->andWhere('e.isStarred = true') |
@@ -579,6 +587,11 @@ class EntryRepository extends EntityRepository | |||
579 | */ | 587 | */ |
580 | private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc') | 588 | private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc') |
581 | { | 589 | { |
582 | return $qb->orderBy(sprintf('e.%s', $sortBy), $direction); | 590 | // in case one of these isn't defined, don't apply the orderBy |
591 | if (!$sortBy || !$direction) { | ||
592 | return $qb; | ||
593 | } | ||
594 | |||
595 | return $qb->orderBy(sprintf('e.%s', $sortBy), strtoupper($direction)); | ||
583 | } | 596 | } |
584 | } | 597 | } |