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)