Prehistoric biblio

This commit is contained in:
2026-05-22 16:12:09 +02:00
parent a98554d775
commit e0869c3869
3 changed files with 57 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ namespace App\Controller;
use App\Entity\Image; use App\Entity\Image;
use App\Entity\Prehistoric; use App\Entity\Prehistoric;
//use App\Entity\Bibliography; use App\Entity\Bibliography;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
@@ -48,10 +48,10 @@ class PrehistoricController extends AbstractController
{ {
$repo = $em->getRepository(Prehistoric::class); $repo = $em->getRepository(Prehistoric::class);
$coordinates = $repo->coordinates($prehistoric->getId()); $coordinates = $repo->coordinates($prehistoric->getId());
//$repo = $em->getRepository(Bibliography::class); $repo = $em->getRepository(Bibliography::class);
//$biblio = $repo->findAllByNotConserved($prehistoric->getId()); $biblio = $repo->findAllByPrehistoric($prehistoric->getId());
//$notConserved->setBibliographies($biblio); $prehistoric->setBibliography($biblio);
$prehistoric->setLat($coordinates['lat']); $prehistoric->setLat($coordinates['lat']);
$prehistoric->setLng($coordinates['lng']); $prehistoric->setLng($coordinates['lng']);

View File

@@ -48,6 +48,11 @@ class Prehistoric implements \JsonSerializable
*/ */
private ?array $images = null; private ?array $images = null;
/**
* @var Bibliography[] $bibliography
*/
private ?array $bibliography = null;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@@ -198,6 +203,18 @@ class Prehistoric implements \JsonSerializable
return $this; return $this;
} }
public function getBibliography(): ?array
{
return $this->bibliography;
}
public function setBibliography(array $bibliography): static
{
$this->bibliography = $bibliography;
return $this;
}
public function jsonSerialize(): array public function jsonSerialize(): array
{ {
return [ return [
@@ -211,6 +228,7 @@ class Prehistoric implements \JsonSerializable
'label' => $this->label, 'label' => $this->label,
'municipality' => $this->municipality, 'municipality' => $this->municipality,
'coordinates' => [$this->lat, $this->lng], 'coordinates' => [$this->lat, $this->lng],
'bibliography' => $this->bibliography,
'images' => $this->images, 'images' => $this->images,
]; ];
} }

View File

@@ -155,6 +155,41 @@ class BibliographyRepository extends ServiceEntityRepository
$entities[] = $biblio; $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; return $entities;
} }
} }