3 namespace Wallabag\CoreBundle\Repository
;
5 use Doctrine\ORM\EntityRepository
;
6 use Doctrine\ORM\Tools\Pagination\Paginator
;
8 class EntryRepository
extends EntityRepository
11 * Retrieves unread entries for a user
14 * @param int $firstResult
15 * @param int $maxResults
19 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
21 $qb = $this->createQueryBuilder('e')
22 ->setFirstResult($firstResult)
23 ->setMaxResults($maxResults)
24 ->leftJoin('e.user', 'u')
25 ->where('e.isArchived = false')
26 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
27 ->andWhere('e.isDeleted=false')
28 ->orderBy('e.createdAt', 'desc')
31 $paginator = new Paginator($qb);
37 * Retrieves read entries for a user
40 * @param int $firstResult
41 * @param int $maxResults
45 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
47 $qb = $this->createQueryBuilder('e')
49 ->setFirstResult($firstResult)
50 ->setMaxResults($maxResults)
51 ->leftJoin('e.user', 'u')
52 ->where('e.isArchived = true')
53 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
54 ->andWhere('e.isDeleted=false')
55 ->orderBy('e.createdAt', 'desc')
58 $paginator = new Paginator($qb);
64 * Retrieves starred entries for a user
67 * @param int $firstResult
68 * @param int $maxResults
72 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
74 $qb = $this->createQueryBuilder('e')
76 ->setFirstResult($firstResult)
77 ->setMaxResults($maxResults)
78 ->leftJoin('e.user', 'u')
79 ->where('e.isStarred = true')
80 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
81 ->andWhere('e.isDeleted = false')
82 ->orderBy('e.createdAt', 'desc')
85 $paginator = new Paginator($qb);
94 * @param bool $isArchived
95 * @param bool $isStarred
96 * @param bool $isDeleted
98 * @param string $order
102 public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC')
104 $qb = $this->createQueryBuilder('e')
105 ->leftJoin('e.user', 'u')
106 ->where('u.id =:userId')->setParameter('userId', $userId);
108 if (null !== $isArchived) {
109 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
112 if (null !== $isStarred) {
113 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
116 if (null !== $isDeleted) {
117 $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted);
120 if ('created' === $sort) {
121 $qb->orderBy('e.createdAt', $order);
122 } elseif ('updated' === $sort) {
123 $qb->orderBy('e.updatedAt', $order);