service motocultrice, traductions
This commit is contained in:
parent
528ebb672a
commit
f5ab0c8205
16 changed files with 427 additions and 128 deletions
18
src/Controller/AdminController.php
Normal file
18
src/Controller/AdminController.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class AdminController extends AbstractController
|
||||
{
|
||||
#[Route('/admin', name: 'app_admin')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('admin/index.html.twig', [
|
||||
'controller_name' => 'AdminController',
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ namespace App\Controller;
|
|||
|
||||
use App\Entity\Stats;
|
||||
use App\Entity\Place;
|
||||
use App\Service\Motocultrice;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -17,78 +18,17 @@ class PublicController extends AbstractController
|
|||
private $maptiler_token = 'BVM2NRJuzQunWvXbTnzg';
|
||||
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager
|
||||
private EntityManagerInterface $entityManager,
|
||||
private Motocultrice $motocultrice
|
||||
) {
|
||||
}
|
||||
|
||||
public function get_osm_object_data($osm_object_id = 12855459190)
|
||||
{
|
||||
|
||||
// TODO extraire ceci dans un service
|
||||
$object_id = "https://www.openstreetmap.org/api/0.6/node/".$osm_object_id;
|
||||
|
||||
$osm_object_data = [
|
||||
// "version"=> "0.6",
|
||||
// "generator"=> "openstreetmap-cgimap 2.0.1 (2557185 spike-08.openstreetmap.org)",
|
||||
// "copyright"=> "OpenStreetMap and contributors",
|
||||
// "attribution"=> "http://www.openstreetmap.org/copyright",
|
||||
// "license"=> "http://opendatacommons.org/licenses/odbl/1-0/",
|
||||
// "elements"=> [
|
||||
// [
|
||||
// "type"=> "node",
|
||||
// "id"=> 12855459190,
|
||||
// "lat"=> 49.6504926,
|
||||
// "lon"=> -1.5722526,
|
||||
// "timestamp"=> "2025-05-22T13:15:45Z",
|
||||
// "version"=> 1,
|
||||
// "changeset"=> 166613142,
|
||||
// "user"=> "tykayn",
|
||||
// "uid"=> 2962129,
|
||||
// "tags"=> [
|
||||
// "name"=> "Harry le potier",
|
||||
// "tourism"=> "artwork"
|
||||
// ]
|
||||
// ]
|
||||
// ]
|
||||
];
|
||||
|
||||
// Récupérer les vraies données OSM
|
||||
$client = new Client();
|
||||
try {
|
||||
$response = $client->get($object_id);
|
||||
$xml = simplexml_load_string($response->getBody()->getContents());
|
||||
$json = json_encode($xml);
|
||||
$osm_object_data = json_decode($json, true);
|
||||
} catch (\Exception $e) {
|
||||
// En cas d'erreur, on garde les données de test
|
||||
$this->addFlash('warning', 'Impossible de récupérer les données OSM. Utilisation des données de test.');
|
||||
}
|
||||
|
||||
// var_dump($osm_object_data['node']);
|
||||
// die();
|
||||
|
||||
// convertir les tags en clés et valeurs
|
||||
$osm_object_data['tags_converted'] = [];
|
||||
|
||||
// var_dump($osm_object_data['node']['tag']);
|
||||
|
||||
|
||||
foreach ($osm_object_data['node']['tag'] as $attribute) {
|
||||
// var_dump($attribute['@attributes']['k']);
|
||||
// die();
|
||||
|
||||
$osm_object_data['node']['tags_converted'][$attribute['@attributes']['k']] = $attribute['@attributes']['v'];
|
||||
}
|
||||
|
||||
// var_dump($osm_object_data['node']['tags_converted']);
|
||||
// die();
|
||||
return $osm_object_data['node'];
|
||||
}
|
||||
|
||||
|
||||
#[Route('/', name: 'app_public_index')]
|
||||
public function index(): Response
|
||||
{
|
||||
$commerce = $this->get_osm_object_data();
|
||||
$commerce = $this->motocultrice->get_osm_object_data();
|
||||
return $this->render('public/index.html.twig', [
|
||||
'controller_name' => 'PublicController',
|
||||
'commerce' => $commerce,
|
||||
|
@ -212,7 +152,7 @@ class PublicController extends AbstractController
|
|||
}
|
||||
|
||||
// après envoi on récupère les données
|
||||
$commerce = $this->get_osm_object_data($osm_object_id);
|
||||
$commerce = $this->motocultrice->get_osm_object_data($osm_object_id);
|
||||
return $this->render('public/view.html.twig', [
|
||||
'controller_name' => 'PublicController',
|
||||
'commerce' => $commerce,
|
||||
|
|
91
src/Service/Motocultrice.php
Normal file
91
src/Service/Motocultrice.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class Motocultrice
|
||||
{
|
||||
private $overpassApiUrl = 'https://overpass-api.de/api/interpreter';
|
||||
|
||||
public function __construct(
|
||||
private HttpClientInterface $client
|
||||
) {
|
||||
}
|
||||
|
||||
public function labourer(string $zone): array
|
||||
{
|
||||
$query = <<<QUERY
|
||||
[out:json][timeout:25];
|
||||
area["name"="{$zone}"]->.searchArea;
|
||||
(
|
||||
nwr["shop"](area.searchArea);
|
||||
);
|
||||
out body;
|
||||
>;
|
||||
out skel qt;
|
||||
QUERY;
|
||||
|
||||
try {
|
||||
$response = $this->client->request('POST', $this->overpassApiUrl, [
|
||||
'body' => ['data' => $query]
|
||||
]);
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
|
||||
$shops = [];
|
||||
if (isset($data['elements'])) {
|
||||
foreach ($data['elements'] as $element) {
|
||||
if (isset($element['tags']['shop'])) {
|
||||
$shops[] = [
|
||||
'id' => $element['id'],
|
||||
'type' => $element['type'],
|
||||
'name' => $element['tags']['name'] ?? 'Sans nom',
|
||||
'shop_type' => $element['tags']['shop'],
|
||||
'lat' => $element['lat'] ?? null,
|
||||
'lon' => $element['lon'] ?? null,
|
||||
'tags' => $element['tags']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $shops;
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Erreur lors de la requête Overpass : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function get_osm_object_data($osm_object_id = 12855459190)
|
||||
{
|
||||
$object_id = "https://www.openstreetmap.org/api/0.6/node/".$osm_object_id;
|
||||
|
||||
try {
|
||||
$response = $this->client->request('GET', $object_id);
|
||||
$xml = simplexml_load_string($response->getContent());
|
||||
$json = json_encode($xml);
|
||||
$osm_object_data = json_decode($json, true);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Impossible de récupérer les données OSM : " . $e->getMessage());
|
||||
}
|
||||
|
||||
// convertir les tags en clés et valeurs
|
||||
$osm_object_data['tags_converted'] = [];
|
||||
|
||||
foreach ($osm_object_data['node']['tag'] as $attribute) {
|
||||
$osm_object_data['node']['tags_converted'][$attribute['@attributes']['k']] = $attribute['@attributes']['v'];
|
||||
}
|
||||
|
||||
return $osm_object_data['node'];
|
||||
}
|
||||
|
||||
public function semer(): string
|
||||
{
|
||||
return "La motocultrice sème les graines";
|
||||
}
|
||||
|
||||
public function récolter(): string
|
||||
{
|
||||
return "La motocultrice récolte les cultures";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue