mirror of
https://gitlab.aliens-lyon.fr/encartes/backend.git
synced 2026-03-17 22:51:04 +01:00
Add Editions
This commit is contained in:
parent
0cb138d7d6
commit
626a3de5e4
@ -10,7 +10,7 @@ use App\Repository\RoomRepository;
|
||||
|
||||
class MapApiController extends AbstractController
|
||||
{
|
||||
#[Route('/map/api')]
|
||||
#[Route('/map/api/test')]
|
||||
public function test(SiteRepository $rep): JsonResponse
|
||||
{
|
||||
|
||||
@ -38,98 +38,115 @@ class MapApiController extends AbstractController
|
||||
return $jsonPlaces;
|
||||
}
|
||||
|
||||
#[Route('/map/api/find_room_by_name')]
|
||||
public function find_room_by_name(RoomRepository $rep, string $name): JsonResponse
|
||||
#[Route('/map/api/find_place_by_name')]
|
||||
public function find_place_by_name(PlaceRepository $rep, string $name): JsonResponse
|
||||
{
|
||||
$rooms = $rep->findRoomByName($name);
|
||||
if (sizeof($rooms)!=1) {
|
||||
$places = $rep->findPlaceByName($name);
|
||||
if (sizeof($places)!=1) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
$room = $rooms[0];
|
||||
$CP = $room->getConnectedPlaces();
|
||||
if (sizeof($CP)==0) return null;
|
||||
$floor = $CP[0]->getFloor();
|
||||
$place = $places[0];
|
||||
return $this->json([
|
||||
'idRoom' => $room->getId(),
|
||||
'idFloor' => $floor->getId()
|
||||
'idRoom' => $place->getId(),
|
||||
'idFloor' => $place->getFloor()->getId()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[Route('/map/api/show_room_info')]
|
||||
public function index(RoomRepository $rep, int $id): JsonResponse
|
||||
#[Route('/map/api/show_place_info')]
|
||||
public function index(PlaceRepository $rep, int $id): JsonResponse
|
||||
{
|
||||
$rooms = $rep->findRoomById($id);
|
||||
if (sizeof($rooms)!=1) {
|
||||
$places = $rep->findPlaceById($id);
|
||||
if (sizeof($places)!=1) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return $this->json([
|
||||
'idRoom' => $rooms[0]->getId(),
|
||||
'names' => $rooms[0]->getName(),
|
||||
'users' => $rooms[0]->getUser()
|
||||
'idRoom' => $places[0]->getId(),
|
||||
'names' => $places[0]->getName(),
|
||||
'users' => $places[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/get_all_editions')]
|
||||
public function getEditions(EditionRepository $rep): JsonResponse
|
||||
{
|
||||
$edits = $rep->getAllEditions();
|
||||
if (sizeof($edits)<1) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
$listEdits = new ArrayCollection();
|
||||
foreach ($edits as $edit){
|
||||
$listEdits[] = $this->json([
|
||||
'id' => $edit->getId(),
|
||||
'mode' => $edit->getMode(),
|
||||
'name' => $edit->getNamePlace(),
|
||||
'idPlace' => $edit->getIdPlace(),
|
||||
'value' => $edit->getValue()
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
return $listEdits;
|
||||
}
|
||||
|
||||
#[Route('/map/api/set_edition')]
|
||||
public function setEdition(PlaceRepository $rep, string $mode, int $idPlace, string $value): bool
|
||||
{
|
||||
$edit = new Edition();
|
||||
return $edit->setEdition($rep, $mode, $idPlace, $value);
|
||||
}
|
||||
|
||||
#[Route('/map/api/del_room_name')]
|
||||
public function delRoomName(RoomRepository $rep, int $id, string $value): bool
|
||||
#[Route('/map/api/remove_edition')]
|
||||
public function removeEdition(EditionRepository $rep, int $id): bool
|
||||
{
|
||||
$rooms = $rep->findRoomById($id);
|
||||
if (sizeof($rooms)!=1) { return null; }
|
||||
$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 {
|
||||
$rooms[0]->removeName($value);
|
||||
$places[0]->removeName($value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#[Route('/map/api/add_room_name')]
|
||||
public function addRoomName(RoomRepository $rep, int $id, string $value): bool
|
||||
#[Route('/map/api/add_place_name')]
|
||||
public function addPlaceName(PlaceRepository $rep, int $id, string $value): bool
|
||||
{
|
||||
$rooms = $rep->findRoomById($id);
|
||||
if (sizeof($rooms)!=1) { return null; }
|
||||
$places = $rep->findPlaceById($id);
|
||||
if (sizeof($places)!=1) { return null; }
|
||||
else {
|
||||
$rooms[0]->addName($value);
|
||||
$places[0]->addName($value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#[Route('/map/api/del_prof_room_name')]
|
||||
public function delProfRoomName(RoomRepository $rep, int $id, string $value): bool
|
||||
#[Route('/map/api/del_room_user_name')]
|
||||
public function delRoomUserName(PlaceRepository $rep, int $id, string $value): bool
|
||||
{
|
||||
$rooms = $rep->findRoomById($id);
|
||||
$rooms = $rep->findPlaceById($id);
|
||||
if (sizeof($rooms)!=1) { return null; }
|
||||
else {
|
||||
$rooms[0]->delUser($value);
|
||||
$rooms[0]->removeRoomUser($value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#[Route('/map/api/add_prof_room_name')]
|
||||
public function addProfRoomName(RoomRepository $rep, int $id, string $value): bool
|
||||
#[Route('/map/api/add_room_user_name')]
|
||||
public function addRoomUserName(PlaceRepository $rep, int $id, string $value): bool
|
||||
{
|
||||
$rooms = $rep->findRoomById($id);
|
||||
$rooms = $rep->findPlaceById($id);
|
||||
if (sizeof($rooms)!=1) { return null; }
|
||||
else {
|
||||
$rooms[0]->addUser($value);
|
||||
$rooms[0]->addRoomUser($value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
90
src/Entity/Edition.php
Normal file
90
src/Entity/Edition.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
64
src/Repository/EditionRepository.php
Normal file
64
src/Repository/EditionRepository.php
Normal 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()
|
||||
;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user