diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 48 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/TagRepository.php | 22 |
2 files changed, 45 insertions, 25 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index c27ee90c..eb5e3205 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -3,9 +3,10 @@ | |||
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 Doctrine\ORM\QueryBuilder; |
7 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 7 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
8 | use Pagerfanta\Pagerfanta; | 8 | use Pagerfanta\Pagerfanta; |
9 | use Wallabag\CoreBundle\Entity\Entry; | ||
9 | use Wallabag\CoreBundle\Entity\Tag; | 10 | use Wallabag\CoreBundle\Entity\Tag; |
10 | 11 | ||
11 | class EntryRepository extends EntityRepository | 12 | class EntryRepository extends EntityRepository |
@@ -74,7 +75,7 @@ class EntryRepository extends EntityRepository | |||
74 | * | 75 | * |
75 | * @param int $userId | 76 | * @param int $userId |
76 | * @param string $term | 77 | * @param string $term |
77 | * @param strint $currentRoute | 78 | * @param string $currentRoute |
78 | * | 79 | * |
79 | * @return QueryBuilder | 80 | * @return QueryBuilder |
80 | */ | 81 | */ |
@@ -126,7 +127,7 @@ class EntryRepository extends EntityRepository | |||
126 | * @param int $since | 127 | * @param int $since |
127 | * @param string $tags | 128 | * @param string $tags |
128 | * | 129 | * |
129 | * @return array | 130 | * @return Pagerfanta |
130 | */ | 131 | */ |
131 | public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'ASC', $since = 0, $tags = '') | 132 | public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'ASC', $since = 0, $tags = '') |
132 | { | 133 | { |
@@ -172,7 +173,7 @@ class EntryRepository extends EntityRepository | |||
172 | * | 173 | * |
173 | * @param int $userId | 174 | * @param int $userId |
174 | * | 175 | * |
175 | * @return Entry | 176 | * @return array |
176 | */ | 177 | */ |
177 | public function findOneWithTags($userId) | 178 | public function findOneWithTags($userId) |
178 | { | 179 | { |
@@ -329,26 +330,6 @@ class EntryRepository extends EntityRepository | |||
329 | } | 330 | } |
330 | 331 | ||
331 | /** | 332 | /** |
332 | * Count all entries for a tag and a user. | ||
333 | * | ||
334 | * @param int $userId | ||
335 | * @param int $tagId | ||
336 | * | ||
337 | * @return int | ||
338 | */ | ||
339 | public function countAllEntriesByUserIdAndTagId($userId, $tagId) | ||
340 | { | ||
341 | $qb = $this->createQueryBuilder('e') | ||
342 | ->select('count(e.id)') | ||
343 | ->leftJoin('e.tags', 't') | ||
344 | ->where('e.user=:userId')->setParameter('userId', $userId) | ||
345 | ->andWhere('t.id=:tagId')->setParameter('tagId', $tagId) | ||
346 | ; | ||
347 | |||
348 | return (int) $qb->getQuery()->getSingleScalarResult(); | ||
349 | } | ||
350 | |||
351 | /** | ||
352 | * Remove all entries for a user id. | 333 | * Remove all entries for a user id. |
353 | * Used when a user want to reset all informations. | 334 | * Used when a user want to reset all informations. |
354 | * | 335 | * |
@@ -374,7 +355,7 @@ class EntryRepository extends EntityRepository | |||
374 | * Get id and url from all entries | 355 | * Get id and url from all entries |
375 | * Used for the clean-duplicates command. | 356 | * Used for the clean-duplicates command. |
376 | */ | 357 | */ |
377 | public function getAllEntriesIdAndUrl($userId) | 358 | public function findAllEntriesIdAndUrlByUserId($userId) |
378 | { | 359 | { |
379 | $qb = $this->createQueryBuilder('e') | 360 | $qb = $this->createQueryBuilder('e') |
380 | ->select('e.id, e.url') | 361 | ->select('e.id, e.url') |
@@ -384,6 +365,23 @@ class EntryRepository extends EntityRepository | |||
384 | } | 365 | } |
385 | 366 | ||
386 | /** | 367 | /** |
368 | * @param int $userId | ||
369 | * | ||
370 | * @return array | ||
371 | */ | ||
372 | public function findAllEntriesIdByUserId($userId = null) | ||
373 | { | ||
374 | $qb = $this->createQueryBuilder('e') | ||
375 | ->select('e.id'); | ||
376 | |||
377 | if (null !== $userId) { | ||
378 | $qb->where('e.user = :userid')->setParameter(':userid', $userId); | ||
379 | } | ||
380 | |||
381 | return $qb->getQuery()->getArrayResult(); | ||
382 | } | ||
383 | |||
384 | /** | ||
387 | * Find all entries by url and owner. | 385 | * Find all entries by url and owner. |
388 | * | 386 | * |
389 | * @param $url | 387 | * @param $url |
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 6c63a6a2..5c45211f 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.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 Wallabag\CoreBundle\Entity\Tag; | ||
6 | 7 | ||
7 | class TagRepository extends EntityRepository | 8 | class TagRepository extends EntityRepository |
8 | { | 9 | { |
@@ -62,6 +63,27 @@ class TagRepository extends EntityRepository | |||
62 | } | 63 | } |
63 | 64 | ||
64 | /** | 65 | /** |
66 | * Find all tags (flat) per user with nb entries. | ||
67 | * | ||
68 | * @param int $userId | ||
69 | * | ||
70 | * @return array | ||
71 | */ | ||
72 | public function findAllFlatTagsWithNbEntries($userId) | ||
73 | { | ||
74 | return $this->createQueryBuilder('t') | ||
75 | ->select('t.id, t.label, t.slug, count(e.id) as nbEntries') | ||
76 | ->distinct(true) | ||
77 | ->leftJoin('t.entries', 'e') | ||
78 | ->where('e.user = :userId') | ||
79 | ->groupBy('t.id') | ||
80 | ->orderBy('t.slug') | ||
81 | ->setParameter('userId', $userId) | ||
82 | ->getQuery() | ||
83 | ->getArrayResult(); | ||
84 | } | ||
85 | |||
86 | /** | ||
65 | * Used only in test case to get a tag for our entry. | 87 | * Used only in test case to get a tag for our entry. |
66 | * | 88 | * |
67 | * @return Tag | 89 | * @return Tag |