Skip to content

Commit

Permalink
nettoyage
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi81 committed Jan 23, 2025
1 parent 3709721 commit 4657f37
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions src/Service/Aid/AidService.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,38 +985,6 @@ public function getAidStatsSpreadSheetOfBacker(
);
}

public function getAidsFromResults(array $results): array
{
/** @var AidRepository $aidRepository */
$aidRepository = $this->managerRegistry->getRepository(Aid::class);

$ids = array_column($results, 'id');
// Nettoyer les IDs en préservant l'ordre
$ids = array_values(array_filter($ids, fn ($id) => !empty($id)));
$scores = array_combine(
array_column($results, 'id'),
array_column($results, 'score_total')
);

if (empty($ids)) {
return [];
}

$qb = $aidRepository->createQueryBuilder('a')
->andWhere('a.id IN (:ids)')
->orderBy(sprintf('FIELD(a.id, %s)', implode(',', $ids))) // Maintient l'ordre original des IDs
->setParameter('ids', $ids);

$aids = $qb->getQuery()->getResult();

// Restauration des scores
foreach ($aids as $aid) {
$aid->setScoreTotal($scores[$aid->getId()] ?? null);
}

return $aids;
}

/**
* Fonction de recherche des aides.
* On recupère uniquement les ids et le score total qui seront mis en cache.
Expand Down Expand Up @@ -1073,10 +1041,12 @@ public function hydrateLightAids(array $lightAids, array $aidParams): array
// récupère les aides
$aids = $aidRepository->findCompleteAidsByIds($ids);

// on remet les scores

foreach ($aids as $key => $aid) {
// on remet les scores
$aids[$key]->setScoreTotal($scoreTotalById[$aid->getId()]);

// on met en highlight les projets référents recherchés
if (isset($aidParams['projectReference']) && $aidParams['projectReference'] instanceof ProjectReference) {
foreach ($aid->getProjectReferences() as $projectReference) {
if ($projectReference->getId() == $aidParams['projectReference']->getId()) {
Expand Down

0 comments on commit 4657f37

Please sign in to comment.