From 49b042dfdf33a0efd3c838e1476754e6019730d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 10 Nov 2016 15:23:53 +0100 Subject: Added translations and currentRoute parameter --- .../CoreBundle/Repository/EntryRepository.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/CoreBundle/Repository') diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 8f23164f..51cfe4d1 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -90,18 +90,30 @@ class EntryRepository extends EntityRepository * * @param int $userId * @param string $term + * @param strint $currentRoute * * @return QueryBuilder */ - public function getBuilderForSearchByUser($userId, $term) + public function getBuilderForSearchByUser($userId, $term, $currentRoute) { - return $this - ->getBuilderByUser($userId) - ->andWhere('e.content LIKE :term')->setParameter('term', '%'.$term.'%') - ->orWhere('e.title LIKE :term')->setParameter('term', '%'.$term.'%') + $qb = $this + ->getBuilderByUser($userId); + + if ('starred' === $currentRoute) { + $qb->andWhere('e.isStarred = true'); + } elseif ('unread' === $currentRoute) { + $qb->andWhere('e.isArchived = false'); + } elseif ('archive' === $currentRoute) { + $qb->andWhere('e.isArchived = true'); + } + + $qb + ->andWhere('e.content LIKE :term OR e.title LIKE :term')->setParameter('term', '%'.$term.'%') ->leftJoin('e.tags', 't') ->groupBy('e.id') ->having('count(t.id) = 0'); + + return $qb; } /** -- cgit v1.2.3