Merge remote-tracking branch 'origin/main'

This commit is contained in:
Mysaa 2023-02-01 12:05:47 +01:00
commit 2f5d10b723
Signed by: Mysaa
GPG Key ID: 7054D5D6A90F084F
3 changed files with 93 additions and 30 deletions

View File

@ -6,11 +6,12 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\SiteRepository;
use App\Repository\RoomRepository;
class MapApiController extends AbstractController
{
#[Route('/map/api')]
public function index(SiteRepository $srep): JsonResponse
public function test(SiteRepository $srep): JsonResponse
{
return $this->json([
@ -19,4 +20,54 @@ class MapApiController extends AbstractController
'sites' => $srep->allSites()[0]->getZeroLatitude()
]);
}
#[Route('/map/api/get_floor')]
public function get_floor(FloorRepository $srep, 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()
]);
}
#[Route('/map/api/find_room_by_name')]
public function find_room_by_name(RoomRepository $srep, string $name): JsonResponse
{
$rooms = $rep->findRoomByName($name);
if (sizeof($rooms)!=1) {
return false;
}
else {
$room = $rooms[0];
$CP = $room->getConnectedPlaces();
if (sizeof($CP)==0) return null;
$floor = $CP[0]->getFloor();
return $this->json([
'idRoom' => $room->getId(),
'idFloor' => $floor->getId()
]);
}
}
#[Route('/map/api/show_room_info')]
public function index(RoomRepository $srep, int $id): JsonResponse
{
$rooms = $rep->findRoomById($id);
if (sizeof($rooms)!=1) {
return null;
}
else {
return $this->json([
'idRoom' => $rooms[0]->getId(),
'names' => $rooms[0]->getNames(),
'users' => $rooms[0]->getUsers()
]);
}
}
}

View File

@ -39,20 +39,21 @@ class PlaceRepository extends ServiceEntityRepository
}
}
// /**
// * @return Place[] Returns an array of Place objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
/**
* @return Place[] Returns an array of Place objects having connection with Corrido
*/
public function findPlaceConnectedTo($value): array
{
return $this->createQueryBuilder('p')
->andWhere('p.connectedPlace = :val')
->setParameter('val', $value)
->orderBy('p.id', 'ASC')
->getQuery()
->getResult()
;
}
// public function findOneBySomeField($value): ?Place
// {

View File

@ -39,21 +39,32 @@ class RoomRepository extends ServiceEntityRepository
}
}
// /**
// * @return Room[] Returns an array of Room objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('r')
// ->andWhere('r.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('r.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
/**
* @return Room[] Returns an array of Room objects
*/
public function findRoomByName(string $name): array
{
return $this->createQueryBuilder('r')
->andWhere('r.name.lower() = :val')
->setParameter('val', $name.lower())
->orderBy('r.id', 'ASC')
->getQuery()
->getResult()
;
}
/**
* @return Room[] Returns an array of Room objects
*/
public function findRoomById(int $id): array
{
return $this->createQueryBuilder('r')
->andWhere('r.id = :val')
->setParameter('val', $id)
->orderBy('r.id', 'ASC')
->getQuery()
->getResult()
;
}
// public function findOneBySomeField($value): ?Room
// {
// return $this->createQueryBuilder('r')