mirror of
https://github.com/wallabag/wallabag.git
synced 2025-10-20 19:52:09 +00:00
Refactorize the way to retrieve entries
One place to retrieve entries in Entry & Rss controller. More simple and easy to maintain.
This commit is contained in:
parent
4fcb7eaf13
commit
0ab7404f93
3 changed files with 124 additions and 115 deletions
|
@ -8,6 +8,22 @@ use Pagerfanta\Pagerfanta;
|
|||
|
||||
class EntryRepository extends EntityRepository
|
||||
{
|
||||
/**
|
||||
* Return a query builder to used by other getBuilderFor* method.
|
||||
*
|
||||
* @param int $userId
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
private function getBuilderByUser($userId)
|
||||
{
|
||||
return $this->createQueryBuilder('e')
|
||||
->leftJoin('e.user', 'u')
|
||||
->andWhere('u.id = :userId')->setParameter('userId', $userId)
|
||||
->orderBy('e.id', 'desc')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves unread entries for a user.
|
||||
*
|
||||
|
@ -15,13 +31,12 @@ class EntryRepository extends EntityRepository
|
|||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function findUnreadByUser($userId)
|
||||
public function getBuilderForUnreadByUser($userId)
|
||||
{
|
||||
return $this->createQueryBuilder('e')
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('e.isArchived = false')
|
||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||
->orderBy('e.id', 'desc');
|
||||
return $this
|
||||
->getBuilderByUser($userId)
|
||||
->andWhere('e.isArchived = false')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,13 +46,12 @@ class EntryRepository extends EntityRepository
|
|||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function findArchiveByUser($userId)
|
||||
public function getBuilderForArchiveByUser($userId)
|
||||
{
|
||||
return $this->createQueryBuilder('e')
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('e.isArchived = true')
|
||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||
->orderBy('e.id', 'desc');
|
||||
return $this
|
||||
->getBuilderByUser($userId)
|
||||
->andWhere('e.isArchived = true')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,13 +61,12 @@ class EntryRepository extends EntityRepository
|
|||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function findStarredByUser($userId)
|
||||
public function getBuilderForStarredByUser($userId)
|
||||
{
|
||||
return $this->createQueryBuilder('e')
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('e.isStarred = true')
|
||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||
->orderBy('e.id', 'desc');
|
||||
return $this
|
||||
->getBuilderByUser($userId)
|
||||
->andWhere('e.isStarred = true')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue