]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Start work on sort function.
authorThomas Citharel <tcit@tcit.fr>
Tue, 28 Jun 2016 12:59:31 +0000 (14:59 +0200)
committerNicolas LÅ“uillet <nicolas@loeuillet.org>
Tue, 28 Apr 2020 08:10:42 +0000 (10:10 +0200)
Backend is ready. Needs tests and proper UI

src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php

index 9b2954e7d5d0525711ac4a61dec9cbae3f6eeda1..cef299900d0636970c4e8e3c3a6477893446b3ec 100644 (file)
@@ -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));
index bfd079377ac783bdd4c2e0e2f84cb3f2e9d0496b..92d1867bf7532e924185b54862b6710d86330249 100644 (file)
@@ -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)
         ;
     }