mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Notification with paginitation
This commit is contained in:
@@ -24,6 +24,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\Query;
|
||||
|
||||
final class NotificationRepository implements ObjectRepository
|
||||
{
|
||||
@@ -60,21 +61,51 @@ final class NotificationRepository implements ObjectRepository
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Notification[]
|
||||
*/
|
||||
public function findAllForAttendee(User $addressee) // TODO passer à attendees avec S
|
||||
private function queryAllForAttendee(User $addressee, bool $countQuery=False): Query
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('n');
|
||||
|
||||
$select = 'n';
|
||||
if($countQuery) {
|
||||
$select = 'count(n)';
|
||||
}
|
||||
|
||||
$qb
|
||||
->select('n')
|
||||
->select($select)
|
||||
->join('n.addressees', 'a')
|
||||
->where('a = :addressee')
|
||||
->setParameter('addressee', $addressee);
|
||||
|
||||
$query = $qb->getQuery();
|
||||
return $qb->getQuery()->getResult();
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function countAllForAttendee(User $addressee): int // TODO passer à attendees avec S
|
||||
{
|
||||
$query = $this->queryAllForAttendee($addressee, $countQuery=True);
|
||||
|
||||
return $query->getSingleScalarResult();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Notification[]
|
||||
*/
|
||||
public function findAllForAttendee(User $addressee, $limit = null, $offset = null): array // TODO passer à attendees avec S
|
||||
{
|
||||
$query = $this->queryAllForAttendee($addressee);
|
||||
|
||||
if($limit) {
|
||||
$query = $query->setMaxResults($limit);
|
||||
}
|
||||
|
||||
if($offset) {
|
||||
$query = $query->setFirstResult($offset);
|
||||
}
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
|
||||
public function getClassName() {
|
||||
|
Reference in New Issue
Block a user