diff --git a/src/Controller/PrehistoricController.php b/src/Controller/PrehistoricController.php index f72a2fe..25fb1cb 100644 --- a/src/Controller/PrehistoricController.php +++ b/src/Controller/PrehistoricController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use App\Entity\Image; use App\Entity\Prehistoric; //use App\Entity\Bibliography; use Doctrine\ORM\EntityManagerInterface; @@ -24,6 +25,14 @@ class PrehistoricController extends AbstractController $id = $record->getId(); $record->setLat($repo->coordinates($id)['lat']); $record->setLng($repo->coordinates($id)['lng']); + $repoImg = $em->getRepository(Image::class); + + $images = $repoImg->findBy( + ['prehistoric' => $record->getId()], + ['sequence' => 'ASC'] + ); + + $record->setImages($images); $records[$key] = $record; } @@ -46,6 +55,14 @@ class PrehistoricController extends AbstractController $prehistoric->setLat($coordinates['lat']); $prehistoric->setLng($coordinates['lng']); + $repo = $em->getRepository(Image::class); + + $images = $repo->findBy( + ['prehistoric' => $prehistoric->getId()], + ['sequence' => 'ASC'] + ); + + $prehistoric->setImages($images); return $this->json($prehistoric); } diff --git a/src/Entity/Image.php b/src/Entity/Image.php index 38a42f0..c8a8508 100644 --- a/src/Entity/Image.php +++ b/src/Entity/Image.php @@ -34,6 +34,9 @@ class Image implements \JsonSerializable #[ORM\Column(name: 'non_conserv', type: Types::BIGINT, nullable: true)] private ?string $notConserved = null; + #[ORM\Column(name: 'affioramento', type: Types::BIGINT, nullable: true)] + private ?string $prehistoric = null; + #[ORM\Column(name: 'ordine', type: Types::SMALLINT)] private ?int $sequence = null; @@ -124,6 +127,18 @@ class Image implements \JsonSerializable return $this; } + public function getPrehistoric(): ?string + { + return $this->prehistoric; + } + + public function setPrehistoric(?string $prehistoric): static + { + $this->prehistoric = $prehistoric; + + return $this; + } + public function getSequence(): ?int { return $this->sequence; diff --git a/src/Entity/Prehistoric.php b/src/Entity/Prehistoric.php index f1f5316..7f43b9d 100644 --- a/src/Entity/Prehistoric.php +++ b/src/Entity/Prehistoric.php @@ -37,6 +37,11 @@ class Prehistoric implements \JsonSerializable private ?float $lng; + /** + * @var Image[] $images + */ + private ?array $images = null; + public function getId(): ?int { return $this->id; @@ -145,6 +150,24 @@ class Prehistoric implements \JsonSerializable return $this; } + /** + * @return Image[] + */ + public function getImages(): array + { + return $this->images; + } + + /** + * @param Image[] $images + */ + public function setImages(array $images): static + { + $this->images = $images; + + return $this; + } + public function jsonSerialize(): array { return [ @@ -156,6 +179,7 @@ class Prehistoric implements \JsonSerializable 'author' => $this->author, 'description' => $this->description, 'coordinates' => [$this->lat, $this->lng], + 'images' => $this->images, ]; } }