From a57adb9883cf2b6626d785fde585a09d49c4d011 Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Sun, 19 Feb 2023 11:55:13 +0100 Subject: [PATCH] find_place_by_name returns a list of places with name NAME if many occurence of NAME are found --- src/Controller/MapApiController.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index bd91729..e97f79b 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -104,17 +104,16 @@ class MapApiController extends AbstractController { $places = $rep->findPlaceByName($name); if (sizeof($places)==0){ throw new NotFoundHttpException('Error: \''.$name.'\' doesn\'t correspond to any placeName.'); } - elseif (sizeof($places)>1) { throw new UnprocessableEntityHttpException('Error: \''.$name.'\' refers to more than one place ; the API can\'t decide which one should be provided.'); } else { - $place = $places[0]; - $floorsId = array(); - foreach ($place->getFloors() as $floor) { - $floorsId[] = $floor->getId(); + $all = array(); + foreach ($places as $place){ + $floorsId = array(); + foreach ($place->getFloors() as $floor) { + $floorsId[] = $floor->getId(); + } + $all[] = array('idRoom' => $place->getId(), 'idFloors' => $floorsId); } - return $this->json([ - 'idRoom' => $place->getId(), - 'idFloors' => $floorsId - ]); + return $this->json($all); } }