createQueryBuilder('c'); // $qb->where('c.person = :person') // ->andWhere('c.startDate < :date') // ->andWhere('c.startDate < :date OR c.startDate IS NULL'); // if (null !== $sort) { // $qb->orderBy($sort); // } // $qb->setParameters([ // 'person' => $person, // 'date' => $date, // ]); // return $qb->getQuery()->getResult(); // } public function findByEntityAndDate($entity, DateTime $date, $sort = null) { $qb = $this->createQueryBuilder('c'); $entityStr = $entity instanceof Person ? 'person' : 'household'; $qb->where("c.$entityStr = :$entityStr") ->andWhere('c.startDate < :date') ->andWhere('c.startDate < :date OR c.startDate IS NULL'); if (null !== $sort) { $qb->orderBy($sort); } $qb->setParameters([ $entityStr => $entity, 'date' => $date, ]); return $qb->getQuery()->getResult(); } // public function findByHouseholdAndDate(Household $household, DateTime $date) // { // $qb = $this->createQueryBuilder('c'); // $qb->where('c.household = :household') // ->andWhere('c.startDate < :date OR c.startDate IS NULL'); // $qb->setParameters([ // 'person' => $household, // 'date' => $date, // ]); // return $qb->getQuery()->getResult(); // } }