From e0869c3869cf29c1b2a7148f375056f19bf616b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Fri, 22 May 2026 16:12:09 +0200 Subject: [PATCH] Prehistoric biblio --- src/Controller/PrehistoricController.php | 8 +++--- src/Entity/Prehistoric.php | 18 ++++++++++++ src/Repository/BibliographyRepository.php | 35 +++++++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/Controller/PrehistoricController.php b/src/Controller/PrehistoricController.php index 3f6727e..1730094 100644 --- a/src/Controller/PrehistoricController.php +++ b/src/Controller/PrehistoricController.php @@ -4,7 +4,7 @@ namespace App\Controller; use App\Entity\Image; use App\Entity\Prehistoric; -//use App\Entity\Bibliography; +use App\Entity\Bibliography; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -48,10 +48,10 @@ class PrehistoricController extends AbstractController { $repo = $em->getRepository(Prehistoric::class); $coordinates = $repo->coordinates($prehistoric->getId()); - //$repo = $em->getRepository(Bibliography::class); + $repo = $em->getRepository(Bibliography::class); - //$biblio = $repo->findAllByNotConserved($prehistoric->getId()); - //$notConserved->setBibliographies($biblio); + $biblio = $repo->findAllByPrehistoric($prehistoric->getId()); + $prehistoric->setBibliography($biblio); $prehistoric->setLat($coordinates['lat']); $prehistoric->setLng($coordinates['lng']); diff --git a/src/Entity/Prehistoric.php b/src/Entity/Prehistoric.php index 3645660..5a9fb49 100644 --- a/src/Entity/Prehistoric.php +++ b/src/Entity/Prehistoric.php @@ -48,6 +48,11 @@ class Prehistoric implements \JsonSerializable */ private ?array $images = null; + /** + * @var Bibliography[] $bibliography + */ + private ?array $bibliography = null; + public function getId(): ?int { return $this->id; @@ -198,6 +203,18 @@ class Prehistoric implements \JsonSerializable return $this; } + public function getBibliography(): ?array + { + return $this->bibliography; + } + + public function setBibliography(array $bibliography): static + { + $this->bibliography = $bibliography; + + return $this; + } + public function jsonSerialize(): array { return [ @@ -211,6 +228,7 @@ class Prehistoric implements \JsonSerializable 'label' => $this->label, 'municipality' => $this->municipality, 'coordinates' => [$this->lat, $this->lng], + 'bibliography' => $this->bibliography, 'images' => $this->images, ]; } diff --git a/src/Repository/BibliographyRepository.php b/src/Repository/BibliographyRepository.php index 2c62e74..ff3fab1 100644 --- a/src/Repository/BibliographyRepository.php +++ b/src/Repository/BibliographyRepository.php @@ -155,6 +155,41 @@ class BibliographyRepository extends ServiceEntityRepository $entities[] = $biblio; } + return $entities; + } + /** + * @return Bibliography[] + */ + public function findAllByPrehistoric(int $prehistoricId): array + { + $conn = $this->getEntityManager()->getConnection(); + + $sql = ' + SELECT + b.id, + b.citazione, + b.riferimento, + br.pagine + FROM bibliografia b + INNER JOIN bibliografia_preistoria br ON br.id_bibliografia = b.id + WHERE br.id_preistoria = :prehistoricId + ORDER BY br.ordine ASC + '; + + $stmt = $conn->prepare($sql); + $results = $stmt->executeQuery(['prehistoricId' => $prehistoricId])->fetchAllAssociative(); + + $entities = []; + + foreach ($results as $row) { + $biblio = new Bibliography(); + $biblio->setId($row['id']); + $biblio->setCitation($row['citazione']); + $biblio->setReference($row['riferimento']); + $biblio->setPages($row['pagine']); + $entities[] = $biblio; + } + return $entities; } }