Skip to content

Commit cae5b06

Browse files
committed
Vérifie si le linéaire est présent dans le pérmiètre de l'organisation
1 parent 75fb6bc commit cae5b06

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

docs/adr/011_administrative_boundaries.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,14 @@ Cette approche permet de :
114114
- Conserver une précision élevée pour les communes
115115
- Réduire significativement le poids des géométries pour les grandes entités (comme les régions)
116116
- Maintenir un bon équilibre entre précision visuelle et performance
117+
118+
## Règles de validation d'une localisation d'un arrêté
119+
120+
Pour la validation d'une localisation d'un arrêté dans un périmètre géographique d'une organisation, nous avons défini les règles métiers suivantes :
121+
122+
- Inclusion totale : Le linéaire est entièrement contenu dans le périmètre de l'organisation.
123+
- Inclusion partielle sortante : Le linéaire commence dans le périmètre de l'organisation puis se termine à l'extérieur.
124+
- Inclusion partielle entrante : Le linéaire commence à l'extérieur du périmètre de l'organisation puis se termine à l'intérieur.
125+
- Traversée multiple : Le linéaire traverse plusieurs fois les limites du périmètre de l'organisation (entrée-sortie-entrée...).
126+
127+
Cette solution résout le problème de linéaires partagés entre plusieurs organisations tout en prenant en compte des scénarios plus complexes comme les traversées multiples. Elle permet d'associer de manière fiable les arrêtés aux organisations concernées en fonction de leur localisation géographique.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Domain\Organization\Exception;
6+
7+
final class OrganizationDoesntHaveGeometryException extends \Exception
8+
{
9+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Domain\Regulation\Specification;
6+
7+
use App\Domain\Organization\Exception\OrganizationDoesntHaveGeometryException;
8+
use App\Domain\User\Exception\OrganizationNotFoundException;
9+
use App\Domain\User\Repository\OrganizationRepositoryInterface;
10+
11+
class CanOrganizationInterveneOnGeometry
12+
{
13+
public function __construct(
14+
private OrganizationRepositoryInterface $organizationRepository,
15+
) {
16+
}
17+
18+
public function isSatisfiedBy(string $uuid, string $geometry): bool
19+
{
20+
$organization = $this->organizationRepository->findOneByUuid($uuid);
21+
if (!$organization) {
22+
return throw new OrganizationNotFoundException();
23+
}
24+
25+
if (!$organization->getGeometry()) {
26+
throw new OrganizationDoesntHaveGeometryException();
27+
}
28+
29+
return $this->organizationRepository->canInterveneOnGeometry($uuid, $geometry);
30+
}
31+
}

src/Domain/User/Repository/OrganizationRepositoryInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ public function countOrganizations(): int;
2323
public function add(Organization $organization): void;
2424

2525
public function flush(): void;
26+
27+
public function canInterveneOnGeometry(string $uuid, string $geometry): bool;
2628
}

src/Infrastructure/Persistence/Doctrine/Repository/Organization/OrganizationRepository.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,22 @@ public function countOrganizations(): int
8484
->getSingleScalarResult()
8585
;
8686
}
87+
88+
public function canInterveneOnGeometry(string $uuid, string $geometry): bool
89+
{
90+
$result = $this->createQueryBuilder('o')
91+
->select('ST_Intersects(
92+
ST_GeomFromGeoJSON(:geometry),
93+
o.geometry
94+
) as has_intersection')
95+
->where('o.uuid = :uuid')
96+
->setParameters([
97+
'uuid' => $uuid,
98+
'geometry' => $geometry,
99+
])
100+
->getQuery()
101+
->getOneOrNullResult();
102+
103+
return (bool) ($result['has_intersection'] ?? false);
104+
}
87105
}

0 commit comments

Comments
 (0)