Add Prehistoric stuff...

This commit is contained in:
2025-01-10 11:33:03 +01:00
parent faee735af8
commit dc06764e36
3 changed files with 273 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Controller;
use App\Entity\Prehistoric;
//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 PrehistoricController extends AbstractController
{
#[Route('/prehistoric', name: 'app_prehistoric')]
public function index(EntityManagerInterface $em): JsonResponse
{
$repo = $em->getRepository(Prehistoric::class);
//$repoBib = $em->getRepository(Bibliography::class);
$records = $repo->findBy([], ['id' => 'ASC']);
// Terrible? N+1..
foreach ($records as $key => $record) {
$id = $record->getId();
$record->setLat($repo->coordinates($id)['lat']);
$record->setLng($repo->coordinates($id)['lng']);
$records[$key] = $record;
}
return $this->json([
'message' => 'All records for prehistoric assets',
'records' => $records
],
);
}
#[Route('/prehistoric/{id<\d+>}', name: 'app_prehistoric_record')]
public function record(Prehistoric $prehistoric, EntityManagerInterface $em): JsonResponse
{
$repo = $em->getRepository(Prehistoric::class);
$coordinates = $repo->coordinates($prehistoric->getId());
//$repo = $em->getRepository(Bibliography::class);
//$biblio = $repo->findAllByNotConserved($prehistoric->getId());
//$notConserved->setBibliographies($biblio);
$prehistoric->setLat($coordinates['lat']);
$prehistoric->setLng($coordinates['lng']);
return $this->json($prehistoric);
}
}