mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-09 17:02:46 +02:00
motocultrice labourer aussi les lieux sans email, et proposition opening hours
This commit is contained in:
parent
268ac799e4
commit
cae369c9cd
9 changed files with 565 additions and 53 deletions
|
@ -111,6 +111,9 @@ class Motocultrice
|
|||
|
||||
public function labourer(string $zone): array
|
||||
{
|
||||
|
||||
$use_places_without_email_to_reference = $_ENV['USE_PLACES_WITHOUT_EMAIL_TO_REFERENCE'] ?? false;
|
||||
|
||||
if (!$zone) {
|
||||
throw new \InvalidArgumentException("La zone ne peut pas être vide");
|
||||
}
|
||||
|
@ -119,27 +122,44 @@ class Motocultrice
|
|||
$zone = addslashes(trim($zone));
|
||||
|
||||
$query = <<<QUERY
|
||||
[out:json][timeout:25];
|
||||
area["postal_code"="{$zone}"]->.searchArea;
|
||||
(
|
||||
// Recherche des commerces et services avec email
|
||||
nw["amenity"]["contact:email"](area.searchArea);
|
||||
nw["amenity"]["email"](area.searchArea);
|
||||
nw["shop"]["contact:email"](area.searchArea);
|
||||
nw["shop"]["email"](area.searchArea);
|
||||
nw["office"]["contact:email"](area.searchArea);
|
||||
nw["office"]["email"](area.searchArea);
|
||||
|
||||
// Recherche des commerces et services sans email pour référence
|
||||
nw["amenity"](area.searchArea);
|
||||
nw["shop"](area.searchArea);
|
||||
nw["office"](area.searchArea);
|
||||
);
|
||||
out body;
|
||||
>;
|
||||
out skel qt;
|
||||
[out:json][timeout:25];
|
||||
area["postal_code"="{$zone}"]->.searchArea;
|
||||
(
|
||||
// Recherche des commerces et services avec email
|
||||
nw["amenity"]["contact:email"](area.searchArea);
|
||||
nw["amenity"]["email"](area.searchArea);
|
||||
nw["shop"]["contact:email"](area.searchArea);
|
||||
nw["shop"]["email"](area.searchArea);
|
||||
nw["office"]["contact:email"](area.searchArea);
|
||||
nw["office"]["email"](area.searchArea);
|
||||
|
||||
// Recherche des commerces et services sans email pour référence
|
||||
nw["amenity"](area.searchArea);
|
||||
nw["shop"](area.searchArea);
|
||||
nw["office"](area.searchArea);
|
||||
);
|
||||
out body;
|
||||
>;
|
||||
out skel qt;
|
||||
QUERY;
|
||||
|
||||
if($use_places_without_email_to_reference) {
|
||||
$query = <<<QUERY
|
||||
|
||||
[out:json][timeout:25];
|
||||
area["postal_code"="{$zone}"]->.searchArea;
|
||||
(
|
||||
nw["amenity"]["cafe|bar|restaurant"](area.searchArea);
|
||||
nw["shop"](area.searchArea);
|
||||
nw["tourism"="museum"](area.searchArea);
|
||||
nw["office"](area.searchArea);
|
||||
);
|
||||
out body;
|
||||
>;
|
||||
out skel qt;
|
||||
QUERY;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->client->request('POST', $this->overpassApiUrl, [
|
||||
'body' => ['data' => $query]
|
||||
|
@ -152,13 +172,15 @@ QUERY;
|
|||
foreach ($data['elements'] as $element) {
|
||||
if (isset($element['tags'])) {
|
||||
|
||||
|
||||
$email = "";
|
||||
if( ! $use_places_without_email_to_reference){
|
||||
|
||||
$email = $element['tags']['contact:email'] ?? $element['tags']['email'] ?? null;
|
||||
// On passe si pas d'email
|
||||
if (!$email) {
|
||||
continue;
|
||||
}
|
||||
$email = $element['tags']['contact:email'] ?? $element['tags']['email'] ?? null;
|
||||
// On passe si pas d'email
|
||||
if (!$email) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$places[] = [
|
||||
'id' => $element['id'],
|
||||
|
@ -175,6 +197,9 @@ QUERY;
|
|||
|
||||
return $places;
|
||||
} catch (\Exception $e) {
|
||||
var_dump($query);
|
||||
var_dump($e->getMessage());
|
||||
die();
|
||||
throw new \Exception("Erreur lors de la requête Overpass : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -202,9 +227,19 @@ QUERY;
|
|||
} elseif (isset($osm_object_data['way'])) {
|
||||
$osm_object_data['way']['tags_converted'] = [];
|
||||
}
|
||||
if(isset($osm_object_data['node'])){
|
||||
foreach ($osm_object_data['node']['tag'] as $attribute) {
|
||||
$osm_object_data['node']['tags_converted'][$attribute['@attributes']['k']] = $attribute['@attributes']['v'];
|
||||
if(isset($osm_object_data['node'])){
|
||||
// Vérifier si le nœud a des tags
|
||||
if (!isset($osm_object_data['node']['tag'])) {
|
||||
$osm_object_data['node']['tags_converted'] = [];
|
||||
return $osm_object_data['node'];
|
||||
}
|
||||
|
||||
// Si un seul tag, le convertir en tableau
|
||||
if (isset($osm_object_data['node']['tag']['@attributes'])) {
|
||||
$osm_object_data['node']['tag'] = [$osm_object_data['node']['tag']];
|
||||
}
|
||||
foreach ($osm_object_data['node']['tag'] as $tag) {
|
||||
$osm_object_data['node']['tags_converted'][$tag['@attributes']['k']] = $tag['@attributes']['v'];
|
||||
}
|
||||
$osm_object_data['node']['tags_converted'] = $this->migrate_tags($osm_object_data['node']['tags_converted']);
|
||||
return $osm_object_data['node'];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue