diff options
author | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
---|---|---|
committer | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
commit | 99731f0bb1f6fd2815eeb9af504ce86df927657b (patch) | |
tree | b080efc608d2bbd52b77a4a0067402007f50c5a8 /src/Wallabag/CoreBundle/Repository | |
parent | 3a3c6b866b52721431bed22426d9abfcd0d2dfe0 (diff) | |
parent | 7180aaed45dce62e40620a9e4b202526ebd6a3bb (diff) | |
download | wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.gz wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.zst wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.zip |
Merge remote-tracking branch 'wallabag/master'
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 67 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/TagRepository.php | 34 |
2 files changed, 97 insertions, 4 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 @@ | |||
3 | namespace Wallabag\CoreBundle\Repository; | 3 | namespace Wallabag\CoreBundle\Repository; |
4 | 4 | ||
5 | use Doctrine\ORM\EntityRepository; | 5 | use Doctrine\ORM\EntityRepository; |
6 | use Doctrine\ORM\Query; | ||
6 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 7 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
7 | use Pagerfanta\Pagerfanta; | 8 | use Pagerfanta\Pagerfanta; |
8 | use Wallabag\CoreBundle\Entity\Tag; | 9 | use 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 | } |
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index abf915fe..e76878d4 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php | |||
@@ -7,7 +7,33 @@ use Doctrine\ORM\EntityRepository; | |||
7 | class TagRepository extends EntityRepository | 7 | class TagRepository extends EntityRepository |
8 | { | 8 | { |
9 | /** | 9 | /** |
10 | * Find Tags. | 10 | * Count all tags per user. |
11 | * | ||
12 | * @param int $userId | ||
13 | * @param int $cacheLifeTime Duration of the cache for this query | ||
14 | * | ||
15 | * @return int | ||
16 | */ | ||
17 | public function countAllTags($userId, $cacheLifeTime = null) | ||
18 | { | ||
19 | $query = $this->createQueryBuilder('t') | ||
20 | ->select('t.slug') | ||
21 | ->leftJoin('t.entries', 'e') | ||
22 | ->where('e.user = :userId')->setParameter('userId', $userId) | ||
23 | ->groupBy('t.slug') | ||
24 | ->getQuery(); | ||
25 | |||
26 | if (null !== $cacheLifeTime) { | ||
27 | $query->useQueryCache(true); | ||
28 | $query->useResultCache(true); | ||
29 | $query->setResultCacheLifetime($cacheLifeTime); | ||
30 | } | ||
31 | |||
32 | return count($query->getArrayResult()); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Find all tags per user. | ||
11 | * | 37 | * |
12 | * @param int $userId | 38 | * @param int $userId |
13 | * | 39 | * |
@@ -16,10 +42,14 @@ class TagRepository extends EntityRepository | |||
16 | public function findAllTags($userId) | 42 | public function findAllTags($userId) |
17 | { | 43 | { |
18 | return $this->createQueryBuilder('t') | 44 | return $this->createQueryBuilder('t') |
45 | ->select('t.slug', 't.label', 't.id') | ||
19 | ->leftJoin('t.entries', 'e') | 46 | ->leftJoin('t.entries', 'e') |
20 | ->where('e.user = :userId')->setParameter('userId', $userId) | 47 | ->where('e.user = :userId')->setParameter('userId', $userId) |
48 | ->groupBy('t.slug') | ||
49 | ->addGroupBy('t.label') | ||
50 | ->addGroupBy('t.id') | ||
21 | ->getQuery() | 51 | ->getQuery() |
22 | ->getResult(); | 52 | ->getArrayResult(); |
23 | } | 53 | } |
24 | 54 | ||
25 | /** | 55 | /** |