From 679adf5bb4dd0693f10cee3bbeca6cb91b444a3c Mon Sep 17 00:00:00 2001 From: Kouril42 Date: Tue, 28 Feb 2023 16:55:32 +0100 Subject: [PATCH] Add P,F,B,S names to find_place_by_name --- API.md | 13 +++++++++++-- src/Controller/MapApiController.php | 19 ++++++++----------- src/Entity/Place.php | 8 ++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/API.md b/API.md index 544a3eb..1c72ba7 100644 --- a/API.md +++ b/API.md @@ -99,9 +99,18 @@ __Format of the dict :__ [ { 'idPlace':int, //unique id of the place + 'namePlace':string[], //list of Names of the place 'idSite': int, //id of the place Site - 'idBuilding': int, //id of the place Building - 'idFloors': int[] //list of every floorID the place is in + 'nameSite' : string, //name of the Site + 'idBuilding': int, //id of the Building + 'nameBuilding': string, //name of the Building + 'floors': [ //list of every {floorID, floorName} the place is in + { + 'name': string, //name of the first floor of the building + 'id' : int //its id + }, + {...} + ] }, {...} ] diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index 81b8ae2..2aa5245 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -94,18 +94,12 @@ class MapApiController extends AbstractController $jsonPlaces = array(); if ($representation == 'Cylinder' || $representation == 'PolySurface'){ foreach ($places as $place){ - $connectedFloors = array(); - foreach ($place->getFloors() as $f) { - if ($f->getId() != $id) { - $connectedFloors[] = array('id' => $f->getId(), 'name' => $f->getName()); - } - } $jsonPlaces[] = array( 'id' => $place->getId(), 'names' => $place->getJoinedNames(), 'type' => $place->getType(), 'surface' => $place->getTwoDRepresentation($representation, $floor->getAltitude()), - 'connectedFloors' => $connectedFloors #$rep->getFloorsIdConnectedToPlaceID($place->getId()) // Will be added later + 'connectedFloors' => $place->getFloorsNameAndId() #$rep->getFloorsIdConnectedToPlaceID($place->getId()) // Will be added later ); } } @@ -147,16 +141,19 @@ class MapApiController extends AbstractController { $result = array(); foreach ($rep->findPlaceByName($name) as $place){ - $floorsId = array(); + $floors = array(); foreach ($place->getFloors() as $floor) { - $floorsId[] = $floor->getId(); + $floors[] = $floor->getId(); } $building = $place->getFloors()[0]->getBuilding(); $result[] = array( - 'idRoom' => $place->getId(), + 'idPlace' => $place->getId(), + 'namePlace' => $place->getJoinedNames(), 'idSite' => $building->getSite()->getId(), + 'nameSite' => $building->getSite()->getName(), 'idBuilding' => $building->getId(), - 'idFloors' => $floorsId + 'nameBuilding' => $building->getName(), + 'floors' => $place->getFloorsNameAndId() ); } return $this->json($result); diff --git a/src/Entity/Place.php b/src/Entity/Place.php index 8c817d8..0e26a93 100644 --- a/src/Entity/Place.php +++ b/src/Entity/Place.php @@ -165,6 +165,14 @@ class Place } return $response; } + public function getFloorsNameAndId(): array + { + $response = array(); + foreach ($this->floors as $f) { + $response[] = array('id' => $f->getId(), 'name' => $f->getName()); + } + return $response; + } public function addFloor(Floor $floor): self {