simplification des followup
This commit is contained in:
parent
949dc71fb8
commit
0a20be186a
1 changed files with 33 additions and 0 deletions
|
@ -215,6 +215,39 @@ class FollowUpService
|
|||
}
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
|
||||
// Suppression des mesures redondantes (même valeur consécutive, sauf la dernière)
|
||||
$repo = $em->getRepository(CityFollowUp::class);
|
||||
foreach (array_keys(self::getFollowUpThemes()) as $type) {
|
||||
foreach (['_count', '_completion'] as $suffix) {
|
||||
$name = $type . $suffix;
|
||||
$followups = $repo->createQueryBuilder('f')
|
||||
->where('f.stats = :stats')
|
||||
->andWhere('f.name = :name')
|
||||
->setParameter('stats', $stats)
|
||||
->setParameter('name', $name)
|
||||
->orderBy('f.date', 'ASC')
|
||||
->getQuery()->getResult();
|
||||
$toDelete = [];
|
||||
$prev = null;
|
||||
$n = count($followups);
|
||||
foreach ($followups as $i => $fu) {
|
||||
// Si seulement 2 mesures, ne rien supprimer
|
||||
if ($n == 2) {
|
||||
break;
|
||||
}
|
||||
if ($prev && $fu->getMeasure() === $prev->getMeasure() && $i < $n - 1) {
|
||||
$toDelete[] = $prev;
|
||||
}
|
||||
$prev = $fu;
|
||||
}
|
||||
foreach ($toDelete as $del) {
|
||||
$em->remove($del);
|
||||
}
|
||||
}
|
||||
}
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
|
||||
public function generateGlobalFollowUps(EntityManagerInterface $em): void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue