Add images to prehistoric

This commit is contained in:
Nicolò P 2025-05-07 16:41:23 +02:00
parent 696ef51508
commit e5810d94c6
3 changed files with 56 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace App\Controller; namespace App\Controller;
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;
@ -24,6 +25,14 @@ class PrehistoricController extends AbstractController
$id = $record->getId(); $id = $record->getId();
$record->setLat($repo->coordinates($id)['lat']); $record->setLat($repo->coordinates($id)['lat']);
$record->setLng($repo->coordinates($id)['lng']); $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; $records[$key] = $record;
} }
@ -46,6 +55,14 @@ class PrehistoricController extends AbstractController
$prehistoric->setLat($coordinates['lat']); $prehistoric->setLat($coordinates['lat']);
$prehistoric->setLng($coordinates['lng']); $prehistoric->setLng($coordinates['lng']);
$repo = $em->getRepository(Image::class);
$images = $repo->findBy(
['prehistoric' => $prehistoric->getId()],
['sequence' => 'ASC']
);
$prehistoric->setImages($images);
return $this->json($prehistoric); return $this->json($prehistoric);
} }

View File

@ -34,6 +34,9 @@ class Image implements \JsonSerializable
#[ORM\Column(name: 'non_conserv', type: Types::BIGINT, nullable: true)] #[ORM\Column(name: 'non_conserv', type: Types::BIGINT, nullable: true)]
private ?string $notConserved = null; private ?string $notConserved = null;
#[ORM\Column(name: 'affioramento', type: Types::BIGINT, nullable: true)]
private ?string $prehistoric = null;
#[ORM\Column(name: 'ordine', type: Types::SMALLINT)] #[ORM\Column(name: 'ordine', type: Types::SMALLINT)]
private ?int $sequence = null; private ?int $sequence = null;
@ -124,6 +127,18 @@ class Image implements \JsonSerializable
return $this; return $this;
} }
public function getPrehistoric(): ?string
{
return $this->prehistoric;
}
public function setPrehistoric(?string $prehistoric): static
{
$this->prehistoric = $prehistoric;
return $this;
}
public function getSequence(): ?int public function getSequence(): ?int
{ {
return $this->sequence; return $this->sequence;

View File

@ -37,6 +37,11 @@ class Prehistoric implements \JsonSerializable
private ?float $lng; private ?float $lng;
/**
* @var Image[] $images
*/
private ?array $images = null;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@ -145,6 +150,24 @@ class Prehistoric implements \JsonSerializable
return $this; 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 public function jsonSerialize(): array
{ {
return [ return [
@ -156,6 +179,7 @@ class Prehistoric implements \JsonSerializable
'author' => $this->author, 'author' => $this->author,
'description' => $this->description, 'description' => $this->description,
'coordinates' => [$this->lat, $this->lng], 'coordinates' => [$this->lat, $this->lng],
'images' => $this->images,
]; ];
} }
} }