DateConditions.php 518 B

12345678910111213141516171819
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\DQL;
  4. use Doctrine\ORM\QueryBuilder;
  5. class DateConditions{
  6. public static function addDateInPeriodCondition(QueryBuilder $qb, string $table, string $date): QueryBuilder{
  7. return $qb
  8. ->andWhere(sprintf('%s.startDate <= :date AND (%s.endDate >= :date OR %s.endDate IS NULL)',
  9. $table,
  10. $table,
  11. $table
  12. ))
  13. ->setParameter('date', $date)
  14. ;
  15. }
  16. }