find_place_by_name returns a list of places with name NAME if many occurence of NAME are found

This commit is contained in:
Kouril42 2023-02-19 11:55:13 +01:00
parent 9f185ce8a2
commit a57adb9883

View File

@ -104,17 +104,16 @@ class MapApiController extends AbstractController
{ {
$places = $rep->findPlaceByName($name); $places = $rep->findPlaceByName($name);
if (sizeof($places)==0){ throw new NotFoundHttpException('Error: \''.$name.'\' doesn\'t correspond to any placeName.'); } 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 { else {
$place = $places[0]; $all = array();
$floorsId = array(); foreach ($places as $place){
foreach ($place->getFloors() as $floor) { $floorsId = array();
$floorsId[] = $floor->getId(); foreach ($place->getFloors() as $floor) {
$floorsId[] = $floor->getId();
}
$all[] = array('idRoom' => $place->getId(), 'idFloors' => $floorsId);
} }
return $this->json([ return $this->json($all);
'idRoom' => $place->getId(),
'idFloors' => $floorsId
]);
} }
} }