From 136f710ddb48f01e24892c5d2dde3b1f3a069fc4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 7 Jun 2019 17:58:11 +0200 Subject: Fix sort --- src/Wallabag/CoreBundle/Controller/EntryController.php | 2 +- src/Wallabag/CoreBundle/Repository/EntryRepository.php | 15 ++++++++++++++- .../views/themes/material/Entry/entries.html.twig | 6 ++---- .../Resources/views/themes/material/layout.html.twig | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index b3ec7729..5157653c 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -535,7 +535,7 @@ class EntryController extends Controller // defined as null by default because each repository method have the right field as default value too // like `getBuilderForStarredByUser` will have `starredAt` sort by default $sortBy = null; - if (in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { + if (\in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { $sortBy = $request->get('sort', null); } 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 */ public function getBuilderForAllByUser($userId, $sortBy = 'id', $direction = 'DESC') { + $sortBy = $sortBy ?: 'id'; + return $this ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) ; @@ -40,6 +42,8 @@ class EntryRepository extends EntityRepository */ public function getBuilderForUnreadByUser($userId, $sortBy = 'id', $direction = 'DESC') { + $sortBy = $sortBy ?: 'id'; + return $this ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) ->andWhere('e.isArchived = false') @@ -57,6 +61,8 @@ class EntryRepository extends EntityRepository */ public function getBuilderForArchiveByUser($userId, $sortBy = 'archivedAt', $direction = 'DESC') { + $sortBy = $sortBy ?: 'archivedAt'; + return $this ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) ->andWhere('e.isArchived = true') @@ -74,6 +80,8 @@ class EntryRepository extends EntityRepository */ public function getBuilderForStarredByUser($userId, $sortBy = 'starredAt', $direction = 'DESC') { + $sortBy = $sortBy ?: 'starredAt'; + return $this ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) ->andWhere('e.isStarred = true') @@ -579,6 +587,11 @@ class EntryRepository extends EntityRepository */ private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc') { - return $qb->orderBy(sprintf('e.%s', $sortBy), $direction); + // in case one of these isn't defined, don't apply the orderBy + if (!$sortBy || !$direction) { + return $qb; + } + + return $qb->orderBy(sprintf('e.%s', $sortBy), strtoupper($direction)); } } diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index deeb19a3..1654a0e0 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig @@ -210,8 +210,7 @@ {% endif %} -
- +

{{ 'entry.sort.title'|trans }}

@@ -239,9 +238,8 @@
- - {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} + {# {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} #} {% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig index 95d7da9a..0c3d4d5b 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig @@ -93,7 +93,7 @@
  • - + sort_by_alpha
  • -- cgit v1.2.3