From b84d4589fee916d6c36d435b7175410677b9f9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Mon, 28 Apr 2025 15:55:07 +0200 Subject: [PATCH] Documents for not conserved --- src/Controller/NotConservedController.php | 16 +++++++++---- src/Entity/NotConserved.php | 18 +++++++++++++++ src/Repository/DocumentRepository.php | 28 +++++++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/Controller/NotConservedController.php b/src/Controller/NotConservedController.php index 592531f..9db20f1 100644 --- a/src/Controller/NotConservedController.php +++ b/src/Controller/NotConservedController.php @@ -4,6 +4,7 @@ namespace App\Controller; use App\Entity\NotConserved; use App\Entity\Bibliography; +use App\Entity\Document; use App\Entity\Image; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -17,6 +18,7 @@ class NotConservedController extends AbstractController { $repo = $em->getRepository(NotConserved::class); //$repoBib = $em->getRepository(Bibliography::class); + $repoImg = $em->getRepository(Image::class); $records = $repo->findBy([], ['id' => 'ASC']); @@ -27,6 +29,12 @@ class NotConservedController extends AbstractController $record->setLng($repo->coordinates($id)['lng']); //$biblio = $repoBib->findAllByNotConserved($id); //$record->setBibliographies($biblio); + $images = $repoImg->findBy( + ['notConserved' => $record->getId()], + ['sequence' => 'ASC'] + ); + + $record->setImages($images); $records[$key] = $record; } @@ -45,8 +53,10 @@ class NotConservedController extends AbstractController $repo = $em->getRepository(Bibliography::class); $biblio = $repo->findAllByNotConserved($notConserved->getId()); - + $repo = $em->getRepository(Document::class); + $documents = $repo->findByNotConserved($notConserved->getId()); $notConserved->setBibliographies($biblio); + $notConserved->setDocuments($documents); $notConserved->setLat($coordinates['lat']); $notConserved->setLng($coordinates['lng']); @@ -58,8 +68,6 @@ class NotConservedController extends AbstractController $notConserved->setImages($images); - return $this->json( - $notConserved, - ); + return $this->json($notConserved); } } diff --git a/src/Entity/NotConserved.php b/src/Entity/NotConserved.php index 5ea0663..730ebe0 100644 --- a/src/Entity/NotConserved.php +++ b/src/Entity/NotConserved.php @@ -28,6 +28,11 @@ class NotConserved implements \JsonSerializable */ private ?array $bibliographies = null; + /** + * @var Document[] $documents + */ + private ?array $documents = null; + #[ORM\Column(length: 255, nullable: true, name: 'periodo')] private ?string $period = null; @@ -105,6 +110,18 @@ class NotConserved implements \JsonSerializable return $this; } + public function getDocuments(): ?array + { + return $this->documents; + } + + public function setDocuments(array $documents): static + { + $this->documents = $documents; + + return $this; + } + public function getPeriod(): ?string { return $this->period; @@ -182,6 +199,7 @@ class NotConserved implements \JsonSerializable 'shortDescription' => $this->shortDescription, 'author' => $this->author, 'bibliography' => $this->bibliographies, + 'documents' => $this->documents, 'images' => $this->images, ]; } diff --git a/src/Repository/DocumentRepository.php b/src/Repository/DocumentRepository.php index e4c83bf..8a86209 100644 --- a/src/Repository/DocumentRepository.php +++ b/src/Repository/DocumentRepository.php @@ -46,6 +46,34 @@ class DocumentRepository extends ServiceEntityRepository return $query->getResult(); } + /** + * @return Document[] Returns an array of Document objects + */ + public function findByNotConserved(int $notConservedId): array + { + $rsm = new ResultSetMappingBuilder($this->getEntityManager()); + $rsm->addRootEntityFromClassMetadata('App\Entity\Document', 'd'); + $query = $this->getEntityManager()->createNativeQuery( + 'SELECT + id, + titolo, + filename, + descrizione, + autori, + luogo, + tipo + FROM documento d + JOIN non_conserv_documento + ON id_documento = d.id + WHERE id_non_conserv = :id + ', + $rsm + ); + + $query->setParameter('id', $notConservedId); + + return $query->getResult(); + } // /** // * @return Document[] Returns an array of Document objects // */