Add Prehistoric stuff...
This commit is contained in:
53
src/Controller/PrehistoricController.php
Normal file
53
src/Controller/PrehistoricController.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user