From: Thomas Citharel Date: Tue, 28 Jun 2016 12:59:31 +0000 (+0200) Subject: Start work on sort function. X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;ds=sidebyside;h=8d2527ec528d1631be21967137f63d2fc0cf218f;p=github%2Fwallabag%2Fwallabag.git Start work on sort function. Backend is ready. Needs tests and proper UI --- diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 9b2954e7..cef29990 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -532,24 +532,27 @@ class EntryController extends Controller $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); + $sortBy = $request->get('sort', 'id'); + $direction = $request->get('direction', 'DESC'); + switch ($type) { case 'search': $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute); break; case 'untagged': - $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId()); + $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId(), $sortBy, $direction); break; case 'starred': - $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId()); + $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId(), $sortBy, $direction); break; case 'archive': - $qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId()); + $qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId(), $sortBy, $direction); break; case 'unread': - $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId()); + $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId(), $sortBy, $direction); break; case 'all': - $qb = $repository->getBuilderForAllByUser($this->getUser()->getId()); + $qb = $repository->getBuilderForAllByUser($this->getUser()->getId(), $sortBy, $direction); break; default: throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index bfd07937..92d1867b 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -20,10 +20,10 @@ class EntryRepository extends EntityRepository * * @return QueryBuilder */ - public function getBuilderForAllByUser($userId) + public function getBuilderForAllByUser($userId, $sortBy = 'id', $direction = 'DESC') { return $this - ->getSortedQueryBuilderByUser($userId) + ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) ; } @@ -34,11 +34,12 @@ class EntryRepository extends EntityRepository * * @return QueryBuilder */ - public function getBuilderForUnreadByUser($userId) + public function getBuilderForUnreadByUser($userId, $sortBy = 'id', $direction = 'DESC') { return $this ->getSortedQueryBuilderByUser($userId) ->andWhere('e.isArchived = false') + ->orderBy('e.'.$sortBy, $direction) ; } @@ -49,11 +50,12 @@ class EntryRepository extends EntityRepository * * @return QueryBuilder */ - public function getBuilderForArchiveByUser($userId) + public function getBuilderForArchiveByUser($userId, $sortBy = 'id', $direction = 'DESC') { return $this ->getSortedQueryBuilderByUser($userId, 'archivedAt', 'desc') ->andWhere('e.isArchived = true') + ->orderBy('e.'.$sortBy, $direction) ; } @@ -64,11 +66,12 @@ class EntryRepository extends EntityRepository * * @return QueryBuilder */ - public function getBuilderForStarredByUser($userId) + public function getBuilderForStarredByUser($userId, $sortBy = 'id', $direction = 'DESC') { return $this ->getSortedQueryBuilderByUser($userId, 'starredAt', 'desc') ->andWhere('e.isStarred = true') + ->orderBy('e.'.$sortBy, $direction) ; }