47 lines
1.1 KiB
PHP

<?php
/**
* Chill is a software for social workers.
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://www.champs-libres.coop/
*/
declare(strict_types=1);
namespace Chill\AMLI\BudgetBundle\Repository;
use Chill\PersonBundle\Entity\Person;
use DateTime;
/**
* ChargeRepository.
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ChargeRepository extends \Doctrine\ORM\EntityRepository
{
public function findByPersonAndDate(Person $person, DateTime $date, $sort = null)
{
$qb = $this->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();
}
}