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;
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);
}

View File

@ -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;

View File

@ -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,
];
}
}