mirror of
https://gitlab.aliens-lyon.fr/encartes/backend.git
synced 2026-03-17 14:41:03 +01:00
220 lines
6.7 KiB
PHP
220 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use App\Repository\SiteRepository;
|
|
use App\Repository\BuildingRepository;
|
|
use App\Repository\FloorRepository;
|
|
use App\Entity\Building;
|
|
use App\Entity\Cylinder;
|
|
use App\Entity\Edition;
|
|
use App\Entity\Floor;
|
|
use App\Entity\Place;
|
|
use App\Entity\PlaceName;
|
|
use App\Entity\PlaneSurface;
|
|
use App\Entity\Point;
|
|
use App\Entity\Polyhedron;
|
|
use App\Entity\PolySurface;
|
|
use App\Entity\RoomUserName;
|
|
use App\Entity\Site;
|
|
use App\Entity\ThreeDObjectFile;
|
|
|
|
|
|
class JsonReaderController extends AbstractController
|
|
{
|
|
#[Route('/api/debug/loadJson')]
|
|
public function index(Request $request): Response
|
|
{
|
|
return new Response(print_r($request,true));
|
|
|
|
$response = new Response();
|
|
$response->setStatusCode(Response::HTTP_OK);
|
|
return $response;
|
|
}
|
|
|
|
#[Route('/api/debug/initialData')]
|
|
public function init(Request $request, SiteRepository $srep, BuildingRepository $brep, FloorRepository $frep, ManagerRegistry $mr): Response
|
|
{
|
|
//return new Response(print_r(json_decode($request->getContent()),true));
|
|
|
|
$monod = new Site();
|
|
$monod->setZeroLatitude(45.72980);
|
|
$monod->setZeroLongitude(4.82777);
|
|
$monod->setName('Monod');
|
|
$srep->add($monod);
|
|
|
|
$descartes = new Site();
|
|
$descartes->setZeroLatitude(45.73261);
|
|
$descartes->setZeroLongitude(4.83293);
|
|
$descartes->setName('Descartes');
|
|
$srep->add($descartes);
|
|
|
|
$mgn1 = new Building();
|
|
$mgn1->setSite($monod);
|
|
$mgn1->setName('MGN1');
|
|
$brep->add($mgn1);
|
|
|
|
$floornames = ['-1','RdC','1','1H','2','3','4'];
|
|
$floors = array();
|
|
for($i=0;$i<7;$i++){
|
|
$floor = new Floor();
|
|
$floor->setBuilding($mgn1);
|
|
$floor->setAltitude(0.45*$i);
|
|
$floor->setName($floornames[$i]);
|
|
$frep->add($floor);
|
|
$floors[$i] = $floor;
|
|
}
|
|
|
|
$data = json_decode($request->getContent(),true);
|
|
|
|
// Adding all the rooms
|
|
$rooms2Data = $data['rooms2'];
|
|
$cor2Data = $data['cor2'];
|
|
$rooms3Data = $data['rooms3'];
|
|
$cor3Data = $data['cor3'];
|
|
$rooms4Data = $data['rooms4'];
|
|
$cor4Data = $data['cor4'];
|
|
$rooms34Data = $data['bothRooms'];
|
|
$roomsXData = $data['allRooms'];
|
|
|
|
// We create the rooms
|
|
$rooms2 = [];
|
|
foreach($rooms2Data as $rData) {
|
|
$rooms2[] = JsonReaderController::addRoom($rData, "R", $mr);
|
|
}
|
|
$cor2 = JsonReaderController::addRoom($cor2Data, "C", $mr);
|
|
$rooms3 = [];
|
|
foreach($rooms3Data as $rData) {
|
|
$rooms3[] = JsonReaderController::addRoom($rData, "R", $mr);
|
|
}
|
|
$cor3 = JsonReaderController::addRoom($cor3Data, "C", $mr);
|
|
$rooms4 = [];
|
|
foreach($rooms4Data as $rData) {
|
|
$rooms4[] = JsonReaderController::addRoom($rData, "R", $mr);
|
|
}
|
|
$cor4 = JsonReaderController::addRoom($cor4Data, "C", $mr);
|
|
$rooms34 = [];
|
|
foreach($rooms34Data as $rData) {
|
|
$rooms34[] = JsonReaderController::addRoom($rData, "R", $mr);
|
|
}
|
|
$roomsX = [];
|
|
foreach($roomsXData as $rData) {
|
|
/* Determining between stairs and lift */
|
|
echo sizeof(json_decode($rData['points'],true)) . '<br/>';
|
|
if(sizeof(json_decode($rData['points'],true))<=5)
|
|
$letter = "E";
|
|
else
|
|
$letter = "S";
|
|
$roomsX[] = JsonReaderController::addRoom($rData, $letter, $mr);
|
|
}
|
|
|
|
|
|
// Connect all rooms
|
|
$floors[4]->addPlace($cor2);
|
|
foreach($rooms2 as $r){
|
|
$floors[4]->addPlace($r);
|
|
$cor2->addConnection($r);
|
|
}
|
|
$floors[5]->addPlace($cor3);
|
|
foreach($rooms3 as $r){
|
|
$floors[5]->addPlace($r);
|
|
$cor3->addConnection($r);
|
|
}
|
|
$floors[6]->addPlace($cor4);
|
|
foreach($rooms4 as $r){
|
|
$floors[6]->addPlace($r);
|
|
$cor4->addConnection($r);
|
|
}
|
|
foreach($rooms34 as $r){
|
|
$floors[5]->addPlace($r);
|
|
$floors[6]->addPlace($r);
|
|
$cor3->addConnection($r);
|
|
$cor4->addConnection($r);
|
|
}
|
|
foreach($roomsX as $r){
|
|
for($i=0;$i<7;$i++){
|
|
$floors[$i]->addPlace($r);
|
|
}
|
|
$cor2->addConnection($r);
|
|
$cor3->addConnection($r);
|
|
$cor4->addConnection($r);
|
|
}
|
|
|
|
$mr->getManager()->flush();
|
|
|
|
return new Response("All Done !");
|
|
|
|
}
|
|
|
|
#[Route('/api/debug/dropAllDatabaseThereIsNoWayIGotTheNameOfThisPageWrong')]
|
|
public function dropDatabase(EntityManagerInterface $em): Response
|
|
{
|
|
$entityClasses = array(
|
|
Building::class,
|
|
Cylinder::class,
|
|
Edition::class,
|
|
Floor::class,
|
|
Place::class,
|
|
PlaceName::class,
|
|
PlaneSurface::class,
|
|
Point::class,
|
|
Polyhedron::class,
|
|
PolySurface::class,
|
|
RoomUserName::class,
|
|
Site::class,
|
|
ThreeDObjectFile::class
|
|
);
|
|
foreach($entityClasses as $eclass){
|
|
$repository = $em->getRepository($eclass);
|
|
$entities = $repository->findAll();
|
|
|
|
foreach ($entities as $entity) {
|
|
$em->remove($entity);
|
|
}
|
|
}
|
|
$em->flush();
|
|
|
|
return new Response('', Response::HTTP_OK);
|
|
}
|
|
|
|
public function addRoom(array $room, string $roomType, ManagerRegistry $mr): Place {
|
|
|
|
$manager = $mr->getManager();
|
|
|
|
$height = (float) $room['height'];
|
|
$z = (float) $room['z'];
|
|
$name = $room['name'];
|
|
$points = json_decode($room['points'],true);
|
|
|
|
$r = new Place();
|
|
$r->setType($roomType);
|
|
$cyl = new Cylinder();
|
|
$cyl->setHeight($height);
|
|
$cbas = new PlaneSurface();
|
|
foreach($points as $px) {
|
|
$p = new Point();
|
|
$p->setX($px[0]);
|
|
$p->setY($px[1]);
|
|
$p->setZ($z);
|
|
$manager->persist($p);
|
|
$cbas->addPolygonpoint($p);
|
|
}
|
|
|
|
$manager->persist($cbas);
|
|
$cyl->setCylinderBase($cbas);
|
|
$manager->persist($cyl);
|
|
$r->addCylinderRepresentation($cyl);
|
|
$manager->persist($r);
|
|
|
|
return $r;
|
|
}
|
|
|
|
}
|
|
|