57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\NotConserved;
|
|
use App\Entity\Bibliography;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
class NotConservedController extends AbstractController
|
|
{
|
|
#[Route('/not_conserved', name: 'app_not_conserved')]
|
|
public function index(EntityManagerInterface $em): JsonResponse
|
|
{
|
|
$repo = $em->getRepository(NotConserved::class);
|
|
$repoBib = $em->getRepository(Bibliography::class);
|
|
|
|
$records = $repo->findAll();
|
|
|
|
// Terrible? N+1..
|
|
foreach ($records as $key => $record) {
|
|
$id = $record->getId();
|
|
$record->setLat($repo->coordinates($id)['lat']);
|
|
$record->setLng($repo->coordinates($id)['lng']);
|
|
$record->setBibliographies($repoBib->findAllByNotConserved($id));
|
|
$records[$key] = $record;
|
|
}
|
|
|
|
return $this->json([
|
|
'message' => 'All records for not conserved archaeological assets',
|
|
'records' => $records
|
|
],
|
|
);
|
|
}
|
|
|
|
#[Route('/not_conserved/{id<\d+>}', name: 'app_not_conserved_record')]
|
|
public function record(NotConserved $notConserved, EntityManagerInterface $em): JsonResponse
|
|
{
|
|
$repo = $em->getRepository(NotConserved::class);
|
|
$coordinates = $repo->coordinates($notConserved->getId());
|
|
$repo = $em->getRepository(Bibliography::class);
|
|
|
|
$biblio = $repo->findAllByNotConserved($notConserved->getId());
|
|
|
|
$notConserved->setBibliographies($biblio);
|
|
|
|
$notConserved->setLat($coordinates['lat']);
|
|
$notConserved->setLng($coordinates['lng']);
|
|
|
|
return $this->json(
|
|
$notConserved,
|
|
);
|
|
}
|
|
}
|