up recherche home avec nominatim

This commit is contained in:
Tykayn 2025-07-18 14:21:55 +02:00 committed by tykayn
parent 7f79ec3a9f
commit c89751b45c
7 changed files with 601 additions and 220 deletions

View file

@ -1967,7 +1967,7 @@ final class AdminController extends AbstractController
// Set OSM object type and OSM ID from the Place
$demande->setOsmObjectType($place->getOsmKind());
$demande->setOsmId((int)$place->getOsmId());
$demande->setOsmId($place->getOsmId());
$this->entityManager->persist($demande);
$this->entityManager->flush();

View file

@ -148,10 +148,11 @@ class PublicController extends AbstractController
// Save the OSM ID if provided
if (isset($data['osmId']) && !empty($data['osmId'])) {
$demande->setOsmId((int)$data['osmId']);
$demande->setOsmId($data['osmId']);
}
// Check if a Place exists with the same OSM ID and type
$place = null;
if ($demande->getOsmId() && $demande->getOsmObjectType()) {
$existingPlace = $this->entityManager->getRepository(Place::class)->findOneBy([
'osm_kind' => $demande->getOsmObjectType(),
@ -162,6 +163,45 @@ class PublicController extends AbstractController
// Link the Place UUID to the Demande
$demande->setPlaceUuid($existingPlace->getUuidForUrl());
$demande->setPlace($existingPlace);
$place = $existingPlace;
} else {
// Create a new Place if one doesn't exist
$place = new Place();
$place->setOsmId((string)$demande->getOsmId());
$place->setOsmKind($demande->getOsmObjectType());
// Get OSM data from Overpass API
$commerce_overpass = $this->motocultrice->get_osm_object_data($demande->getOsmObjectType(), $demande->getOsmId());
if ($commerce_overpass) {
// Update the Place with OSM data
$place->update_place_from_overpass_data($commerce_overpass);
// Link the Place to the Demande
$demande->setPlaceUuid($place->getUuidForUrl());
$demande->setPlace($place);
// Persist the Place
$this->entityManager->persist($place);
}
}
// Link the Place to a Stat object using the INSEE code
if ($place && $demande->getInsee()) {
$stats = $place->getStats();
if (!$stats) {
$stats_exist = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $demande->getInsee()]);
if ($stats_exist) {
$stats = $stats_exist;
} else {
$stats = new Stats();
$stats->setZone((string)$demande->getInsee());
$this->entityManager->persist($stats);
}
$stats->addPlace($place);
$place->setStats($stats);
}
}
}

View file

@ -41,8 +41,8 @@ class Demande
#[ORM\Column(length: 10, nullable: true)]
private ?string $osmObjectType = null;
#[ORM\Column(nullable: true)]
private ?int $osmId = null;
#[ORM\Column(nullable: true, type: 'string', length: 255)]
private ?string $osmId = null;
public function __construct()
{
@ -163,12 +163,12 @@ class Demande
return $this;
}
public function getOsmId(): ?int
public function getOsmId(): ?string
{
return $this->osmId;
}
public function setOsmId(?int $osmId): static
public function setOsmId(?string $osmId): static
{
$this->osmId = $osmId;