mirror of
https://gitlab.aliens-lyon.fr/encartes/backend.git
synced 2026-03-17 14:41:03 +01:00
Ajout des scripts pour mettre les données dans la BDD, correction des attributs Doctrine (certains, pas tous)
This commit is contained in:
parent
29cda25a69
commit
23acce12ef
@ -7,19 +7,31 @@ 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\Entity\Room;
|
||||
use App\Repository\BuildingRepository;
|
||||
use App\Repository\FloorRepository;
|
||||
use App\Entity\Building;
|
||||
use App\Entity\Cylinder;
|
||||
use App\Entity\Point;
|
||||
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(SiteRepository $srep): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
|
||||
return new Response(print_r($request,true));
|
||||
|
||||
$response = new Response();
|
||||
$response->setStatusCode(Response::HTTP_OK);
|
||||
@ -27,28 +39,147 @@ class JsonReaderController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/api/debug/initialData')]
|
||||
public function init(SiteRepository $srep, BuildingRepository $brep, FloorRepository $frep): Response
|
||||
public function init(Request $request, SiteRepository $srep, BuildingRepository $brep, FloorRepository $frep, ManagerRegistry $mr): Response
|
||||
{
|
||||
$s = new Site();
|
||||
$p->setX();
|
||||
$p->setY();
|
||||
$p->setZ();
|
||||
$prep->add($p);
|
||||
//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/newRoom')]
|
||||
public function addRoom(Request $request, ManagerRegistry $mr): Response {
|
||||
#[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();
|
||||
|
||||
//return new Response(print_r($request->request->all()));
|
||||
|
||||
$height = $request->request->get('height');
|
||||
$z = $request->request->get('z');
|
||||
$name = $request->request->get('name');
|
||||
$points = json_decode($request->request->get('points'));
|
||||
$height = (float) $room['height'];
|
||||
$z = (float) $room['z'];
|
||||
$name = $room['name'];
|
||||
$points = json_decode($room['points'],true);
|
||||
|
||||
$r = new Room();
|
||||
$r = new Place();
|
||||
$r->setType($roomType);
|
||||
$cyl = new Cylinder();
|
||||
$cyl->setHeight($height);
|
||||
$cbas = new PlaneSurface();
|
||||
@ -66,66 +197,8 @@ class JsonReaderController extends AbstractController
|
||||
$manager->persist($cyl);
|
||||
$r->addCylinderRepresentation($cyl);
|
||||
$manager->persist($r);
|
||||
$manager->flush();
|
||||
|
||||
return new Response($r->getId());
|
||||
}
|
||||
|
||||
#[Route('/api/debug/newCorridor')]
|
||||
public function addCorridor(Request $request, ManagerRegistry $mr, FloorRepository $frep): Response {
|
||||
|
||||
$manager = $mr->getManager();
|
||||
|
||||
//return new Response(print_r($request->request->all()));
|
||||
|
||||
$z = $request->request->get('z');
|
||||
$name = $request->request->get('name');
|
||||
$floorid = $request->request->get('floorid');
|
||||
//$points = json_decode($request->request->get('points'));
|
||||
|
||||
$f = $manager->getRepository(Floor::class)->find($floorid);
|
||||
$c = new Corridor();
|
||||
/*$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);*/
|
||||
$f->addCorridor($c);
|
||||
$manager->persist($c);
|
||||
$manager->flush();
|
||||
|
||||
return new Response($c->getId());
|
||||
}
|
||||
|
||||
#[Route('/api/debug/connect')]
|
||||
public function connect(Request $request, ManagerRegistry $mr, PlaceRepository $prep): Response {
|
||||
|
||||
$manager = $mr->getManager();
|
||||
|
||||
//return new Response(print_r($request->request->all()));
|
||||
|
||||
$aid = $request->request->get('a');
|
||||
$bid = $request->request->get('b');
|
||||
|
||||
$a = $prep->find($aid);
|
||||
$b = $prep->find($bid);
|
||||
|
||||
$a->addConnection($b);
|
||||
|
||||
$manager->flush();
|
||||
|
||||
return new Response("OK");
|
||||
return $r;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ class Floor
|
||||
{
|
||||
if (!$this->places->contains($place)) {
|
||||
$this->places[] = $place;
|
||||
$place->setFloor($this);
|
||||
$place->addFloor($this);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
@ -79,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
@ -132,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;
|
||||
@ -140,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;
|
||||
@ -264,7 +263,7 @@ class Place
|
||||
{
|
||||
if (!$this->CylinderRepresentation->contains($cylinderRepresentation)) {
|
||||
$this->CylinderRepresentation[] = $cylinderRepresentation;
|
||||
$cylinderRepresentation->setRoom($this);
|
||||
$cylinderRepresentation->setPlace($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -274,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,7 +294,7 @@ class Place
|
||||
{
|
||||
if (!$this->PolySurfaceRepresentation->contains($polySurfaceRepresentation)) {
|
||||
$this->PolySurfaceRepresentation[] = $polySurfaceRepresentation;
|
||||
$polySurfaceRepresentation->setRoom($this);
|
||||
$polySurfaceRepresentation->setPlace($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -305,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
src/Repository/PlaceNameRepository.php
Normal file
49
src/Repository/PlaceNameRepository.php
Normal 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
src/Repository/RoomUserNameRepository.php
Normal file
49
src/Repository/RoomUserNameRepository.php
Normal 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()
|
||||
;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user