diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 4f03ae0f..47e24d6b 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -86,6 +86,36 @@ class EntryRepository extends EntityRepository | |||
86 | } | 86 | } |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * Retrieves entries filtered with a search term for a user. | ||
90 | * | ||
91 | * @param int $userId | ||
92 | * @param string $term | ||
93 | * @param strint $currentRoute | ||
94 | * | ||
95 | * @return QueryBuilder | ||
96 | */ | ||
97 | public function getBuilderForSearchByUser($userId, $term, $currentRoute) | ||
98 | { | ||
99 | $qb = $this | ||
100 | ->getBuilderByUser($userId); | ||
101 | |||
102 | if ('starred' === $currentRoute) { | ||
103 | $qb->andWhere('e.isStarred = true'); | ||
104 | } elseif ('unread' === $currentRoute) { | ||
105 | $qb->andWhere('e.isArchived = false'); | ||
106 | } elseif ('archive' === $currentRoute) { | ||
107 | $qb->andWhere('e.isArchived = true'); | ||
108 | } | ||
109 | |||
110 | $qb | ||
111 | ->andWhere('e.content LIKE :term OR e.title LIKE :term')->setParameter('term', '%'.$term.'%') | ||
112 | ->leftJoin('e.tags', 't') | ||
113 | ->groupBy('e.id'); | ||
114 | |||
115 | return $qb; | ||
116 | } | ||
117 | |||
118 | /** | ||
89 | * Retrieves untagged entries for a user. | 119 | * Retrieves untagged entries for a user. |
90 | * | 120 | * |
91 | * @param int $userId | 121 | * @param int $userId |
@@ -329,4 +359,18 @@ class EntryRepository extends EntityRepository | |||
329 | 359 | ||
330 | return $qb->getQuery()->getSingleScalarResult(); | 360 | return $qb->getQuery()->getSingleScalarResult(); |
331 | } | 361 | } |
362 | |||
363 | /** | ||
364 | * Remove all entries for a user id. | ||
365 | * Used when a user want to reset all informations. | ||
366 | * | ||
367 | * @param int $userId | ||
368 | */ | ||
369 | public function removeAllByUserId($userId) | ||
370 | { | ||
371 | $this->getEntityManager() | ||
372 | ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = :userId') | ||
373 | ->setParameter('userId', $userId) | ||
374 | ->execute(); | ||
375 | } | ||
332 | } | 376 | } |