up recherche home
This commit is contained in:
parent
c89751b45c
commit
7887356dd9
3 changed files with 281 additions and 251 deletions
|
@ -2,23 +2,22 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Stats;
|
||||
use App\Entity\Place;
|
||||
use App\Entity\CityFollowUp;
|
||||
use App\Entity\Demande;
|
||||
use App\Service\Motocultrice;
|
||||
use App\Service\FollowUpService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use GuzzleHttp\Client;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use App\Entity\Place;
|
||||
use App\Entity\Stats;
|
||||
use App\Service\ActionLogger;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use App\Service\FollowUpService;
|
||||
use App\Service\Motocultrice;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use GuzzleHttp\Client;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class PublicController extends AbstractController
|
||||
{
|
||||
|
@ -27,11 +26,13 @@ class PublicController extends AbstractController
|
|||
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private Motocultrice $motocultrice,
|
||||
private MailerInterface $mailer,
|
||||
private ActionLogger $actionLogger,
|
||||
private FollowUpService $followUpService
|
||||
) {}
|
||||
private Motocultrice $motocultrice,
|
||||
private MailerInterface $mailer,
|
||||
private ActionLogger $actionLogger,
|
||||
private FollowUpService $followUpService
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/propose-email/{email}/{type}/{id}', name: 'app_public_propose_email')]
|
||||
public function proposeEmail(string $email, string $type, int $id): Response
|
||||
|
@ -60,11 +61,11 @@ class PublicController extends AbstractController
|
|||
|
||||
$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);
|
||||
$debug = 'Voici votre lien unique de modification: <a href="' . $this->generateUrl('app_public_edit', [
|
||||
'zipcode' => $zipCode,
|
||||
'name' => $place_name,
|
||||
'uuid' => $existingPlace->getUuidForUrl()
|
||||
], true) . '">cliquez ici pour accéder au formulaire de modification</a>"';
|
||||
}
|
||||
|
||||
$this->addFlash('success', 'L\'email a été mis à jour. Un email vous sera envoyé avec le lien de modification. ' . $debug);
|
||||
|
@ -95,10 +96,10 @@ class PublicController extends AbstractController
|
|||
$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);
|
||||
'zipcode' => $zipCode,
|
||||
'name' => $place_name,
|
||||
'uuid' => $place->getUuidForUrl()
|
||||
], true);
|
||||
}
|
||||
$this->addFlash('success', 'Un email vous sera envoyé avec le lien de modification. ' . $debug);
|
||||
}
|
||||
|
@ -111,10 +112,10 @@ class PublicController extends AbstractController
|
|||
->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));
|
||||
'zipcode' => $zipCode,
|
||||
'name' => $place_name,
|
||||
'uuid' => $existingPlace ? $existingPlace->getUuidForUrl() : $place->getUuidForUrl()
|
||||
], true));
|
||||
|
||||
$this->mailer->send($message);
|
||||
|
||||
|
@ -195,21 +196,31 @@ class PublicController extends AbstractController
|
|||
$stats = $stats_exist;
|
||||
} else {
|
||||
$stats = new Stats();
|
||||
$stats->setZone((string)$demande->getInsee());
|
||||
$zipcode = (string)$demande->getInsee();
|
||||
$stats->setZone($zipcode);
|
||||
$place->setZipCode($zipcode);
|
||||
$this->entityManager->persist($stats);
|
||||
}
|
||||
|
||||
|
||||
$stats->addPlace($place);
|
||||
$place->setStats($stats);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$place->getUuidForUrl()) {
|
||||
$place->setUuidForUrl(uniqid());
|
||||
}
|
||||
if (!$place->getZipCode()) {
|
||||
$place->setZipCode("00000");
|
||||
}
|
||||
|
||||
$this->entityManager->persist($demande);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse([
|
||||
'success' => true,
|
||||
'success' => true,
|
||||
'message' => 'Demande créée avec succès',
|
||||
'id' => $demande->getId()
|
||||
]);
|
||||
|
@ -237,7 +248,7 @@ class PublicController extends AbstractController
|
|||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse([
|
||||
'success' => true,
|
||||
'success' => true,
|
||||
'message' => 'Email ajouté avec succès'
|
||||
]);
|
||||
}
|
||||
|
@ -260,8 +271,8 @@ class PublicController extends AbstractController
|
|||
'name' => $cityName,
|
||||
'zone' => $stat->getZone(),
|
||||
'coordinates' => [
|
||||
'lat' => (float) $stat->getLat(),
|
||||
'lon' => (float) $stat->getLon()
|
||||
'lat' => (float)$stat->getLat(),
|
||||
'lon' => (float)$stat->getLon()
|
||||
],
|
||||
'placesCount' => $stat->getPlacesCount(),
|
||||
'completionPercent' => $stat->getCompletionPercent(),
|
||||
|
@ -317,8 +328,8 @@ class PublicController extends AbstractController
|
|||
if (!empty($data) && isset($data[0]['lat']) && isset($data[0]['lon'])) {
|
||||
error_log("DEBUG: Coordonnées trouvées pour $cityName ($inseeCode): " . $data[0]['lat'] . ", " . $data[0]['lon']);
|
||||
return [
|
||||
'lat' => (float) $data[0]['lat'],
|
||||
'lon' => (float) $data[0]['lon']
|
||||
'lat' => (float)$data[0]['lat'],
|
||||
'lon' => (float)$data[0]['lon']
|
||||
];
|
||||
} else {
|
||||
error_log("DEBUG: Aucune coordonnée trouvée pour $cityName ($inseeCode)");
|
||||
|
@ -846,7 +857,7 @@ class PublicController extends AbstractController
|
|||
public function publicFollowupGraph(string $insee_code, string $theme): Response
|
||||
{
|
||||
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
|
||||
if (!$stats) {
|
||||
if (!$stats) {
|
||||
$this->addFlash('error', '13 Aucune stats trouvée pour ce code INSEE.');
|
||||
return $this->redirectToRoute('app_public_index');
|
||||
}
|
||||
|
@ -901,7 +912,7 @@ class PublicController extends AbstractController
|
|||
if ($place) {
|
||||
return $this->redirectToRoute('app_public_edit', [
|
||||
'zipcode' => $place->getZipCode(),
|
||||
'name' => $place->getName() !== '' ? $place->getName() : '?',
|
||||
'name' => $place->getName() ? $place->getName() : '?',
|
||||
'uuid' => $place->getUuidForUrl()
|
||||
]);
|
||||
} else {
|
||||
|
@ -1115,7 +1126,7 @@ class PublicController extends AbstractController
|
|||
|
||||
// Trier les changements par date pour chaque thème
|
||||
foreach ($themeChanges as &$changes) {
|
||||
usort($changes, function($a, $b) {
|
||||
usort($changes, function ($a, $b) {
|
||||
return $b->getDate() <=> $a->getDate();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
// use App\Service\Motocultrice;
|
||||
#[ORM\Entity(repositoryClass: PlaceRepository::class)]
|
||||
class Place
|
||||
|
@ -94,12 +95,12 @@ class Place
|
|||
#[ORM\Column(length: 255, nullable: true, options: ['charset' => 'utf8mb4'])]
|
||||
private ?string $street = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true, options: ['charset'
|
||||
=> 'utf8mb4'])]
|
||||
#[ORM\Column(length: 255, nullable: true, options: ['charset'
|
||||
=> 'utf8mb4'])]
|
||||
private ?string $housenumber = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true, options: ['charset'
|
||||
=> 'utf8mb4'])]
|
||||
#[ORM\Column(length: 255, nullable: true, options: ['charset'
|
||||
=> 'utf8mb4'])]
|
||||
private ?string $siret = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
|
@ -134,7 +135,7 @@ class Place
|
|||
if ($this->main_tag == 'amenity=bar') {
|
||||
return 'bar';
|
||||
}
|
||||
if ($this->main_tag == 'amenity=cafe') {
|
||||
if ($this->main_tag == 'amenity=cafe') {
|
||||
return 'café';
|
||||
}
|
||||
if ($this->main_tag == 'amenity=hotel') {
|
||||
|
@ -164,7 +165,7 @@ class Place
|
|||
return $this->main_tag;
|
||||
}
|
||||
|
||||
public function setMainTag(?string $main_tag): static
|
||||
public function setMainTag(?string $main_tag): static
|
||||
{
|
||||
$this->main_tag = $main_tag;
|
||||
|
||||
|
@ -188,36 +189,39 @@ class Place
|
|||
}
|
||||
if ($this->has_wheelchair) {
|
||||
$filled_fields += 1;
|
||||
}
|
||||
}
|
||||
if ($this->has_note) {
|
||||
$filled_fields += 1;
|
||||
}
|
||||
return round($filled_fields / $total_fields * 100);
|
||||
}
|
||||
|
||||
public function guess_main_tag(array $tags_converted) {
|
||||
public function guess_main_tag(array $tags_converted)
|
||||
{
|
||||
$main_tag = null;
|
||||
if (isset($tags_converted['amenity']) && $tags_converted['amenity'] != '') {
|
||||
$main_tag = 'amenity='.$tags_converted['amenity'];
|
||||
$main_tag = 'amenity=' . $tags_converted['amenity'];
|
||||
}
|
||||
if (isset($tags_converted['shop']) && $tags_converted['shop'] != '') {
|
||||
$main_tag = 'shop='.$tags_converted['shop'];
|
||||
$main_tag = 'shop=' . $tags_converted['shop'];
|
||||
}
|
||||
if (isset($tags_converted['tourism']) && $tags_converted['tourism'] != '') {
|
||||
$main_tag = 'tourism='.$tags_converted['tourism'];
|
||||
$main_tag = 'tourism=' . $tags_converted['tourism'];
|
||||
}
|
||||
if (isset($tags_converted['office']) && $tags_converted['office'] != '') {
|
||||
$main_tag = 'office='.$tags_converted['office'];
|
||||
$main_tag = 'office=' . $tags_converted['office'];
|
||||
}
|
||||
if (isset($tags_converted['healthcare']) && $tags_converted['healthcare'] != '') {
|
||||
$main_tag = 'healthcare='.$tags_converted['healthcare'];
|
||||
}
|
||||
$main_tag = 'healthcare=' . $tags_converted['healthcare'];
|
||||
}
|
||||
return $main_tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* mettre à jour le lieu selon les tags osm
|
||||
*/
|
||||
public function update_place_from_overpass_data(array $overpass_data) {
|
||||
public function update_place_from_overpass_data(array $overpass_data)
|
||||
{
|
||||
|
||||
if (!isset($overpass_data['tags']) || $overpass_data['tags'] == null) {
|
||||
return;
|
||||
|
@ -228,8 +232,8 @@ class Place
|
|||
// Setters for basic properties from top-level of overpass data
|
||||
$this->setOsmId($overpass_data['id'])
|
||||
->setOsmKind($overpass_data['type'])
|
||||
->setLat((float) ($overpass_data['lat'] ?? 0))
|
||||
->setLon((float) ($overpass_data['lon'] ?? 0));
|
||||
->setLat((float)($overpass_data['lat'] ?? 0))
|
||||
->setLon((float)($overpass_data['lon'] ?? 0));
|
||||
|
||||
// Setters for metadata
|
||||
if (isset($overpass_data['timestamp'])) {
|
||||
|
@ -254,7 +258,7 @@ class Place
|
|||
|
||||
// Guess main tag
|
||||
$main_tag = $this->guess_main_tag($tags);
|
||||
if ($main_tag) {
|
||||
if ($main_tag) {
|
||||
$this->setMainTag($main_tag);
|
||||
}
|
||||
|
||||
|
@ -283,8 +287,8 @@ class Place
|
|||
|
||||
// has address logic
|
||||
|
||||
$this->setHasAddress(!empty($this->getStreet()) && !empty($this->getHousenumber())
|
||||
| (isset($tags['addr:street']) && isset($tags['addr:housenumber'])) );
|
||||
$this->setHasAddress(!empty($this->getStreet()) && !empty($this->getHousenumber())
|
||||
| (isset($tags['addr:street']) && isset($tags['addr:housenumber'])));
|
||||
|
||||
// has website logic (with multiple possible tags)
|
||||
$websiteTags = ['website', 'contact:website', 'url', 'contact:url'];
|
||||
|
@ -319,6 +323,10 @@ class Place
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setUuidForUrl(uniqid())
|
||||
->setDead(false)
|
||||
->setAskedHumainsSupport(false)
|
||||
->setOptedOut(false);
|
||||
$this->histories = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
@ -755,7 +763,7 @@ class Place
|
|||
|
||||
/**
|
||||
* Helper method to truncate strings to a maximum length
|
||||
*
|
||||
*
|
||||
* @param string|null $string The string to truncate
|
||||
* @param int $maxLength The maximum length
|
||||
* @return string|null The truncated string or null if input was null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue