Add Editions

This commit is contained in:
Kouril42 2023-02-02 18:54:28 +01:00
parent 0cb138d7d6
commit 626a3de5e4
3 changed files with 224 additions and 53 deletions

View File

@ -10,7 +10,7 @@ use App\Repository\RoomRepository;
class MapApiController extends AbstractController class MapApiController extends AbstractController
{ {
#[Route('/map/api')] #[Route('/map/api/test')]
public function test(SiteRepository $rep): JsonResponse public function test(SiteRepository $rep): JsonResponse
{ {
@ -38,98 +38,115 @@ class MapApiController extends AbstractController
return $jsonPlaces; return $jsonPlaces;
} }
#[Route('/map/api/find_room_by_name')] #[Route('/map/api/find_place_by_name')]
public function find_room_by_name(RoomRepository $rep, string $name): JsonResponse public function find_place_by_name(PlaceRepository $rep, string $name): JsonResponse
{ {
$rooms = $rep->findRoomByName($name); $places = $rep->findPlaceByName($name);
if (sizeof($rooms)!=1) { if (sizeof($places)!=1) {
return false; return false;
} }
else { else {
$room = $rooms[0]; $place = $places[0];
$CP = $room->getConnectedPlaces();
if (sizeof($CP)==0) return null;
$floor = $CP[0]->getFloor();
return $this->json([ return $this->json([
'idRoom' => $room->getId(), 'idRoom' => $place->getId(),
'idFloor' => $floor->getId() 'idFloor' => $place->getFloor()->getId()
]); ]);
} }
} }
#[Route('/map/api/show_room_info')] #[Route('/map/api/show_place_info')]
public function index(RoomRepository $rep, int $id): JsonResponse public function index(PlaceRepository $rep, int $id): JsonResponse
{ {
$rooms = $rep->findRoomById($id); $places = $rep->findPlaceById($id);
if (sizeof($rooms)!=1) { if (sizeof($places)!=1) {
return null; return null;
} }
else { else {
return $this->json([ return $this->json([
'idRoom' => $rooms[0]->getId(), 'idRoom' => $places[0]->getId(),
'names' => $rooms[0]->getName(), 'names' => $places[0]->getName(),
'users' => $rooms[0]->getUser() 'users' => $places[0]->getUser()
]); ]);
} }
} }
// #[Route('/map/api/get_all_propal_edit')] #[Route('/map/api/get_all_editions')]
// public function index(EditRepository $rep): JsonResponse public function getEditions(EditionRepository $rep): JsonResponse
// { {
// $edits = $rep->getAllEdit($id); $edits = $rep->getAllEditions();
// if (sizeof($rooms)<1) { if (sizeof($edits)<1) {
// return null; return null;
// } }
// else { else {
// $listEdits = [] $listEdits = new ArrayCollection();
// for i foreach ($edits as $edit){
// return $this->json([ $listEdits[] = $this->json([
// 'idRoom' => $rooms[0]->getId(), 'id' => $edit->getId(),
// 'names' => $rooms[0]->getName(), 'mode' => $edit->getMode(),
// 'users' => $rooms[0]->getUser() 'name' => $edit->getNamePlace(),
// ]); 'idPlace' => $edit->getIdPlace(),
// } 'value' => $edit->getValue()
// } ]);
}
}
return $listEdits;
}
#[Route('/map/api/del_room_name')] #[Route('/map/api/set_edition')]
public function delRoomName(RoomRepository $rep, int $id, string $value): bool public function setEdition(PlaceRepository $rep, string $mode, int $idPlace, string $value): bool
{ {
$rooms = $rep->findRoomById($id); $edit = new Edition();
if (sizeof($rooms)!=1) { return null; } 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 { else {
$rooms[0]->removeName($value); $places[0]->removeName($value);
return true; return true;
} }
} }
#[Route('/map/api/add_room_name')] #[Route('/map/api/add_place_name')]
public function addRoomName(RoomRepository $rep, int $id, string $value): bool public function addPlaceName(PlaceRepository $rep, int $id, string $value): bool
{ {
$rooms = $rep->findRoomById($id); $places = $rep->findPlaceById($id);
if (sizeof($rooms)!=1) { return null; } if (sizeof($places)!=1) { return null; }
else { else {
$rooms[0]->addName($value); $places[0]->addName($value);
return true; return true;
} }
} }
#[Route('/map/api/del_prof_room_name')] #[Route('/map/api/del_room_user_name')]
public function delProfRoomName(RoomRepository $rep, int $id, string $value): bool public function delRoomUserName(PlaceRepository $rep, int $id, string $value): bool
{ {
$rooms = $rep->findRoomById($id); $rooms = $rep->findPlaceById($id);
if (sizeof($rooms)!=1) { return null; } if (sizeof($rooms)!=1) { return null; }
else { else {
$rooms[0]->delUser($value); $rooms[0]->removeRoomUser($value);
return true; return true;
} }
} }
#[Route('/map/api/add_prof_room_name')] #[Route('/map/api/add_room_user_name')]
public function addProfRoomName(RoomRepository $rep, int $id, string $value): bool public function addRoomUserName(PlaceRepository $rep, int $id, string $value): bool
{ {
$rooms = $rep->findRoomById($id); $rooms = $rep->findPlaceById($id);
if (sizeof($rooms)!=1) { return null; } if (sizeof($rooms)!=1) { return null; }
else { else {
$rooms[0]->addUser($value); $rooms[0]->addRoomUser($value);
return true; return true;
} }
} }

90
src/Entity/Edition.php Normal file
View File

@ -0,0 +1,90 @@
<?php
namespace App\Entity;
use App\Repository\EditionRepository;
use App\Repository\PlaceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EditionRepository::class)]
class Edition
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer")]
private $id;
#[ORM\Id]
#[ORM\Column(type: "string")]
private $mode;
#[ORM\Id]
#[ORM\Column(type: "int")]
private $idPlace;
#[ORM\Id]
#[ORM\Column(type: "string")]
private $namePlace;
#[ORM\Id]
#[ORM\Column(type: "string")]
private $val;
public function getId(): ?int
{
return $this->id;
}
public function getMode(): ?string
{ return $this->mode; }
public function setMode(string $mode): self
{
$this->mode = $mode;
return $this;
}
public function getIdPlace(): ?int
{ return $this->idPlace; }
public function setIdPlace(int $id): self
{
$this->idPlace = $id;
return $this;
}
public function getNamePlace(): ?string
{ return $this->namePlace; }
public function setNamePlace(string $name): self
{
$this->NamePlace = $name;
return $this;
}
public function getValue(): ?string
{ return $this->val; }
public function setValue(string $val): self
{
$this->val = $val;
return $this;
}
public function setEdition(PlaceRepository $rep, string $mode, int $id, string $val): self
{
$place = $rep->findPlaceById($id);
if ($place==null) { return null; }
$names = $place->getName();
$name = '';
foreach ($names as $n) {
$name = $name + $n + ", " ;
}
$this->mode = $mode;
$this->idPlace = $id;
$this->namePlace = $name;
$this->val = $val;
return $this;
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace App\Repository;
use App\Entity\Edition;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Edition>
*
* @method Edition|null find($id, $lockMode = null, $lockVersion = null)
* @method Edition|null findOneBy(array $criteria, array $orderBy = null)
* @method Edition[] findAll()
* @method Edition[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class EditionRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Edition::class);
}
public function add(Edition $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Edition $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
/**
* @return Edition[] Returns an array of Edition objects
*/
public function getAllEditions(): array
{
return $this->createQueryBuilder('f')
->orderBy('f.id', 'ASC')
->getQuery()
->getResult()
;
}
public function findEditionById(int $id): ?Edition
{
return $this->createQueryBuilder('f')
->andWhere('f.id = :val')
->setParameter('val', $id)
->getQuery()
->getOneOrNullResult()
;
}
}