Add Document and Bibliography

This commit is contained in:
2024-11-18 09:43:17 +01:00
parent 54332fab42
commit 3f9b1faabf
8 changed files with 230 additions and 14 deletions

View File

@@ -3,6 +3,7 @@
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;
@@ -14,20 +15,44 @@ class NotConservedController extends AbstractController
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) {
$record->setLat($repo->coordinates($record->getId())['lat']);
$record->setLng($repo->coordinates($record->getId())['lng']);
$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
],
headers: ['Access-Control-Allow-Origin' => '*']
);
'message' => 'All records for not conserved archaeological assets',
'records' => $records
],
headers: ['Access-Control-Allow-Origin' => '*']
);
}
#[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,
headers: ['Access-Control-Allow-Origin' => '*']
);
}
}

View File

@@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\Site;
use App\Entity\Image;
use App\Entity\Document;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -29,8 +30,11 @@ class SiteController extends AbstractController
['sequence' => 'ASC']
)
);
$site->setImages($images);
$repo = $em->getRepository(Document::class);
$documents = $repo->findBySite($site->getId());
$site->setImages($images);
$site->setDocuments($documents);
$site->setLat((float) $coords['lat']);
$site->setLng((float) $coords['lng']);