up command and labourage

This commit is contained in:
Tykayn 2025-08-08 18:51:44 +02:00 committed by tykayn
parent 8cfea30fdf
commit a81112a018
5 changed files with 279 additions and 86 deletions

View file

@ -96,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);
}
@ -112,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);
@ -272,8 +272,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(),
@ -329,8 +329,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)");
@ -1060,22 +1060,61 @@ class PublicController extends AbstractController
}
/**
* Calculate marker color based on completion percentage
* Returns a gradient from intense green (high completion) to gray (low completion) with 10 intermediate shades
*/
private function calculateMarkerColor(float $completionPercent): string
{
// Define the colors for the gradient
$greenColor = [0, 170, 0]; // Intense green RGB
$grayColor = [128, 128, 128]; // Gray RGB
// Ensure completion percent is between 0 and 100
$completionPercent = max(0, min(100, $completionPercent));
// Calculate the position in the gradient (0 to 1)
$position = $completionPercent / 100;
// Calculate the RGB values for the gradient
$r = intval($grayColor[0] + ($greenColor[0] - $grayColor[0]) * $position);
$g = intval($grayColor[1] + ($greenColor[1] - $grayColor[1]) * $position);
$b = intval($grayColor[2] + ($greenColor[2] - $grayColor[2]) * $position);
// Convert RGB to hexadecimal
return sprintf('#%02x%02x%02x', $r, $g, $b);
}
#[Route('/cities', name: 'app_public_cities')]
public function cities(): Response
{
$stats = $this->entityManager->getRepository(Stats::class)->findAll();
// Only select Stats that have an empty kind or 'user' kind
$stats = $this->entityManager->getRepository(Stats::class)
->createQueryBuilder('s')
->where('s.kind IS NULL OR s.kind = :user_kind')
->setParameter('user_kind', 'user')
->orderBy('s.name', 'ASC')
->getQuery()
->getResult();
// Prepare data for the map
$citiesForMap = [];
foreach ($stats as $stat) {
if ($stat->getZone() !== 'undefined' && preg_match('/^\d+$/', $stat->getZone())) {
// Calculate marker color based on completion percentage
// Gradient from intense green (high completion) to gray (low completion) with 10 intermediate shades
$completionPercent = $stat->getCompletionPercent();
// Ensure we have a float value even if getCompletionPercent returns null
$markerColor = $this->calculateMarkerColor($completionPercent ?? 0);
$citiesForMap[] = [
'name' => $stat->getName(),
'zone' => $stat->getZone(),
'lat' => $stat->getLat(),
'lon' => $stat->getLon(),
'placesCount' => $stat->getPlacesCount(),
'completionPercent' => $stat->getCompletionPercent(),
'completionPercent' => $completionPercent,
'markerColor' => $markerColor,
];
}
}