aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php4
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php67
2 files changed, 55 insertions, 16 deletions
diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
index b44f7e64..0de5c934 100644
--- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
+++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
@@ -21,7 +21,7 @@ class AnnotationRepository extends EntityRepository
21 public function getBuilderForAllByUser($userId) 21 public function getBuilderForAllByUser($userId)
22 { 22 {
23 return $this 23 return $this
24 ->getBuilderByUser($userId) 24 ->getSortedQueryBuilderByUser($userId)
25 ; 25 ;
26 } 26 }
27 27
@@ -133,7 +133,7 @@ class AnnotationRepository extends EntityRepository
133 * 133 *
134 * @return QueryBuilder 134 * @return QueryBuilder
135 */ 135 */
136 private function getBuilderByUser($userId) 136 private function getSortedQueryBuilderByUser($userId)
137 { 137 {
138 return $this->createQueryBuilder('a') 138 return $this->createQueryBuilder('a')
139 ->leftJoin('a.user', 'u') 139 ->leftJoin('a.user', 'u')
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 38a3026d..34123eea 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -21,7 +21,7 @@ class EntryRepository extends EntityRepository
21 public function getBuilderForAllByUser($userId) 21 public function getBuilderForAllByUser($userId)
22 { 22 {
23 return $this 23 return $this
24 ->getBuilderByUser($userId) 24 ->getSortedQueryBuilderByUser($userId)
25 ; 25 ;
26 } 26 }
27 27
@@ -35,7 +35,7 @@ class EntryRepository extends EntityRepository
35 public function getBuilderForUnreadByUser($userId) 35 public function getBuilderForUnreadByUser($userId)
36 { 36 {
37 return $this 37 return $this
38 ->getBuilderByUser($userId) 38 ->getSortedQueryBuilderByUser($userId)
39 ->andWhere('e.isArchived = false') 39 ->andWhere('e.isArchived = false')
40 ; 40 ;
41 } 41 }
@@ -50,7 +50,7 @@ class EntryRepository extends EntityRepository
50 public function getBuilderForArchiveByUser($userId) 50 public function getBuilderForArchiveByUser($userId)
51 { 51 {
52 return $this 52 return $this
53 ->getBuilderByUser($userId) 53 ->getSortedQueryBuilderByUser($userId)
54 ->andWhere('e.isArchived = true') 54 ->andWhere('e.isArchived = true')
55 ; 55 ;
56 } 56 }
@@ -65,7 +65,7 @@ class EntryRepository extends EntityRepository
65 public function getBuilderForStarredByUser($userId) 65 public function getBuilderForStarredByUser($userId)
66 { 66 {
67 return $this 67 return $this
68 ->getBuilderByUser($userId, 'starredAt', 'desc') 68 ->getSortedQueryBuilderByUser($userId, 'starredAt', 'desc')
69 ->andWhere('e.isStarred = true') 69 ->andWhere('e.isStarred = true')
70 ; 70 ;
71 } 71 }
@@ -82,7 +82,7 @@ class EntryRepository extends EntityRepository
82 public function getBuilderForSearchByUser($userId, $term, $currentRoute) 82 public function getBuilderForSearchByUser($userId, $term, $currentRoute)
83 { 83 {
84 $qb = $this 84 $qb = $this
85 ->getBuilderByUser($userId); 85 ->getSortedQueryBuilderByUser($userId);
86 86
87 if ('starred' === $currentRoute) { 87 if ('starred' === $currentRoute) {
88 $qb->andWhere('e.isStarred = true'); 88 $qb->andWhere('e.isStarred = true');
@@ -102,7 +102,7 @@ class EntryRepository extends EntityRepository
102 } 102 }
103 103
104 /** 104 /**
105 * Retrieves untagged entries for a user. 105 * Retrieve a sorted list of untagged entries for a user.
106 * 106 *
107 * @param int $userId 107 * @param int $userId
108 * 108 *
@@ -111,8 +111,21 @@ class EntryRepository extends EntityRepository
111 public function getBuilderForUntaggedByUser($userId) 111 public function getBuilderForUntaggedByUser($userId)
112 { 112 {
113 return $this 113 return $this
114 ->getBuilderByUser($userId) 114 ->sortQueryBuilder($this->getRawBuilderForUntaggedByUser($userId));
115 ->andWhere('size(e.tags) = 0'); 115 }
116
117 /**
118 * Retrieve untagged entries for a user.
119 *
120 * @param int $userId
121 *
122 * @return QueryBuilder
123 */
124 public function getRawBuilderForUntaggedByUser($userId)
125 {
126 return $this->getQueryBuilderByUser($userId)
127 ->leftJoin('e.tags', 't')
128 ->andWhere('t.id is null');
116 } 129 }
117 130
118 /** 131 /**
@@ -260,7 +273,7 @@ class EntryRepository extends EntityRepository
260 */ 273 */
261 public function removeTag($userId, Tag $tag) 274 public function removeTag($userId, Tag $tag)
262 { 275 {
263 $entries = $this->getBuilderByUser($userId) 276 $entries = $this->getSortedQueryBuilderByUser($userId)
264 ->innerJoin('e.tags', 't') 277 ->innerJoin('e.tags', 't')
265 ->andWhere('t.id = :tagId')->setParameter('tagId', $tag->getId()) 278 ->andWhere('t.id = :tagId')->setParameter('tagId', $tag->getId())
266 ->getQuery() 279 ->getQuery()
@@ -296,7 +309,7 @@ class EntryRepository extends EntityRepository
296 */ 309 */
297 public function findAllByTagId($userId, $tagId) 310 public function findAllByTagId($userId, $tagId)
298 { 311 {
299 return $this->getBuilderByUser($userId) 312 return $this->getSortedQueryBuilderByUser($userId)
300 ->innerJoin('e.tags', 't') 313 ->innerJoin('e.tags', 't')
301 ->andWhere('t.id = :tagId')->setParameter('tagId', $tagId) 314 ->andWhere('t.id = :tagId')->setParameter('tagId', $tagId)
302 ->getQuery() 315 ->getQuery()
@@ -414,7 +427,20 @@ class EntryRepository extends EntityRepository
414 } 427 }
415 428
416 /** 429 /**
417 * Return a query builder to used by other getBuilderFor* method. 430 * Return a query builder to be used by other getBuilderFor* method.
431 *
432 * @param int $userId
433 *
434 * @return QueryBuilder
435 */
436 private function getQueryBuilderByUser($userId)
437 {
438 return $this->createQueryBuilder('e')
439 ->andWhere('e.user = :userId')->setParameter('userId', $userId);
440 }
441
442 /**
443 * Return a sorted query builder to be used by other getBuilderFor* method.
418 * 444 *
419 * @param int $userId 445 * @param int $userId
420 * @param string $sortBy 446 * @param string $sortBy
@@ -422,10 +448,23 @@ class EntryRepository extends EntityRepository
422 * 448 *
423 * @return QueryBuilder 449 * @return QueryBuilder
424 */ 450 */
425 private function getBuilderByUser($userId, $sortBy = 'createdAt', $direction = 'desc') 451 private function getSortedQueryBuilderByUser($userId, $sortBy = 'createdAt', $direction = 'desc')
426 { 452 {
427 return $this->createQueryBuilder('e') 453 return $this->sortQueryBuilder($this->getQueryBuilderByUser($userId));
428 ->andWhere('e.user = :userId')->setParameter('userId', $userId) 454 }
455
456 /**
457 * Return the given QueryBuilder with an orderBy() call.
458 *
459 * @param QueryBuilder $qb
460 * @param string $sortBy
461 * @param string $direction
462 *
463 * @return QueryBuilder
464 */
465 private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc')
466 {
467 return $qb
429 ->orderBy(sprintf('e.%s', $sortBy), $direction); 468 ->orderBy(sprintf('e.%s', $sortBy), $direction);
430 } 469 }
431} 470}