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.php67
1 files changed, 65 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 4d45e5f5..cd2b47b9 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -3,6 +3,7 @@
3namespace Wallabag\CoreBundle\Repository; 3namespace Wallabag\CoreBundle\Repository;
4 4
5use Doctrine\ORM\EntityRepository; 5use Doctrine\ORM\EntityRepository;
6use Doctrine\ORM\Query;
6use Pagerfanta\Adapter\DoctrineORMAdapter; 7use Pagerfanta\Adapter\DoctrineORMAdapter;
7use Pagerfanta\Pagerfanta; 8use Pagerfanta\Pagerfanta;
8use Wallabag\CoreBundle\Entity\Tag; 9use Wallabag\CoreBundle\Entity\Tag;
@@ -85,6 +86,22 @@ class EntryRepository extends EntityRepository
85 } 86 }
86 87
87 /** 88 /**
89 * Retrieves untagged entries for a user.
90 *
91 * @param int $userId
92 *
93 * @return QueryBuilder
94 */
95 public function getBuilderForUntaggedByUser($userId)
96 {
97 return $this
98 ->getBuilderByUser($userId)
99 ->leftJoin('e.tags', 't')
100 ->groupBy('e.id')
101 ->having('count(t.id) = 0');
102 }
103
104 /**
88 * Find Entries. 105 * Find Entries.
89 * 106 *
90 * @param int $userId 107 * @param int $userId
@@ -92,12 +109,15 @@ class EntryRepository extends EntityRepository
92 * @param bool $isStarred 109 * @param bool $isStarred
93 * @param string $sort 110 * @param string $sort
94 * @param string $order 111 * @param string $order
112 * @param int $since
113 * @param string $tags
95 * 114 *
96 * @return array 115 * @return array
97 */ 116 */
98 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC') 117 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC', $since = 0, $tags = '')
99 { 118 {
100 $qb = $this->createQueryBuilder('e') 119 $qb = $this->createQueryBuilder('e')
120 ->leftJoin('e.tags', 't')
101 ->where('e.user =:userId')->setParameter('userId', $userId); 121 ->where('e.user =:userId')->setParameter('userId', $userId);
102 122
103 if (null !== $isArchived) { 123 if (null !== $isArchived) {
@@ -108,6 +128,16 @@ class EntryRepository extends EntityRepository
108 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); 128 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
109 } 129 }
110 130
131 if ($since > 0) {
132 $qb->andWhere('e.updatedAt > :since')->setParameter('since', new \DateTime(date('Y-m-d H:i:s', $since)));
133 }
134
135 if ('' !== $tags) {
136 foreach (explode(',', $tags) as $tag) {
137 $qb->andWhere('t.label = :label')->setParameter('label', $tag);
138 }
139 }
140
111 if ('created' === $sort) { 141 if ('created' === $sort) {
112 $qb->orderBy('e.id', $order); 142 $qb->orderBy('e.id', $order);
113 } elseif ('updated' === $sort) { 143 } elseif ('updated' === $sort) {
@@ -210,6 +240,19 @@ class EntryRepository extends EntityRepository
210 } 240 }
211 241
212 /** 242 /**
243 * Remove tags from all user entries.
244 *
245 * @param int $userId
246 * @param Array<Tag> $tags
247 */
248 public function removeTags($userId, $tags)
249 {
250 foreach ($tags as $tag) {
251 $this->removeTag($userId, $tag);
252 }
253 }
254
255 /**
213 * Find all entries that are attached to a give tag id. 256 * Find all entries that are attached to a give tag id.
214 * 257 *
215 * @param int $userId 258 * @param int $userId
@@ -238,7 +281,7 @@ class EntryRepository extends EntityRepository
238 public function findByUrlAndUserId($url, $userId) 281 public function findByUrlAndUserId($url, $userId)
239 { 282 {
240 $res = $this->createQueryBuilder('e') 283 $res = $this->createQueryBuilder('e')
241 ->where('e.url = :url')->setParameter('url', $url) 284 ->where('e.url = :url')->setParameter('url', urldecode($url))
242 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) 285 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
243 ->getQuery() 286 ->getQuery()
244 ->getResult(); 287 ->getResult();
@@ -266,4 +309,24 @@ class EntryRepository extends EntityRepository
266 309
267 return $qb->getQuery()->getSingleScalarResult(); 310 return $qb->getQuery()->getSingleScalarResult();
268 } 311 }
312
313 /**
314 * Count all entries for a tag and a user.
315 *
316 * @param int $userId
317 * @param int $tagId
318 *
319 * @return int
320 */
321 public function countAllEntriesByUserIdAndTagId($userId, $tagId)
322 {
323 $qb = $this->createQueryBuilder('e')
324 ->select('count(e.id)')
325 ->leftJoin('e.tags', 't')
326 ->where('e.user=:userId')->setParameter('userId', $userId)
327 ->andWhere('t.id=:tagId')->setParameter('tagId', $tagId)
328 ;
329
330 return $qb->getQuery()->getSingleScalarResult();
331 }
269} 332}