]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
sort entries in repository 1048/head
authorNicolas Lœuillet <nicolas@loeuillet.org>
Thu, 5 Feb 2015 06:54:04 +0000 (07:54 +0100)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Thu, 5 Feb 2015 06:54:04 +0000 (07:54 +0100)
src/Wallabag/CoreBundle/Repository/EntriesRepository.php

index dd92d5200426ee4c004513eaf1c2a90099d090fa..ae854e5a91b8fbe1ed3da3f85c121c38c03a1d59 100644 (file)
@@ -26,6 +26,7 @@ class EntriesRepository extends EntityRepository
             ->where('e.isRead = 0')
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
             ->andWhere('e.isDeleted=0')
+            ->orderBy('e.createdAt', 'desc')
             ->getQuery();
 
         $paginator = new Paginator($qb);
@@ -50,6 +51,7 @@ class EntriesRepository extends EntityRepository
             ->where('e.isRead = 1')
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
             ->andWhere('e.isDeleted=0')
+            ->orderBy('e.createdAt', 'desc')
             ->getQuery();
 
         $paginator = new Paginator($qb);
@@ -74,6 +76,7 @@ class EntriesRepository extends EntityRepository
             ->where('e.isFav = 1')
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
             ->andWhere('e.isDeleted=0')
+            ->orderBy('e.createdAt', 'desc')
             ->getQuery();
 
         $paginator = new Paginator($qb);
@@ -83,7 +86,6 @@ class EntriesRepository extends EntityRepository
 
     public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order)
     {
-        //TODO tous les paramètres ne sont pas utilisés, à corriger
         $qb = $this->createQueryBuilder('e')
             ->select('e')
             ->where('e.userId =:userId')->setParameter('userId', $userId);
@@ -100,6 +102,12 @@ class EntriesRepository extends EntityRepository
             $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted);
         }
 
+        if ('created' === $sort) {
+            $qb->orderBy('e.createdAt', $order);
+        } elseif ('updated' === $sort) {
+            $qb->orderBy('e.updatedAt', $order);
+        }
+
         return $qb
             ->getQuery()
             ->getResult(Query::HYDRATE_ARRAY);