Repositories adapted for use with person or household

This commit is contained in:
2022-02-24 15:49:04 +01:00
parent 0fcf21bd35
commit 0d96c1f12d
2 changed files with 58 additions and 8 deletions

View File

@@ -11,8 +11,10 @@ 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;
/**
* ResourceRepository.
@@ -20,13 +22,21 @@ use DateTime;
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ResourceRepository extends \Doctrine\ORM\EntityRepository
class ResourceRepository extends EntityRepository
{
public function findByPersonAndDate(Person $person, DateTime $date, $sort = null)
// public function findByEntity($entity)
// {
// }
public function findByEntityAndDate($entity, DateTime $date, $sort = null)
{
$qb = $this->createQueryBuilder('c');
$qb->where('c.person = :person')
$entityStr = $entity instanceof Person ? 'person' : 'household';
$qb->where("c.$entityStr = :$entityStr")
->andWhere('c.startDate < :date')
->andWhere('c.startDate < :date OR c.startDate IS NULL');
@@ -35,10 +45,11 @@ class ResourceRepository extends \Doctrine\ORM\EntityRepository
}
$qb->setParameters([
'person' => $person,
$entityStr => $entity,
'date' => $date,
]);
return $qb->getQuery()->getResult();
}
}