3 namespace Wallabag\CoreBundle\Repository
;
5 use Doctrine\ORM\Query
;
6 use Doctrine\ORM\EntityRepository
;
7 use Doctrine\ORM\Tools\Pagination\Paginator
;
9 class EntryRepository
extends EntityRepository
12 * Retrieves unread entries for a user
15 * @param int $firstResult
16 * @param int $maxResults
20 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
22 $qb = $this->createQueryBuilder('e')
23 ->setFirstResult($firstResult)
24 ->setMaxResults($maxResults)
25 ->leftJoin('e.user', 'u')
26 ->where('e.isArchived = false')
27 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
28 ->andWhere('e.isDeleted=false')
29 ->orderBy('e.createdAt', 'desc')
32 $paginator = new Paginator($qb);
38 * Retrieves read entries for a user
41 * @param int $firstResult
42 * @param int $maxResults
46 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
48 $qb = $this->createQueryBuilder('e')
50 ->setFirstResult($firstResult)
51 ->setMaxResults($maxResults)
52 ->leftJoin('e.user', 'u')
53 ->where('e.isArchived = true')
54 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
55 ->andWhere('e.isDeleted=false')
56 ->orderBy('e.createdAt', 'desc')
59 $paginator = new Paginator($qb);
65 * Retrieves starred entries for a user
68 * @param int $firstResult
69 * @param int $maxResults
73 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
75 $qb = $this->createQueryBuilder('e')
77 ->setFirstResult($firstResult)
78 ->setMaxResults($maxResults)
79 ->leftJoin('e.user', 'u')
80 ->where('e.isStarred = true')
81 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
82 ->andWhere('e.isDeleted = false')
83 ->orderBy('e.createdAt', 'desc')
86 $paginator = new Paginator($qb);
95 * @param bool $isArchived
96 * @param bool $isStarred
97 * @param bool $isDeleted
99 * @param string $order
101 * @return ArrayCollection
103 public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC')
105 $qb = $this->createQueryBuilder('e')
106 ->leftJoin('e.user', 'u')
107 ->where('u.id =:userId')->setParameter('userId', $userId);
109 if (null !== $isArchived) {
110 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
113 if (null !== $isStarred) {
114 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
117 if (null !== $isDeleted) {
118 $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted);
121 if ('created' === $sort) {
122 $qb->orderBy('e.createdAt', $order);
123 } elseif ('updated' === $sort) {
124 $qb->orderBy('e.updatedAt', $order);