aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php45
-rw-r--r--src/Wallabag/CoreBundle/Repository/TagRepository.php4
2 files changed, 45 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 4d45e5f5..302e5a53 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
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php
index abf915fe..41f61607 100644
--- a/src/Wallabag/CoreBundle/Repository/TagRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php
@@ -17,9 +17,7 @@ class TagRepository extends EntityRepository
17 { 17 {
18 return $this->createQueryBuilder('t') 18 return $this->createQueryBuilder('t')
19 ->leftJoin('t.entries', 'e') 19 ->leftJoin('t.entries', 'e')
20 ->where('e.user = :userId')->setParameter('userId', $userId) 20 ->where('e.user = :userId')->setParameter('userId', $userId);
21 ->getQuery()
22 ->getResult();
23 } 21 }
24 22
25 /** 23 /**