aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository/EntryRepository.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php53
1 files changed, 47 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 4f03ae0f..b9532fa2 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -20,8 +20,7 @@ class EntryRepository extends EntityRepository
20 private function getBuilderByUser($userId) 20 private function getBuilderByUser($userId)
21 { 21 {
22 return $this->createQueryBuilder('e') 22 return $this->createQueryBuilder('e')
23 ->leftJoin('e.user', 'u') 23 ->andWhere('e.user = :userId')->setParameter('userId', $userId)
24 ->andWhere('u.id = :userId')->setParameter('userId', $userId)
25 ->orderBy('e.createdAt', 'desc') 24 ->orderBy('e.createdAt', 'desc')
26 ; 25 ;
27 } 26 }
@@ -86,6 +85,36 @@ class EntryRepository extends EntityRepository
86 } 85 }
87 86
88 /** 87 /**
88 * Retrieves entries filtered with a search term for a user.
89 *
90 * @param int $userId
91 * @param string $term
92 * @param strint $currentRoute
93 *
94 * @return QueryBuilder
95 */
96 public function getBuilderForSearchByUser($userId, $term, $currentRoute)
97 {
98 $qb = $this
99 ->getBuilderByUser($userId);
100
101 if ('starred' === $currentRoute) {
102 $qb->andWhere('e.isStarred = true');
103 } elseif ('unread' === $currentRoute) {
104 $qb->andWhere('e.isArchived = false');
105 } elseif ('archive' === $currentRoute) {
106 $qb->andWhere('e.isArchived = true');
107 }
108
109 $qb
110 ->andWhere('e.content LIKE :term OR e.title LIKE :term')->setParameter('term', '%'.$term.'%')
111 ->leftJoin('e.tags', 't')
112 ->groupBy('e.id');
113
114 return $qb;
115 }
116
117 /**
89 * Retrieves untagged entries for a user. 118 * Retrieves untagged entries for a user.
90 * 119 *
91 * @param int $userId 120 * @param int $userId
@@ -96,9 +125,7 @@ class EntryRepository extends EntityRepository
96 { 125 {
97 return $this 126 return $this
98 ->getBuilderByUser($userId) 127 ->getBuilderByUser($userId)
99 ->leftJoin('e.tags', 't') 128 ->andWhere('size(e.tags) = 0');
100 ->groupBy('e.id')
101 ->having('count(t.id) = 0');
102 } 129 }
103 130
104 /** 131 /**
@@ -144,7 +171,7 @@ class EntryRepository extends EntityRepository
144 $qb->orderBy('e.updatedAt', $order); 171 $qb->orderBy('e.updatedAt', $order);
145 } 172 }
146 173
147 $pagerAdapter = new DoctrineORMAdapter($qb); 174 $pagerAdapter = new DoctrineORMAdapter($qb, true, false);
148 175
149 return new Pagerfanta($pagerAdapter); 176 return new Pagerfanta($pagerAdapter);
150 } 177 }
@@ -329,4 +356,18 @@ class EntryRepository extends EntityRepository
329 356
330 return $qb->getQuery()->getSingleScalarResult(); 357 return $qb->getQuery()->getSingleScalarResult();
331 } 358 }
359
360 /**
361 * Remove all entries for a user id.
362 * Used when a user want to reset all informations.
363 *
364 * @param int $userId
365 */
366 public function removeAllByUserId($userId)
367 {
368 $this->getEntityManager()
369 ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = :userId')
370 ->setParameter('userId', $userId)
371 ->execute();
372 }
332} 373}