Merge branch 'main' of gitlab.aliens-lyon.fr:encartes/backend

This commit is contained in:
Kouril42
2023-02-11 20:14:27 +01:00
9 changed files with 439 additions and 20 deletions
+205
View File
@@ -0,0 +1,205 @@
<?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);
$srep->add($monod);
$descartes = new Site();
$descartes->setZeroLatitude(45.73261);
$descartes->setZeroLongitude(4.83293);
$srep->add($descartes);
$mgn1 = new Building();
$mgn1->setSite($monod);
$brep->add($mgn1);
$floors = array();
for($i=0;$i<7;$i++){
$floor = new Floor();
$floor->setBuilding($mgn1);
$floor->setAltitude(0.45*$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) {
$roomsX[] = JsonReaderController::addRoom($rData, "R", $mr);
}
// Connect all rooms
foreach($rooms2 as $r){
$floors[4]->addPlace($r);
$cor2->addConnection($r);
}
foreach($rooms3 as $r){
$floors[5]->addPlace($r);
$cor3->addConnection($r);
}
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;
}
}
+3 -6
View File
@@ -16,19 +16,16 @@ class Edition
#[ORM\Column(type: "integer")]
private $id;
#[ORM\Id]
#[ORM\Column(type: "string")]
private $mode;
#[ORM\Id]
#[ORM\Column(type: "int")]
private $idPlace;
#[ORM\OneToMany(targetEntity: Place::class, mappedBy: "editions")]
private $editedPlace;
#[ORM\Id]
#[ORM\Column(type: "string")]
private $namePlace;
#[ORM\Id]
#[ORM\Column(type: "string")]
private $val;
+2 -3
View File
@@ -15,7 +15,6 @@ class Floor
#[ORM\Column(type: "integer")]
private $id;
#[ORM\Id]
#[ORM\Column(type: "integer")]
private $altitude;
@@ -70,7 +69,7 @@ class Floor
{
if (!$this->places->contains($place)) {
$this->places[] = $place;
$place->setFloor($this);
$place->addFloor($this);
}
return $this;
}
@@ -80,7 +79,7 @@ class Floor
if ($this->places->removeElement($place)) {
// set the owning side to null (unless already changed)
if ($place->getFloor() === $this) {
$place->setFloor(null);
$place->addFloor(null);
}
}
+10 -9
View File
@@ -19,7 +19,6 @@ class Place
#[ORM\Column(type: "integer")]
private $id;
#[ORM\Type]
#[ORM\Column(type: "string")]
// Either 'C'orridor , 'S'tairs , 'E'levator or 'R'oom
private $type;
@@ -46,6 +45,8 @@ class Place
#[ORM\OneToMany(targetEntity: PolySurface::class, mappedBy: "place")]
private $PolySurfaceRepresentation;
#[ORM\ManyToOne(targetEntity: Edition::class, inversedBy: "editedPlace")]
private $editions;
public function __construct()
{
@@ -130,7 +131,7 @@ class Place
return $this->floors;
}
public function addFloor(self $floor): self
public function addFloor(Floor $floor): self
{
if (!$this->floors->contains($floor)) {
$this->floors[] = $floor;
@@ -138,7 +139,7 @@ class Place
return $this;
}
public function removeFloor(self $floor): self
public function removeFloor(Floor $floor): self
{
$this->floors->removeElement($floor);
return $this;
@@ -262,7 +263,7 @@ class Place
{
if (!$this->CylinderRepresentation->contains($cylinderRepresentation)) {
$this->CylinderRepresentation[] = $cylinderRepresentation;
$cylinderRepresentation->setRoom($this);
$cylinderRepresentation->setPlace($this);
}
return $this;
@@ -272,8 +273,8 @@ class Place
{
if ($this->CylinderRepresentation->removeElement($cylinderRepresentation)) {
// set the owning side to null (unless already changed)
if ($cylinderRepresentation->getRoom() === $this) {
$cylinderRepresentation->setRoom(null);
if ($cylinderRepresentation->getPlace() === $this) {
$cylinderRepresentation->setPlace(null);
}
}
@@ -293,7 +294,7 @@ class Place
{
if (!$this->PolySurfaceRepresentation->contains($polySurfaceRepresentation)) {
$this->PolySurfaceRepresentation[] = $polySurfaceRepresentation;
$polySurfaceRepresentation->setRoom($this);
$polySurfaceRepresentation->setPlace($this);
}
return $this;
@@ -303,8 +304,8 @@ class Place
{
if ($this->PolySurfaceRepresentation->removeElement($polySurfaceRepresentation)) {
// set the owning side to null (unless already changed)
if ($polySurfaceRepresentation->getRoom() === $this) {
$polySurfaceRepresentation->setRoom(null);
if ($polySurfaceRepresentation->getPlace() === $this) {
$polySurfaceRepresentation->setPlace(null);
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
namespace App\Entity;
use App\Repository\PolyhedronRepository;
use App\Repository\PlaceNameRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -2,11 +2,12 @@
namespace App\Entity;
use App\Repository\RoomUserNameRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RoomUserRepository::class)]
#[ORM\Entity(repositoryClass: RoomUserNameRepository::class)]
class RoomUserName
{
#[ORM\Id]
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace App\Repository;
use App\Entity\PlaceName;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<PlaceName>
*/
class PlaceNameRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, PlaceName::class);
}
public function add(PlaceName $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(PlaceName $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
/**
* @return PlaceName[] Returns an array of PlaceName objects
*/
public function findPlaceNameById(int $id): array
{
return $this->createQueryBuilder('p')
->andWhere('p.id = :val')
->setParameter('val', $id)
->orderBy('p.id', 'ASC')
->getQuery()
->getResult()
;
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace App\Repository;
use App\Entity\RoomUserName;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<RoomUserName>
*/
class RoomUserNameRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, RoomUserName::class);
}
public function add(RoomUserName $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(RoomUserName $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
/**
* @return RoomUserName[] Returns an array of RoomUserName objects
*/
public function findPlaceNameById(int $id): array
{
return $this->createQueryBuilder('p')
->andWhere('p.id = :val')
->setParameter('val', $id)
->orderBy('p.id', 'ASC')
->getQuery()
->getResult()
;
}
}