<?php
declare(strict_types=1);

namespace App\DQL;

use Doctrine\ORM\QueryBuilder;

class DateConditions{
    public static function addDateInPeriodCondition(QueryBuilder $qb, string $table, string $date): QueryBuilder{
        return $qb
                ->andWhere(sprintf('%s.startDate <= :date AND (%s.endDate >= :date  OR  %s.endDate IS NULL)',
                    $table,
                    $table,
                    $table
                ))
                ->setParameter('date', $date)
            ;
    }
}