From 8ed2e7585d4e191d8f3a2ba992b180c0540d8a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 7 May 2021 19:22:47 +0200 Subject: [PATCH] fix random thid party --- src/Bundle/ChillMainBundle/Search/SearchApi.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Search/SearchApi.php b/src/Bundle/ChillMainBundle/Search/SearchApi.php index 0c7c7b561..518edd31b 100644 --- a/src/Bundle/ChillMainBundle/Search/SearchApi.php +++ b/src/Bundle/ChillMainBundle/Search/SearchApi.php @@ -53,15 +53,19 @@ class SearchApi { $thirdPartiesIds = $this->em->createQuery('SELECT t.id FROM '.ThirdParty::class.' t') ->getScalarResult(); - $nbResults = rand(0, 15); + if ($nbResults === 1) { $nbResults++; + } elseif ($nbResults === 0) { + return []; } - $ids = \array_rand($thirdPartiesIds, $nbResults); + $ids = \array_map(function ($e) use ($thirdPartiesIds) { return $thirdPartiesIds[$e]['id'];}, + \array_rand($thirdPartiesIds, $nbResults)); - return $this->em->getRepository(ThirdParty::class) + $a = $this->em->getRepository(ThirdParty::class) ->findById($ids); + return $a; } private function getPersons(string $query)