labourage avec davantage d'objets

This commit is contained in:
Tykayn 2025-06-03 11:37:27 +02:00 committed by tykayn
parent 2965841e81
commit a412cb977a
11 changed files with 197 additions and 81 deletions

View file

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250603085604 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE place ADD displayed_date TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE place DROP displayed_date
SQL);
}
}

View file

@ -244,11 +244,12 @@ final class AdminController extends AbstractController
$commerces = $this->entityManager->getRepository(Place::class)->findBy(['zip_code' => $zip_code]);
// var_dump($commerces[0]);
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $zip_code]);
return $this->render('admin/labourage_results.html.twig', [
'results' => $results,
'commerces' => $commerces,
'zone' => $zip_code,
'stats' => $stats,
]);
}

View file

@ -147,6 +147,10 @@ class PublicController extends AbstractController
// Trier les tags par ordre alphabétique des clés
ksort($commerce_overpass['tags_converted']);
$place->setDisplayedDate(new \DateTime());
$this->entityManager->persist($place);
$this->entityManager->flush();
return $this->render('public/edit.html.twig', [
'commerce_overpass' => $commerce_overpass,
@ -337,6 +341,7 @@ class PublicController extends AbstractController
$stats->addPlace($place);
$place->setStats($stats);
$place->setModifiedDate(new \DateTime());
$stats->computeCompletionPercent();
$this->entityManager->persist($stats);
@ -346,7 +351,7 @@ class PublicController extends AbstractController
return $this->render('public/view.html.twig', [
'controller_name' => 'PublicController',
'commerce' => $commerce,
'place' => $place,
'status' => $status,
'exception' => $exception,
'exception_message' => $exception_message,
@ -429,7 +434,7 @@ class PublicController extends AbstractController
public function latestChanges(): Response
{
// Récupérer les commerces modifiés, triés par date de modification décroissante
$places = $this->entityManager->getRepository(Place::class)
$places_modified = $this->entityManager->getRepository(Place::class)
->createQueryBuilder('p')
->where('p.modified_date IS NOT NULL')
->orderBy('p.modified_date', 'DESC')
@ -437,8 +442,18 @@ class PublicController extends AbstractController
->getQuery()
->getResult();
// Récupérer les commerces modifiés, triés par date de modification décroissante
$places_displayed = $this->entityManager->getRepository(Place::class)
->createQueryBuilder('p')
->where('p.displayed_date IS NOT NULL')
->orderBy('p.displayed_date', 'DESC')
->setMaxResults(20)
->getQuery()
->getResult();
return $this->render('public/latest_changes.html.twig', [
'places' => $places
'places_modified' => $places_modified,
'places_displayed' => $places_displayed
]);
}
}

View file

@ -82,6 +82,9 @@ class Place
#[ORM\Column(length: 255, nullable: true)]
private ?string $note_content = null;
#[ORM\Column(nullable: true)]
private ?\DateTime $displayed_date = null;
public function getMainTag(): ?string
{
return $this->main_tag;
@ -431,4 +434,16 @@ class Place
return $this;
}
public function getDisplayedDate(): ?\DateTime
{
return $this->displayed_date;
}
public function setDisplayedDate(?\DateTime $displayed_date): static
{
$this->displayed_date = $displayed_date;
return $this;
}
}

View file

@ -24,8 +24,8 @@ class Motocultrice
'opening_hours',
'contact:email',
'contact:phone',
'addr:housenumber',
'addr:street',
'contact:housenumber',
'contact:street',
'contact:website',
'contact:mastodon',
'image',
@ -122,10 +122,10 @@ class Motocultrice
// Nettoyer et échapper la zone pour la requête
$zone = addslashes(trim($zone));
// //area["postal_code"="{$zone}"]->.searchArea;
$query = <<<QUERY
[out:json][timeout:25];
area["postal_code"="{$zone}"]->.searchArea;
{{geocodeArea:{$zone}}}->.searchArea;
(
// Recherche des commerces et services avec email
nw["amenity"]["contact:email"][name](area.searchArea);
@ -147,13 +147,13 @@ QUERY;
if($use_places_without_email_to_reference) {
$query = <<<QUERY
[out:json][timeout:25];
area["postal_code"="{$zone}"]->.searchArea;
area(id:3610571698)->.searchArea;
(
nw["amenity"]["cafe|bar|restaurant|library|cinema|fast_food"](area.searchArea);
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall)$"](area.searchArea);
nw["healthcare"](area.searchArea);
nw["shop"](area.searchArea);
nw["tourism"="museum|hotel|chalet|apartment"](area.searchArea);
nw["tourism"~"^(museum|hotel|chalet|apartment)$"](area.searchArea);
nw["office"](area.searchArea);
);
out body;
@ -162,6 +162,8 @@ out skel qt;
QUERY;
}
$essai_query = "%5Bout%3Ajson%5D%5Btimeout%3A25%5D%3B%0A%0A(%0Aarea(id%3A3610571698)-%3E.searchArea%3B%0A++++nw%5B%22amenity%22~%22%5E(cafe%7Cbar%7Crestaurant%7Clibrary%7Ccinema%7Cfast_food%7Cpost_office%7Cmarketplace%7Ccommunity_centre%7Ctheatre%7Cbank%7Ctownhall)%24%22%5D(area.searchArea)%3B%0A++++nw%5B%22healthcare%22%5D(area.searchArea)%3B%0A++++nw%5B%22shop%22%5D(area.searchArea)%3B%0A++++nw%5B%22tourism%22~%22%5E(museum%7Chotel%7Cchalet%7Capartment)%24%22%5D(area.searchArea)%3B%0A++++nw%5B%22office%22%5D(area.searchArea)%3B%0A)%3B%0Aout+body%3B%0A%3E%3B%0Aout+center%3B";
try {
$response = $this->client->request('POST', $this->overpassApiUrl, [
'body' => ['data' => $query]
@ -177,12 +179,12 @@ QUERY;
$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'],
@ -199,7 +201,7 @@ QUERY;
return $places;
} catch (\Exception $e) {
var_dump($query);
var_dump($essai_query);
var_dump($e->getMessage());
die();
throw new \Exception("Erreur lors de la requête Overpass : " . $e->getMessage());
@ -285,6 +287,16 @@ QUERY;
$osm_object_data['contact:website'] = $osm_object_data['website'];
unset($osm_object_data['website']);
}
// migrer addr:housenumber vers contact:housenumber
if(isset($osm_object_data['addr:housenumber']) && !isset($osm_object_data['contact:housenumber'])){
$osm_object_data['contact:housenumber'] = $osm_object_data['addr:housenumber'];
unset($osm_object_data['addr:housenumber']);
}
// migrer addr:street vers contact:street
if(isset($osm_object_data['addr:street']) && !isset($osm_object_data['contact:street'])){
$osm_object_data['contact:street'] = $osm_object_data['addr:street'];
unset($osm_object_data['addr:street']);
}
return $osm_object_data;
}

View file

@ -1,6 +1,6 @@
{% extends 'base.html.twig' %}
{% block title %}Hello AdminController!{% endblock %}
{% block title %}Résultats du labourage sur la zone {{ zone }}{% endblock %}
{% block body %}
<style>
@ -24,17 +24,8 @@ commerces existants disposant d'un moyen de contact mail: {{ commerces|length }}
{# {{ dump(commerces[0]) }} #}
<table class="table table-striped">
<thead>
<tr>
<th>Nom</th>
<th>Adresse</th>
<th>Email</th>
<th>Site web</th>
<th>Horaires</th>
<th>Note</th>
<th>Actions</th>
</tr>
</thead>
{% include 'admin/stats/table-head.html.twig' %}
<tbody>
{% for commerce in commerces %}
<tr>

View file

@ -33,30 +33,10 @@
<div class="card mt-4">
<h1 class="card-title">Tableau des lieux</h1>
<table class="table table-bordered">
<thead>
<tr>
<th>Nom ({{ stats.getPlacesCount() }})</th>
<th>Type</th>
<th>Adresse ({{ stats.getAvecAdresse() }} / {{ stats.getPlacesCount() }})</th>
<th>Site web ({{ stats.getAvecSite() }} / {{ stats.getPlacesCount() }})</th>
<th>Accessibilité ({{ stats.getAvecAccessibilite() }} / {{ stats.getPlacesCount() }})</th>
<th>Note ({{ stats.getAvecNote() }} / {{ stats.getPlacesCount() }})</th>
<th>Note ({{ stats.getAvecNote() }} / {{ stats.getPlacesCount() }})</th>
</tr>
</thead>
{% include 'admin/stats/table-head.html.twig' %}
<tbody>
{% for commerce in stats.places %}
<tr>
<td style="background-color: {{ commerce.hasAddress() ? 'yellowgreen' : 'transparent' }};">
<a href="{{ path('app_admin_commerce', {'id': commerce.id}) }}">{{ commerce.name }}</a>
</td>
<td style="background-color: {{ commerce.mainTag ? 'yellowgreen' : 'transparent' }};">{{ commerce.mainTag }}</td>
<td style="background-color: {{ commerce.hasAddress() ? 'yellowgreen' : 'transparent' }};">{{ commerce.address }}</td>
<td style="background-color: {{ commerce.hasWebsite() ? 'yellowgreen' : 'transparent' }};">{{ commerce.website }}</td>
<td style="background-color: {{ commerce.hasWheelchair() ? 'yellowgreen' : 'transparent' }};">{{ commerce.wheelchair }}</td>
<td style="background-color: {{ commerce.hasNote() ? 'yellowgreen' : 'transparent' }};">{{ commerce.note }}</td>
<td style="background-color: {{ commerce.hasNote() ? 'yellowgreen' : 'transparent' }};">{{ commerce.noteContent }}</td>
</tr>
{% include 'admin/stats/row.html.twig' %}
{% endfor %}
</tbody>
</table>

View file

@ -0,0 +1,11 @@
<tr>
<td style="background-color: {{ commerce.hasAddress() ? 'yellowgreen' : 'transparent' }};">
<a href="{{ path('app_admin_commerce', {'id': commerce.id}) }}">{{ commerce.name }}</a>
</td>
<td style="background-color: {{ commerce.mainTag ? 'yellowgreen' : 'transparent' }};">{{ commerce.mainTag }}</td>
<td style="background-color: {{ commerce.hasAddress() ? 'yellowgreen' : 'transparent' }};">{{ commerce.address }}</td>
<td style="background-color: {{ commerce.hasWebsite() ? 'yellowgreen' : 'transparent' }};">{{ commerce.website }}</td>
<td style="background-color: {{ commerce.hasWheelchair() ? 'yellowgreen' : 'transparent' }};">{{ commerce.wheelchair }}</td>
<td style="background-color: {{ commerce.hasNote() ? 'yellowgreen' : 'transparent' }};">{{ commerce.note }}</td>
<td style="background-color: {{ commerce.hasNote() ? 'yellowgreen' : 'transparent' }};">{{ commerce.noteContent }}</td>
</tr>

View file

@ -0,0 +1,28 @@
<thead>
<tr>
<th>Nom ({{ stats.getPlacesCount() }})</th>
<th>
<i class="bi bi-tags"></i>
Type
</th>
<th>
<i class="bi bi-geo-alt"></i>
Adresse ({{ stats.getAvecAdresse() }} / {{ stats.getPlacesCount() }})</th>
<th>
<i class="bi bi-globe"></i>
Site web ({{ stats.getAvecSite() }} / {{ stats.getPlacesCount() }})</th>
<th>
<i class="bi bi-wheelchair"></i>
<i class="bi bi-person-fill-slash"></i>
Accès
PMR
({{ stats.getAvecAccessibilite() }} / {{ stats.getPlacesCount() }})</th>
<th>
<i class="bi bi-pencil-square"></i>
Note ? ({{ stats.getAvecNote() }} / {{ stats.getPlacesCount() }})</th>
<th>
<i class="bi bi-pencil-square"></i>
Texte de la note</th>
</tr>
</thead>

View file

@ -5,7 +5,10 @@
{% block body %}
<h1>Dernières modifications</h1>
<div class="row">
<div class="col-12 col-md-6 ">
<h2>Lieux modifiés</h2>
<table class="table table-striped table-hover table-responsive">
<thead>
<tr>
@ -21,35 +24,35 @@
</tr>
</thead>
<tbody>
{% for place in places %}
<tr>
<td>{% if place.name %}
<a href="{{ path('app_public_edit', {'zipcode': place.zipCode, 'name': place.name|url_encode, 'uuid': place.uuidForUrl}) }}">{{ place.name }}</a>
{% else %}
<a href="{{ path('app_public_edit', {'zipcode': place.zipCode, 'name': '?', 'uuid': place.uuidForUrl}) }}"><i class="bi bi-question-circle"></i></a>
{% endif %} </td>
<td>{{ place.mainTag }}</td>
<td>{{ place.email }}</td>
<td>{{ place.modifiedDate | date('Y-m-d H:i:s') }}</td>
<td>{{ place.lastContactAttemptDate | date('Y-m-d H:i:s') }}</td>
<td>{{ place.modifiedDate | date('Y-m-d H:i:s') }}</td>
<td>{{ place.zipCode }}</td>
<td>
<a href="https://www.openstreetmap.org/{{place.osmKind}}/{{ place.osmId }}" target="_blank"><i class="bi bi-globe"></i></a>
{% if place.name %}
<a href="{{ path('app_public_edit', {'zipcode': place.zipCode, 'name': place.name|url_encode, 'uuid': place.uuidForUrl}) }}"><i class="bi bi-pencil"></i></a>
{% else %}
<a href="{{ path('app_public_edit', {'zipcode': place.zipCode, 'name': '?', 'uuid': place.uuidForUrl}) }}"><i class="bi bi-pencil"></i></a>
{% endif %}
<a href="{{ path('app_admin_delete', {'id': place.id}) }}" onclick="return confirm('Êtes-vous sûr de vouloir supprimer ce lieu ?')"><i class="bi bi-trash"></i></a>
</td>
</tr>
{% for place in places_modified %}
{% include 'public/place/row.html.twig' %}
{% endfor %}
</tbody>
</table>
</div>
<div class="col-12 col-md-6 ">
<h2>Lieux affichés</h2>
<table class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Nom</th>
<th>Tag</th>
<th>Email</th>
<th>Date de dernière modification</th>
<th>Date de dernier contact</th>
<th>Date de dernière modification</th>
<th>Code postal</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for place in places_displayed %}
{% include 'public/place/row.html.twig' %}
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,25 @@
<tr>
<td>{% if place.name %}
<a href="{{ path('app_public_edit', {'zipcode': place.zipCode, 'name': place.name|url_encode, 'uuid': place.uuidForUrl}) }}">{{ place.name }}</a>
{% else %}
<a href="{{ path('app_public_edit', {'zipcode': place.zipCode, 'name': '?', 'uuid': place.uuidForUrl}) }}"><i class="bi bi-question-circle"></i></a>
{% endif %} </td>
<td>{{ place.mainTag }}</td>
<td>{{ place.email }}</td>
<td>{{ place.modifiedDate | date('Y-m-d H:i:s') }}</td>
<td>{{ place.lastContactAttemptDate | date('Y-m-d H:i:s') }}</td>
<td>{{ place.modifiedDate | date('Y-m-d H:i:s') }}</td>
<td>{{ place.zipCode }}</td>
<td>
<a href="https://www.openstreetmap.org/{{place.osmKind}}/{{ place.osmId }}" target="_blank"><i class="bi bi-globe"></i></a>
{% if place.name %}
<a href="{{ path('app_public_edit', {'zipcode': place.zipCode, 'name': place.name|url_encode, 'uuid': place.uuidForUrl}) }}"><i class="bi bi-pencil"></i></a>
{% else %}
<a href="{{ path('app_public_edit', {'zipcode': place.zipCode, 'name': '?', 'uuid': place.uuidForUrl}) }}"><i class="bi bi-pencil"></i></a>
{% endif %}
<a href="{{ path('app_admin_delete', {'id': place.id}) }}" onclick="return confirm('Êtes-vous sûr de vouloir supprimer ce lieu ?')"><i class="bi bi-trash"></i></a>
</td>
</tr>