]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Repository/EntryRepository.php
Adds pagerfanta paginator everywhere, modifies article routing. Change API for is_sta...
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
CommitLineData
9d50517c
NL
1<?php
2
ad4d1caa 3namespace Wallabag\CoreBundle\Repository;
9d50517c 4
9d50517c 5use Doctrine\ORM\EntityRepository;
bcf53ab7
WD
6use Pagerfanta\Adapter\DoctrineORMAdapter;
7use Pagerfanta\Pagerfanta;
9d50517c 8
be463487 9class EntryRepository extends EntityRepository
9d50517c 10{
b84a8055 11 /**
4346a860 12 * Retrieves unread entries for a user.
b84a8055 13 *
3b815d2d 14 * @param int $userId
3b815d2d 15 *
9fb6ac83 16 * @return Pagerfanta
b84a8055 17 */
9fb6ac83 18 public function findUnreadByUser($userId)
9d50517c
NL
19 {
20 $qb = $this->createQueryBuilder('e')
3b815d2d 21 ->leftJoin('e.user', 'u')
905ae369 22 ->where('e.isArchived = false')
3b815d2d 23 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
2385f891 24 ->orderBy('e.id', 'desc')
163eae0b 25 ->getQuery();
9d50517c 26
9fb6ac83 27 $pagerAdapter = new DoctrineORMAdapter($qb);
163eae0b 28
9fb6ac83 29 return new Pagerfanta($pagerAdapter);
9d50517c 30 }
bd9f0815 31
b84a8055 32 /**
4346a860 33 * Retrieves read entries for a user.
b84a8055 34 *
3b815d2d 35 * @param int $userId
3b815d2d 36 *
9fb6ac83 37 * @return Pagerfanta
b84a8055 38 */
9fb6ac83 39 public function findArchiveByUser($userId)
bd9f0815
NL
40 {
41 $qb = $this->createQueryBuilder('e')
42 ->select('e')
3b815d2d 43 ->leftJoin('e.user', 'u')
905ae369 44 ->where('e.isArchived = true')
3b815d2d 45 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
2385f891 46 ->orderBy('e.id', 'desc')
b84a8055
NL
47 ->getQuery();
48
9fb6ac83 49 $pagerAdapter = new DoctrineORMAdapter($qb);
bd9f0815 50
9fb6ac83 51 return new Pagerfanta($pagerAdapter);
bd9f0815
NL
52 }
53
b84a8055 54 /**
4346a860 55 * Retrieves starred entries for a user.
b84a8055 56 *
3b815d2d 57 * @param int $userId
3b815d2d 58 *
9fb6ac83 59 * @return Pagerfanta
b84a8055 60 */
9fb6ac83 61 public function findStarredByUser($userId)
bd9f0815 62 {
9fb6ac83 63
bd9f0815
NL
64 $qb = $this->createQueryBuilder('e')
65 ->select('e')
3b815d2d 66 ->leftJoin('e.user', 'u')
905ae369 67 ->where('e.isStarred = true')
3b815d2d 68 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
2385f891 69 ->orderBy('e.id', 'desc')
b84a8055
NL
70 ->getQuery();
71
9fb6ac83 72 $pagerAdapter = new DoctrineORMAdapter($qb);
bd9f0815 73
9fb6ac83 74 return new Pagerfanta($pagerAdapter);
bd9f0815 75 }
a8c90c5c 76
3b815d2d 77 /**
4346a860 78 * Find Entries.
3b815d2d 79 *
2a94b1d1
NL
80 * @param int $userId
81 * @param bool $isArchived
82 * @param bool $isStarred
2a94b1d1
NL
83 * @param string $sort
84 * @param string $order
3b815d2d 85 *
017e2089 86 * @return array
3b815d2d 87 */
1d147791 88 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
a8c90c5c
NL
89 {
90 $qb = $this->createQueryBuilder('e')
0f006880 91 ->where('e.user =:userId')->setParameter('userId', $userId);
6e334aba 92
3b815d2d
J
93 if (null !== $isArchived) {
94 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
6e334aba
NL
95 }
96
3b815d2d
J
97 if (null !== $isStarred) {
98 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
6e334aba
NL
99 }
100
bc782eaa 101 if ('created' === $sort) {
2385f891 102 $qb->orderBy('e.id', $order);
bc782eaa
NL
103 } elseif ('updated' === $sort) {
104 $qb->orderBy('e.updatedAt', $order);
105 }
106
bcf53ab7
WD
107 $pagerAdapter = new DoctrineORMAdapter($qb);
108
109 return new Pagerfanta($pagerAdapter);
a8c90c5c 110 }
46bbd8d3 111
a36737f4
NL
112 /**
113 * Fetch an entry with a tag. Only used for tests.
114 *
115 * @return Entry
116 */
092ca707 117 public function findOneWithTags($userId)
46bbd8d3
NL
118 {
119 $qb = $this->createQueryBuilder('e')
120 ->innerJoin('e.tags', 't')
0ca374e6
NL
121 ->innerJoin('e.user', 'u')
122 ->addSelect('t', 'u')
123 ->where('e.user=:userId')->setParameter('userId', $userId)
124 ;
092ca707 125
0ca374e6 126 return $qb->getQuery()->getResult();
46bbd8d3 127 }
9d50517c 128}