mirror of
https://gitlab.aliens-lyon.fr/encartes/backend.git
synced 2026-09-11 16:50:46 +02:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -10,64 +10,145 @@ use App\Repository\RoomRepository;
|
||||
|
||||
class MapApiController extends AbstractController
|
||||
{
|
||||
#[Route('/map/api')]
|
||||
public function test(SiteRepository $srep): JsonResponse
|
||||
#[Route('/map/api/test')]
|
||||
public function test(SiteRepository $rep): JsonResponse
|
||||
{
|
||||
|
||||
return $this->json([
|
||||
'message' => 'Welcome to your new controller!',
|
||||
'path' => 'src/Controller/MapApiController.php',
|
||||
'sites' => $srep->allSites()[0]->getZeroLatitude()
|
||||
'sites' => $rep->allSites()[0]->getZeroLatitude()
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/map/api/get_floor')]
|
||||
public function get_floor(FloorRepository $srep, int $id): JsonResponse
|
||||
public function get_floor(FloorRepository $rep, int $id, string $representation): JsonResponse
|
||||
{
|
||||
return $rep->get_floor(id);
|
||||
return $this->json([
|
||||
'message' => 'Welcome to your new controller!',
|
||||
'path' => 'src/Controller/MapApiController.php',
|
||||
'sites' => $srep->allSites()[0]->getZeroLatitude()
|
||||
]);
|
||||
$floor = $rep->findFloorById($id);
|
||||
$places = $floor->getPlace();
|
||||
$jsonPlaces = new ArrayCollection();
|
||||
foreach ($places as $place){
|
||||
$jsonPlaces[] = $this->json([
|
||||
'id' => $place->getId(),
|
||||
'name' => $place->getName(),
|
||||
'type' => $place->getType(),
|
||||
'surface' => $place->getTwoDRepresentation($representation, $floor->getAltitude())
|
||||
]);
|
||||
}
|
||||
return $jsonPlaces;
|
||||
}
|
||||
|
||||
#[Route('/map/api/find_room_by_name')]
|
||||
public function find_room_by_name(RoomRepository $srep, string $name): JsonResponse
|
||||
#[Route('/map/api/find_place_by_name')]
|
||||
public function find_place_by_name(PlaceRepository $rep, string $name): JsonResponse
|
||||
{
|
||||
$rooms = $rep->findRoomByName($name);
|
||||
if (sizeof($rooms)!=1) {
|
||||
$places = $rep->findPlaceByName($name);
|
||||
if (sizeof($places)!=1) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
$room = $rooms[0];
|
||||
$CP = $room->getConnectedPlaces();
|
||||
if (sizeof($CP)==0) return null;
|
||||
$floor = $CP[0]->getFloor();
|
||||
$place = $places[0];
|
||||
return $this->json([
|
||||
'idRoom' => $room->getId(),
|
||||
'idFloor' => $floor->getId()
|
||||
'idRoom' => $place->getId(),
|
||||
'idFloor' => $place->getFloor()->getId()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[Route('/map/api/show_room_info')]
|
||||
public function index(RoomRepository $srep, int $id): JsonResponse
|
||||
#[Route('/map/api/show_place_info')]
|
||||
public function index(PlaceRepository $rep, int $id): JsonResponse
|
||||
{
|
||||
$rooms = $rep->findRoomById($id);
|
||||
if (sizeof($rooms)!=1) {
|
||||
$places = $rep->findPlaceById($id);
|
||||
if (sizeof($places)!=1) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return $this->json([
|
||||
'idRoom' => $rooms[0]->getId(),
|
||||
'names' => $rooms[0]->getNames(),
|
||||
'users' => $rooms[0]->getUsers()
|
||||
'idRoom' => $places[0]->getId(),
|
||||
'names' => $places[0]->getName(),
|
||||
'users' => $places[0]->getUser()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
#[Route('/map/api/get_all_editions')]
|
||||
public function getEditions(EditionRepository $rep): JsonResponse
|
||||
{
|
||||
$edits = $rep->getAllEditions();
|
||||
if (sizeof($edits)<1) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
$listEdits = new ArrayCollection();
|
||||
foreach ($edits as $edit){
|
||||
$listEdits[] = $this->json([
|
||||
'id' => $edit->getId(),
|
||||
'mode' => $edit->getMode(),
|
||||
'name' => $edit->getNamePlace(),
|
||||
'idPlace' => $edit->getIdPlace(),
|
||||
'value' => $edit->getValue()
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
return $listEdits;
|
||||
}
|
||||
|
||||
#[Route('/map/api/set_edition')]
|
||||
public function setEdition(PlaceRepository $rep, string $mode, int $idPlace, string $value): bool
|
||||
{
|
||||
$edit = new Edition();
|
||||
return $edit->setEdition($rep, $mode, $idPlace, $value);
|
||||
}
|
||||
|
||||
#[Route('/map/api/remove_edition')]
|
||||
public function removeEdition(EditionRepository $rep, int $id): bool
|
||||
{
|
||||
$edit = $rep->findEditionById($id);
|
||||
if ($edit == null) {return false;}
|
||||
$rep->remove($edit);
|
||||
return true;
|
||||
}
|
||||
|
||||
#[Route('/map/api/del_place_name')]
|
||||
public function delPlaceName(PlaceRepository $rep, int $id, string $value): bool
|
||||
{
|
||||
$places = $rep->findPlaceById($id);
|
||||
if (sizeof($places)!=1) { return null; }
|
||||
else {
|
||||
$places[0]->removeName($value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#[Route('/map/api/add_place_name')]
|
||||
public function addPlaceName(PlaceRepository $rep, int $id, string $value): bool
|
||||
{
|
||||
$places = $rep->findPlaceById($id);
|
||||
if (sizeof($places)!=1) { return null; }
|
||||
else {
|
||||
$places[0]->addName($value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#[Route('/map/api/del_room_user_name')]
|
||||
public function delRoomUserName(PlaceRepository $rep, int $id, string $value): bool
|
||||
{
|
||||
$rooms = $rep->findPlaceById($id);
|
||||
if (sizeof($rooms)!=1) { return null; }
|
||||
else {
|
||||
$rooms[0]->removeRoomUser($value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#[Route('/map/api/add_room_user_name')]
|
||||
public function addRoomUserName(PlaceRepository $rep, int $id, string $value): bool
|
||||
{
|
||||
$rooms = $rep->findPlaceById($id);
|
||||
if (sizeof($rooms)!=1) { return null; }
|
||||
else {
|
||||
$rooms[0]->addRoomUser($value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user