mirror of
https://gitlab.aliens-lyon.fr/encartes/backend.git
synced 2026-03-17 22:51:04 +01:00
155 lines
4.7 KiB
PHP
155 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use App\Repository\SiteRepository;
|
|
use App\Repository\RoomRepository;
|
|
|
|
class MapApiController extends AbstractController
|
|
{
|
|
#[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' => $rep->allSites()[0]->getZeroLatitude()
|
|
]);
|
|
}
|
|
|
|
#[Route('/map/api/get_floor')]
|
|
public function get_floor(FloorRepository $rep, int $id, string $representation): JsonResponse
|
|
{
|
|
$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_place_by_name')]
|
|
public function find_place_by_name(PlaceRepository $rep, string $name): JsonResponse
|
|
{
|
|
$places = $rep->findPlaceByName($name);
|
|
if (sizeof($places)!=1) {
|
|
return false;
|
|
}
|
|
else {
|
|
$place = $places[0];
|
|
return $this->json([
|
|
'idRoom' => $place->getId(),
|
|
'idFloor' => $place->getFloor()->getId()
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
#[Route('/map/api/show_place_info')]
|
|
public function index(PlaceRepository $rep, int $id): JsonResponse
|
|
{
|
|
$places = $rep->findPlaceById($id);
|
|
if (sizeof($places)!=1) {
|
|
return null;
|
|
}
|
|
else {
|
|
return $this->json([
|
|
'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;
|
|
}
|
|
}
|
|
|
|
}
|