Merge remote-tracking branch 'origin/master' into issue706_cc_in_workflow-2

This commit is contained in:
2023-04-13 09:53:23 +02:00
154 changed files with 3079 additions and 2666 deletions

View File

@@ -11,20 +11,58 @@ declare(strict_types=1);
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\GeographicalUnit;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
class GeographicalUnitRepository implements GeographicalUnitRepositoryInterface
final class GeographicalUnitRepository implements GeographicalUnitRepositoryInterface
{
private EntityManagerInterface $em;
private EntityRepository $repository;
public function __construct(EntityManagerInterface $em)
{
$this->repository = $em->getRepository($this->getClassName());
$this->em = $em;
}
public function countGeographicalUnitContainingAddress(Address $address): int
{
$qb = $this->buildQueryGeographicalUnitContainingAddress($address);
return $qb
->select('COUNT(gu)')
->getQuery()
->getSingleScalarResult();
}
public function findGeographicalUnitContainingAddress(Address $address, int $offset = 0, int $limit = 50): array
{
$qb = $this->buildQueryGeographicalUnitContainingAddress($address);
return $qb
->select(sprintf('NEW %s(gu.id, gu.unitName, gu.unitRefId, IDENTITY(gu.layer))', GeographicalUnit\SimpleGeographicalUnitDTO::class))
->addOrderBy('IDENTITY(gu.layer)')
->addOrderBy(('gu.unitName'))
->getQuery()
->setFirstResult($offset)
->setMaxResults($limit)
->getResult();
}
private function buildQueryGeographicalUnitContainingAddress(Address $address): QueryBuilder
{
$qb = $this->repository
->createQueryBuilder('gu')
;
return $qb
->select(sprintf('NEW %s(gu.id, gu.unitName, gu.unitRefId, IDENTITY(gu.layer))', GeographicalUnit\SimpleGeographicalUnitDTO::class))
->innerJoin(Address::class, 'address', Join::WITH, 'ST_CONTAINS(gu.geom, address.point) = TRUE')
->where($qb->expr()->eq('address', ':address'))
->setParameter('address', $address)
;
}
public function find($id): ?GeographicalUnit

View File

@@ -11,8 +11,23 @@ declare(strict_types=1);
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO;
use Doctrine\Persistence\ObjectRepository;
interface GeographicalUnitRepositoryInterface extends ObjectRepository
{
/**
* Return the geographical units as @link{SimpleGeographicalUnitDTO} whithin the address is contained.
*
* This query is executed in real time (without the refresh of the materialized view which load the addresses).
*
* @param Address $address
* @param int $offset
* @param int $limit
* @return SimpleGeographicalUnitDTO[]
*/
public function findGeographicalUnitContainingAddress(Address $address, int $offset = 0, int $limit = 50): array;
public function countGeographicalUnitContainingAddress(Address $address): int;
}