This commit is contained in:
2022-10-18 14:37:33 +02:00
parent 8928664f87
commit 9eb451e359
15 changed files with 79 additions and 76 deletions

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Repository\SocialWork;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@@ -44,6 +45,14 @@ final class SocialActionRepository implements ObjectRepository
return $this->repository->findAll();
}
/**
* @return array|SocialAction[]
*/
public function findAllActive(): array
{
return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult();
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
@@ -68,22 +77,14 @@ final class SocialActionRepository implements ObjectRepository
return SocialAction::class;
}
/**
* @return array|SocialAction[]
*/
public function findAllActive(): array
{
return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult();
}
private function buildQueryWithDesactivatedDateCriteria(): QueryBuilder
{
$qb = $this->repository->createQueryBuilder('sa');
$qb ->where('sa.desactivationDate is null')
$qb->where('sa.desactivationDate is null')
->orWhere('sa.desactivationDate > :now')
->orderBy('sa.ordering', 'ASC')
->setParameter('now', new \DateTime('now'));
->setParameter('now', new DateTime('now'));
return $qb;
}

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Repository\SocialWork;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@@ -39,6 +40,14 @@ final class SocialIssueRepository implements ObjectRepository
return $this->repository->findAll();
}
/**
* @return array|SocialIssue[]
*/
public function findAllActive(): array
{
return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult();
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
@@ -63,22 +72,14 @@ final class SocialIssueRepository implements ObjectRepository
return SocialIssue::class;
}
/**
* @return array|SocialIssue[]
*/
public function findAllActive(): array
{
return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult();
}
private function buildQueryWithDesactivatedDateCriteria(): QueryBuilder
{
$qb = $this->repository->createQueryBuilder('si');
$qb ->where('si.desactivationDate is null')
$qb->where('si.desactivationDate is null')
->orWhere('si.desactivationDate > :now')
->orderBy('si.ordering', 'ASC')
->setParameter('now', new \DateTime('now'));
->setParameter('now', new DateTime('now'));
return $qb;
}