84 lines
2.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.
*/
declare(strict_types=1);
namespace Chill\BudgetBundle\Repository;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Person;
use DateTime;
use Doctrine\ORM\EntityRepository;
/**
* ChargeRepository.
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ChargeRepository extends 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();
// }
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();
// }
}