Sauvegarde avant le carnage

This commit is contained in:
Kouril42 2023-02-01 16:47:28 +01:00
parent 9b5b36c5eb
commit ce2c643cc6
5 changed files with 205 additions and 13 deletions

View File

@ -11,29 +11,44 @@ use App\Repository\RoomRepository;
class MapApiController extends AbstractController
{
#[Route('/map/api')]
public function test(SiteRepository $srep): JsonResponse
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): 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);
$corridors = $floor->getCorridors();
$rooms = array();
foreach ($corridors as $cor){
foreach ($cor->getConnectedPlaces() as $place) {
if (($place instanceof Room) and !($rooms->contains($place))) {
$rooms[] = $place;
}
}
}
$jsonCorridors = array();
$jsonRooms = array();
foreach ($corridors as $cor){
$jsonCorridors[] = $this->json([
'id' => $cor->getId(),
'name' => $cor->getName(),
'type' => $cor->getType()
//'polygon' => $cor->getPolyhedronRepresentation()
]);
}
return array($jsonCorridors, $jsonRooms);
}
#[Route('/map/api/find_room_by_name')]
public function find_room_by_name(RoomRepository $srep, string $name): JsonResponse
public function find_room_by_name(RoomRepository $rep, string $name): JsonResponse
{
$rooms = $rep->findRoomByName($name);
if (sizeof($rooms)!=1) {
@ -53,7 +68,7 @@ class MapApiController extends AbstractController
#[Route('/map/api/show_room_info')]
public function index(RoomRepository $srep, int $id): JsonResponse
public function index(RoomRepository $rep, int $id): JsonResponse
{
$rooms = $rep->findRoomById($id);
if (sizeof($rooms)!=1) {
@ -62,12 +77,70 @@ class MapApiController extends AbstractController
else {
return $this->json([
'idRoom' => $rooms[0]->getId(),
'names' => $rooms[0]->getNames(),
'users' => $rooms[0]->getUsers()
'names' => $rooms[0]->getName(),
'users' => $rooms[0]->getUser()
]);
}
}
// #[Route('/map/api/get_all_propal_edit')]
// public function index(EditRepository $rep): JsonResponse
// {
// $edits = $rep->getAllEdit($id);
// if (sizeof($rooms)<1) {
// return null;
// }
// else {
// $listEdits = []
// for i
// return $this->json([
// 'idRoom' => $rooms[0]->getId(),
// 'names' => $rooms[0]->getName(),
// 'users' => $rooms[0]->getUser()
// ]);
// }
// }
#[Route('/map/api/del_room_name')]
public function delRoomName(RoomRepository $rep, int $id, string $value): bool
{
$rooms = $rep->findRoomById($id);
if (sizeof($rooms)!=1) { return null; }
else {
$rooms[0]->removeName($value);
return true;
}
}
#[Route('/map/api/add_room_name')]
public function addRoomName(RoomRepository $rep, int $id, string $value): bool
{
$rooms = $rep->findRoomById($id);
if (sizeof($rooms)!=1) { return null; }
else {
$rooms[0]->addName($value);
return true;
}
}
#[Route('/map/api/del_prof_room_name')]
public function delProfRoomName(RoomRepository $rep, int $id, string $value): bool
{
$rooms = $rep->findRoomById($id);
if (sizeof($rooms)!=1) { return null; }
else {
$rooms[0]->delUser($value);
return true;
}
}
#[Route('/map/api/add_prof_room_name')]
public function addProfRoomName(RoomRepository $rep, int $id, string $value): bool
{
$rooms = $rep->findRoomById($id);
if (sizeof($rooms)!=1) { return null; }
else {
$rooms[0]->addUser($value);
return true;
}
}
}

View File

@ -5,6 +5,7 @@ namespace App\Entity;
use App\Repository\CorridorRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CorridorRepository::class)]
class Corridor extends Place
{
@ -13,6 +14,10 @@ class Corridor extends Place
#[ORM\Column(type: "integer")]
private $id;
#[ORM\Type]
#[ORM\Column(type: "string")]
private $type;
#[ORM\ManyToOne(targetEntity: Floor::class, inversedBy: "corridors")]
#[ORM\JoinColumn(nullable: false)]
private $floor;
@ -22,6 +27,16 @@ class Corridor extends Place
return $this->id;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getFloor(): ?Floor
{
return $this->floor;

View File

@ -39,6 +39,29 @@ class Place
return $this->id;
}
/**
* @return Collection<int, self>
*/
public function getName(): Collection
{
return $this->names;
}
public function addName(self $name): self
{
if (!$this->names->contains($name)) {
$this->names[] = $name;
}
return $this;
}
public function removeName(self $name): self
{
$this->names->removeElement($name);
return $this;
}
/**
* @return Collection<int, self>
*/

View File

@ -15,6 +15,9 @@ class Room extends Place
#[ORM\Column(type: "integer")]
private $id;
#[ORM\OneToMany(targetEntity: RoomUsersName::class, mappedBy: "room")]
private $users;
#[ORM\OneToMany(targetEntity: ThreeDObjectFile::class, mappedBy: "room")]
private $ComplexRepresentation;
@ -37,6 +40,31 @@ class Room extends Place
return $this->id;
}
/**
* @return Collection<int, self>
*/
public function getUser(): Collection
{
return $this->users;
}
public function addUser(self $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
}
return $this;
}
public function removeUser(self $user): self
{
$this->users->removeElement($user);
return $this;
}
/**
* @return Collection<int, ThreeDObjectFile>
*/

View File

@ -0,0 +1,53 @@
<?php
namespace App\Entity;
use App\Repository\PolyhedronRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RoomRepository::class)]
class RoomUsersName
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer")]
private $id;
#[ORM\Column(type: "string")]
private $usersName;
#[ORM\ManyToOne(targetEntity: Room::class, inversedBy: "id")]
private $room;
public function getId(): ?int
{
return $this->id;
}
public function getRoom(): ?Room
{
return $this->room;
}
public function setRoom(?Room $room): self
{
$this->room = $room;
return $this;
}
public function getUsersName(): ?string
{
return $this->usersName;
}
public function setUsersName(?string $name): self
{
$this->usersName = $name;
return $this;
}
}