mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-11-19 23:00:36 +01:00
ajout thème rnb
This commit is contained in:
parent
3d767ffaae
commit
aae37c6ce0
9 changed files with 119 additions and 26 deletions
70
src/Command/UpdateCityFollowupCommand.php
Normal file
70
src/Command/UpdateCityFollowupCommand.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Stats;
|
||||
use App\Service\Motocultrice;
|
||||
use App\Service\FollowUpService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:update-city-followup',
|
||||
description: 'Met à jour les CityFollowUp d\'une ville à partir de son code INSEE'
|
||||
)]
|
||||
class UpdateCityFollowupCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private Motocultrice $motocultrice,
|
||||
private FollowUpService $followUpService
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addArgument('ville', InputArgument::REQUIRED, 'Code INSEE ou nom de la ville à mettre à jour');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$inputVille = $input->getArgument('ville');
|
||||
$stats = null;
|
||||
if (ctype_digit($inputVille)) {
|
||||
// Recherche par code INSEE
|
||||
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $inputVille]);
|
||||
if (!$stats) {
|
||||
$io->error("Aucune stats trouvée pour le code INSEE $inputVille.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
} else {
|
||||
// Recherche par nom (insensible à la casse)
|
||||
$qb = $this->entityManager->getRepository(Stats::class)->createQueryBuilder('s');
|
||||
$qb->where('LOWER(s.name) = :name')
|
||||
->setParameter('name', mb_strtolower($inputVille));
|
||||
$results = $qb->getQuery()->getResult();
|
||||
if (count($results) === 0) {
|
||||
$io->error("Aucune ville trouvée avec le nom '$inputVille'.");
|
||||
return Command::FAILURE;
|
||||
} elseif (count($results) > 1) {
|
||||
$io->error("Plusieurs villes trouvées pour le nom '$inputVille'. Veuillez préciser le code INSEE.");
|
||||
foreach ($results as $stat) {
|
||||
$io->text("- " . $stat->getName() . " (" . $stat->getZone() . ")");
|
||||
}
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$stats = $results[0];
|
||||
}
|
||||
$this->followUpService->generateCityFollowUps($stats, $this->motocultrice, $this->entityManager);
|
||||
$io->success("Les CityFollowUp de la ville " . $stats->getName() . " (" . $stats->getZone() . ") ont été mis à jour.");
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue