wallabag/src/Wallabag/CoreBundle/Repository/EntriesRepository.php

108 lines
3 KiB
PHP
Raw Normal View History

2015-01-22 16:18:56 +00:00
<?php
namespace Wallabag\CoreBundle\Repository;
2015-01-22 16:18:56 +00:00
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityRepository;
2015-01-23 11:45:24 +00:00
use Doctrine\ORM\Tools\Pagination\Paginator;
2015-01-31 14:14:10 +00:00
use Wallabag\CoreBundle\Entity\Entries;
2015-01-22 16:18:56 +00:00
class EntriesRepository extends EntityRepository
{
2015-01-23 13:58:17 +00:00
/**
* Retrieves unread entries for a user
*
* @param $userId
* @param $firstResult
2015-01-31 18:09:34 +00:00
* @param int $maxResults
2015-01-23 13:58:17 +00:00
* @return Paginator
*/
2015-01-23 11:45:24 +00:00
public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
2015-01-22 16:18:56 +00:00
{
$qb = $this->createQueryBuilder('e')
->select('e')
2015-01-23 11:45:24 +00:00
->setFirstResult($firstResult)
->setMaxResults($maxResults)
2015-01-22 16:18:56 +00:00
->where('e.isRead = 0')
->andWhere('e.userId =:userId')->setParameter('userId', $userId)
2015-02-04 16:54:23 +00:00
->andWhere('e.isDeleted=0')
2015-01-23 11:45:24 +00:00
->getQuery();
2015-01-22 16:18:56 +00:00
2015-01-23 13:58:17 +00:00
$paginator = new Paginator($qb);
2015-01-23 11:45:24 +00:00
2015-01-23 13:58:17 +00:00
return $paginator;
2015-01-22 16:18:56 +00:00
}
2015-01-22 20:11:22 +00:00
2015-01-23 13:58:17 +00:00
/**
* Retrieves read entries for a user
*
* @param $userId
* @param $firstResult
2015-01-31 18:09:34 +00:00
* @param int $maxResults
2015-01-23 13:58:17 +00:00
* @return Paginator
*/
2015-01-23 11:45:24 +00:00
public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
2015-01-22 20:11:22 +00:00
{
$qb = $this->createQueryBuilder('e')
->select('e')
2015-01-23 11:45:24 +00:00
->setFirstResult($firstResult)
->setMaxResults($maxResults)
2015-01-22 20:11:22 +00:00
->where('e.isRead = 1')
->andWhere('e.userId =:userId')->setParameter('userId', $userId)
2015-02-04 16:54:23 +00:00
->andWhere('e.isDeleted=0')
2015-01-23 13:58:17 +00:00
->getQuery();
$paginator = new Paginator($qb);
2015-01-22 20:11:22 +00:00
2015-01-23 13:58:17 +00:00
return $paginator;
2015-01-22 20:11:22 +00:00
}
2015-01-23 13:58:17 +00:00
/**
* Retrieves starred entries for a user
*
* @param $userId
* @param $firstResult
2015-01-31 18:09:34 +00:00
* @param int $maxResults
2015-01-23 13:58:17 +00:00
* @return Paginator
*/
2015-01-23 11:45:24 +00:00
public function findStarredByUser($userId, $firstResult, $maxResults = 12)
2015-01-22 20:11:22 +00:00
{
$qb = $this->createQueryBuilder('e')
->select('e')
2015-01-23 11:45:24 +00:00
->setFirstResult($firstResult)
->setMaxResults($maxResults)
2015-01-22 20:11:22 +00:00
->where('e.isFav = 1')
->andWhere('e.userId =:userId')->setParameter('userId', $userId)
2015-02-04 16:54:23 +00:00
->andWhere('e.isDeleted=0')
2015-01-23 13:58:17 +00:00
->getQuery();
$paginator = new Paginator($qb);
2015-01-22 20:11:22 +00:00
2015-01-23 13:58:17 +00:00
return $paginator;
2015-01-22 20:11:22 +00:00
}
2015-01-30 06:50:52 +00:00
public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order)
{
2015-01-31 14:14:10 +00:00
//TODO tous les paramètres ne sont pas utilisés, à corriger
2015-01-30 06:50:52 +00:00
$qb = $this->createQueryBuilder('e')
->select('e')
->where('e.userId =:userId')->setParameter('userId', $userId);
if (!is_null($isArchived)) {
$qb->andWhere('e.isRead =:isArchived')->setParameter('isArchived', $isArchived);
}
if (!is_null($isStarred)) {
$qb->andWhere('e.isFav =:isStarred')->setParameter('isStarred', $isStarred);
}
if (!is_null($isDeleted)) {
$qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted);
}
return $qb
2015-01-30 06:50:52 +00:00
->getQuery()
->getResult(Query::HYDRATE_ARRAY);
}
2015-01-22 16:18:56 +00:00
}