From ccab91628635c961844a1ef79b31ee4f87fa4952 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 28 May 2025 16:24:34 +0200 Subject: [PATCH] ajout recherche par nom --- public/assets/js/main.js | 1 + src/Controller/AdminController.php | 40 ++++- src/Controller/PublicController.php | 103 ++++++++++-- templates/admin/stats.html.twig | 154 +++-------------- templates/base.html.twig | 6 - templates/public/dashboard.html.twig | 26 ++- templates/public/edit.html.twig | 12 +- templates/public/edit/address.html.twig | 18 +- templates/public/edit/opening_hours.html.twig | 32 +--- templates/public/home.html.twig | 155 ++++++++++++++++++ templates/public/view.html.twig | 2 +- 11 files changed, 345 insertions(+), 204 deletions(-) create mode 100644 public/assets/js/main.js create mode 100644 templates/public/home.html.twig diff --git a/public/assets/js/main.js b/public/assets/js/main.js new file mode 100644 index 0000000..73c0265 --- /dev/null +++ b/public/assets/js/main.js @@ -0,0 +1 @@ +console.log('Hello World'); \ No newline at end of file diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 84c8ff6..1df185f 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -76,6 +76,29 @@ final class AdminController extends AbstractController ]); } + #[Route('/admin/commerce/{id}', name: 'app_admin_commerce')] + public function commerce(int $id): Response + { + + // Vérifier si on est en prod + if ($this->getParameter('kernel.environment') === 'prod') { + $this->addFlash('error', 'Vous n\'avez pas accès à cette page en production.'); + return $this->redirectToRoute('app_public_index'); + } + $commerce = $this->entityManager->getRepository(Place::class)->find($id); + + if (!$commerce) { + throw $this->createNotFoundException('Commerce non trouvé'); + } + + // Redirection vers la page de modification avec les paramètres nécessaires + return $this->redirectToRoute('app_public_edit', [ + 'zipcode' => $commerce->getZipCode(), + 'name' => $commerce->getName() ?? '?', + 'uuid' => $commerce->getUuidForUrl() + ]); + } + #[Route('/admin/labourer/{zip_code}', name: 'app_admin_labourer')] public function labourer_zone(string $zip_code): Response { @@ -201,13 +224,16 @@ final class AdminController extends AbstractController public function delete(int $id): Response { $commerce = $this->entityManager->getRepository(Place::class)->find($id); - $name = $commerce->getName(); - $this->entityManager->remove($commerce); - $this->entityManager->flush(); + if($commerce) { + $this->entityManager->remove($commerce); + $this->entityManager->flush(); - $this->addFlash('success', 'Le lieu '.$name.' a été supprimé avec succès de OSM Mes commerces, mais pas dans OpenStreetMap.'); + $this->addFlash('success', 'Le lieu '.$commerce->getName().' a été supprimé avec succès de OSM Mes commerces, mais pas dans OpenStreetMap.'); + } else { + $this->addFlash('error', 'Le lieu n\'existe pas.'); + } - return $this->redirectToRoute('app_admin_dashboard'); + return $this->redirectToRoute('app_public_dashboard'); } #[Route('/admin/delete_by_zone/{zip_code}', name: 'app_admin_delete_by_zone')] @@ -222,8 +248,8 @@ final class AdminController extends AbstractController $this->addFlash('success', 'Tous les commerces de la zone '.$zip_code.' ont été supprimés avec succès de OSM Mes commerces, mais pas dans OpenStreetMap.'); - return $this->redirectToRoute('app_admin_dashboard'); - } + return $this->redirectToRoute('app_public_dashboard'); + } #[Route('/admin/export', name: 'app_admin_export')] diff --git a/src/Controller/PublicController.php b/src/Controller/PublicController.php index 63159da..7a6493b 100644 --- a/src/Controller/PublicController.php +++ b/src/Controller/PublicController.php @@ -11,7 +11,8 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use GuzzleHttp\Client; use Symfony\Component\HttpFoundation\Request; - +use Symfony\Component\Mime\Email; +use Symfony\Component\Mailer\MailerInterface; class PublicController extends AbstractController { @@ -20,21 +21,100 @@ class PublicController extends AbstractController public function __construct( private EntityManagerInterface $entityManager, - private Motocultrice $motocultrice + private Motocultrice $motocultrice, + private MailerInterface $mailer ) { } - + #[Route('/propose-email/{email}/{type}/{id}', name: 'app_public_propose_email')] + public function proposeEmail(string $email, string $type, int $id): Response + { + + + $data = $this->motocultrice->get_osm_object_data($type, $id); + // Récupérer le code postal depuis les tags, sinon mettre -1 + $zipCode = isset($data['tags_converted']['addr:postcode']) ? (int)$data['tags_converted']['addr:postcode'] : -1; + $place_name = $data['tags_converted']['name']; + + // Vérifier si une Place existe déjà avec le même osm_kind et osmId + $existingPlace = $this->entityManager->getRepository(Place::class)->findOneBy([ + 'osm_kind' => $type, + 'osmId' => $id + ]); + + if ($existingPlace) { + // Mettre à jour l'email de la Place existante + $existingPlace->setEmail($email)->setLastContactAttemptDate(new \DateTime()); + $this->entityManager->flush(); + + $debug = ''; + if ($this->getParameter('kernel.environment') !== 'prod') { + $debug = 'Bonjour, nous sommes des bénévoles d\'OpenStreetMap France et nous vous proposons de modifier les informations de votre commerce. Voici votre lien unique de modification: ' . $this->generateUrl('app_public_edit', [ + 'zipcode' => $zipCode, + 'name' => $place_name, + 'uuid' => $existingPlace->getUuidForUrl() + ], true); + } + + $this->addFlash('success', 'L\'email a été mis à jour. Un email vous sera envoyé avec le lien de modification. '.$debug); + } else { + + + // Créer une nouvelle entité Place + $place = new Place(); + $place->setEmail($email) + ->setOsmId($id) + ->setOsmKind($type) + ->setAskedHumainsSupport(false) + ->setOptedOut(false) + ->setDead(false) + ->setNote('') + ->setModifiedDate(new \DateTime()) + ->setZipCode($zipCode) + ->setPlaceCount(0) + + ->setLastContactAttemptDate(new \DateTime()) + ->setUuidForUrl(uniqid()); + + $this->entityManager->persist($place); + $this->entityManager->flush(); + + $debug = ''; + if ($this->getParameter('kernel.environment') !== 'prod') { + $debug = 'Bonjour, nous sommes des bénévoles d\'OpenStreetMap France et nous vous proposons de modifier les informations de votre commerce. Voici votre lien unique de modification: ' . $this->generateUrl('app_public_edit', [ + 'zipcode' => $zipCode, + 'name' => $place_name, + 'uuid' => $place->getUuidForUrl() + ], true); + } + $this->addFlash('success', 'Un email vous sera envoyé avec le lien de modification. '.$debug); + } + + // Envoyer l'email + $destinataire = $this->getParameter('kernel.environment') === 'prod' ? $email : 'contact+essai_osm_commerce@cipherbliss.com'; + + $message = (new Email()) + ->from('contact@osm-commerce.fr') + ->to($destinataire) + ->subject('Votre lien de modification OpenStreetMap') + ->text('Bonjour, nous sommes des bénévoles d\'OpenStreetMap France et nous vous proposons de modifier les informations de votre commerce. Voici votre lien unique de modification: ' . $this->generateUrl('app_public_edit', [ + 'zipcode' => $zipCode, + 'name' => $place_name, + 'uuid' => $existingPlace ? $existingPlace->getUuidForUrl() : $place->getUuidForUrl() + ], true)); + + $this->mailer->send($message); + + return $this->redirectToRoute('app_public_index'); + } #[Route('/', name: 'app_public_index')] public function index(): Response { - $commerce = $this->motocultrice->get_osm_object_data(); - return $this->render('public/index.html.twig', [ + + return $this->render('public/home.html.twig', [ 'controller_name' => 'PublicController', - 'commerce' => $commerce, - 'mapbox_token' => $_ENV['MAPBOX_TOKEN'], - 'maptiler_token' => $_ENV['MAPTILER_TOKEN'], + ]); } @@ -123,13 +203,8 @@ class PublicController extends AbstractController $status = "Erreur : Le code postal doit être composé de 5 chiffres"; continue; } - } elseif ($tagKey === 'contact:phone' || $tagKey === 'phone') { - // Nettoyer le numéro de téléphone - $value = preg_replace('/[^0-9+]/', '', $value); - } elseif (strpos($value, 'http://') === 0) { - $value = str_replace('http://', 'https://', $value); } - $tags[$tagKey] = $value; + $tags[$tagKey] = trim($value); } } } diff --git a/templates/admin/stats.html.twig b/templates/admin/stats.html.twig index df1c766..517ccaa 100644 --- a/templates/admin/stats.html.twig +++ b/templates/admin/stats.html.twig @@ -43,7 +43,10 @@ {% for commerce in stats.places %} - {{ commerce.name }} + + {{ commerce.name }} + + {{ commerce.address }} {{ commerce.website }} {{ commerce.wheelchair }} @@ -54,139 +57,22 @@ + + {% endblock %} \ No newline at end of file diff --git a/templates/base.html.twig b/templates/base.html.twig index ad2e7eb..baf560e 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -38,12 +38,6 @@ padding-bottom: 15rem; margin-top: 5rem; } - {# table tr:nth-child(odd){ - background-color:rgb(235, 235, 235); - } - table tr:nth-child(even){ - background-color: #f8f9fa; - } #} {% block stylesheets %} diff --git a/templates/public/dashboard.html.twig b/templates/public/dashboard.html.twig index 000ab8f..99d952a 100644 --- a/templates/public/dashboard.html.twig +++ b/templates/public/dashboard.html.twig @@ -27,14 +27,22 @@ Zone Nombre de commerces Complétude % + Actions {% for stat in stats %} - {{ stat.zone }} + + {{ stat.zone }} + {{ stat.placesCount }} {{ stat.completionPercent }} + + + + + {% endfor %} @@ -50,6 +58,7 @@ Date de dernier contact Date de dernière modification Code postal + Actions @@ -58,21 +67,26 @@ {% for place in places %} - {{ place.name }} + {% if place.name %} + {{ place.name }} + {% else %} + + {% endif %} {{ place.email }} {{ place.modifiedDate | date('Y-m-d H:i:s') }} {{ place.lastContactAttemptDate | date('Y-m-d H:i:s') }} {{ place.modifiedDate | date('Y-m-d H:i:s') }} {{ place.zipCode }} - Voir dans OSM + {% if place.name %} - Modifier + {% else %} - Modifier + {% endif %} - + + {% endfor %} diff --git a/templates/public/edit.html.twig b/templates/public/edit.html.twig index 4c409f8..03352e7 100644 --- a/templates/public/edit.html.twig +++ b/templates/public/edit.html.twig @@ -1,6 +1,6 @@ {% extends 'base.html.twig' %} -{% block title %}{{ 'display.title'|trans }}{% endblock %} +{% block title %}{{ 'display.title'|trans }} {{ commerce_overpass.tags_converted.name }}{% endblock %} {% block stylesheets %} {{ parent() }} @@ -58,15 +58,21 @@ {% if hide_filled_inputs and (commerce_overpass.tags_converted['addr:street']) is defined and commerce_overpass.tags_converted['addr:street'] is not empty + and (commerce_overpass.tags_converted['addr:housenumber']) is defined and commerce_overpass.tags_converted['addr:housenumber'] is not empty %} {% include 'public/edit/address.html.twig' %} {% endif %} - {% if hide_filled_inputs and (commerce_overpass.tags_converted.opening_hours) is defined and commerce_overpass.tags_converted.opening_hours is not empty %} + {% if hide_filled_inputs and (commerce_overpass.tags_converted.opening_hours) is defined and commerce_overpass.tags_converted.opening_hours is empty %} {% include 'public/edit/opening_hours.html.twig' %} {% endif %} - {% if hide_filled_inputs and (commerce_overpass.tags_converted.wheelchair) is defined and commerce_overpass.tags_converted.wheelchair is not empty %} + + {% if (commerce_overpass.tags_converted.wheelchair) is defined %} + {{ dump(commerce_overpass.tags_converted.wheelchair) }} + {% endif %} + + {% if hide_filled_inputs and (commerce_overpass.tags_converted.wheelchair) is defined and commerce_overpass.tags_converted.wheelchair is empty %} {% include 'public/edit/wheelchair.html.twig' %} {% endif %} {% if hide_filled_inputs and (commerce_overpass.tags_converted.ask_angela) is defined and commerce_overpass.tags_converted.ask_angela is not empty %} diff --git a/templates/public/edit/address.html.twig b/templates/public/edit/address.html.twig index 16e5c83..e9dab4e 100644 --- a/templates/public/edit/address.html.twig +++ b/templates/public/edit/address.html.twig @@ -1,10 +1,12 @@
-

{{ 'display.address'|trans }}

-
-
- +

{{ 'display.address'|trans }}

+
+
+ + - -
-
-
\ No newline at end of file + + +
+
+ \ No newline at end of file diff --git a/templates/public/edit/opening_hours.html.twig b/templates/public/edit/opening_hours.html.twig index 428a9e7..b51dbb6 100644 --- a/templates/public/edit/opening_hours.html.twig +++ b/templates/public/edit/opening_hours.html.twig @@ -13,32 +13,14 @@ {% endif %}
- - Exemples : - - - + Exemples : +
- {# - Lundi de - - - à - . - - - et - - - à - . - - #}
- + \ No newline at end of file diff --git a/templates/public/home.html.twig b/templates/public/home.html.twig new file mode 100644 index 0000000..8b98a98 --- /dev/null +++ b/templates/public/home.html.twig @@ -0,0 +1,155 @@ +{% extends 'base.html.twig' %} + +{% block title %}{{ 'display.title'|trans }}{% endblock %} + +{% block stylesheets %} + {{ parent() }} + + +{% endblock %} + +{% block body %} +
+
+
+ + + +

+ Mon Commerce OSM +

+

+ Bonjour, ce site permet de modifier les informations de votre commerce sur OpenStreetMap afin de gagner en visibilité sur des milliers de sites web à la fois en une minute, c'est gratuit et sans engagement. Nous sommes bénévoles dans une association à but non lucratif. +
+ Nous vous enverrons un lien unique pour cela par email, et si vous en avez besoin, nous pouvons vous aider. +

+

+ + +

+
+ +
+
+ +
+ +
+ + + +
+
+ +
+
+
+ +{% endblock %} + diff --git a/templates/public/view.html.twig b/templates/public/view.html.twig index 6a9f5c0..0a064d6 100644 --- a/templates/public/view.html.twig +++ b/templates/public/view.html.twig @@ -14,7 +14,7 @@ {% if status == "Les tags ont été mis à jour avec succès" %} {{status}} -

+

Merci d'avoir contribué à l'amélioration de la base de données OSM, votre contribution sera visible sur de nombreux sites web.