*/ class BookingSeriesRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, BookingSeries::class); } /** * @return list */ public function findActiveForUser(User $user, \DateTimeImmutable $on): array { return $this->findActive($on, $user); } /** * Every series still running on the given day, optionally narrowed to one person or one kind * of resource. The admin list is the caller that needs it across everybody. * * The user is eager-selected because the admin list names the holder of every row -- without * it the page fires a query per series. * * @return list */ public function findActive(\DateTimeImmutable $on, ?User $user = null, ?ResourceType $type = null): array { $qb = $this->createQueryBuilder('s') ->addSelect('u', 'r', 'g') ->join('s.user', 'u') ->join('s.resource', 'r') ->leftJoin('r.group', 'g') ->andWhere('s.endDate >= :on') ->setParameter('on', $on->setTime(0, 0)) ->orderBy('s.startDate', 'ASC') ->addOrderBy('u.name', 'ASC'); if (null !== $user) { $qb->andWhere('s.user = :user')->setParameter('user', $user); } if (null !== $type) { $qb->andWhere('r.type = :type')->setParameter('type', $type); } return $qb->getQuery()->getResult(); } }