Images and documents for Underwater
This commit is contained in:
parent
386653b6bf
commit
2fc6977362
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Document;
|
||||||
|
use App\Entity\Image;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
@ -14,15 +16,48 @@ class UnderwaterController extends AbstractController
|
|||||||
public function index(EntityManagerInterface $em): JsonResponse
|
public function index(EntityManagerInterface $em): JsonResponse
|
||||||
{
|
{
|
||||||
$repo = $em->getRepository(Underwater::class);
|
$repo = $em->getRepository(Underwater::class);
|
||||||
|
$imgRepo = $em->getRepository(Image::class);
|
||||||
|
|
||||||
$underwater = $repo->findAll();
|
$underwater = $repo->findAll();
|
||||||
|
|
||||||
foreach ($underwater as $under) {
|
/**
|
||||||
$coords = $repo->coordinates($under->getId());
|
* @var Underwater $record
|
||||||
$under->setLat($coords['lat']);
|
*/
|
||||||
$under->setLng($coords['lng']);
|
foreach ($underwater as $key => $record) {
|
||||||
|
$coords = $repo->coordinates($record->getId());
|
||||||
|
$record->setLat($coords['lat']);
|
||||||
|
$record->setLng($coords['lng']);
|
||||||
|
// TODO N + 1!!
|
||||||
|
$images = $imgRepo->findBy(
|
||||||
|
['underwater' => $record->getId()],
|
||||||
|
['sequence' => 'ASC']
|
||||||
|
);
|
||||||
|
$record->setImages($images);
|
||||||
|
$underwater[$key] = $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->json(['records' => $underwater]);
|
return $this->json(['records' => $underwater]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/underwater/{id<\d+>}', name: 'app_underwater_record')]
|
||||||
|
public function record(Underwater $record, EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$repo = $em->getRepository(Underwater::class);
|
||||||
|
$docRepo = $em->getRepository(Document::class);
|
||||||
|
$documents = $docRepo->findByUnderwater($record->getId());
|
||||||
|
$imgRepo = $em->getRepository(Image::class);
|
||||||
|
$images = $imgRepo->findBy(
|
||||||
|
['underwater' => $record->getId()],
|
||||||
|
['sequence' => 'ASC']
|
||||||
|
);
|
||||||
|
|
||||||
|
$coords = $repo->coordinates($record->getId());
|
||||||
|
$record->setLat($coords['lat']);
|
||||||
|
$record->setLng($coords['lng']);
|
||||||
|
$record->setImages($images);
|
||||||
|
$record->setDocuments($documents);
|
||||||
|
|
||||||
|
return $this->json($record);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,9 @@ class Image implements \JsonSerializable
|
|||||||
#[ORM\Column(name: 'reimpiego', type: Types::BIGINT, nullable: true)]
|
#[ORM\Column(name: 'reimpiego', type: Types::BIGINT, nullable: true)]
|
||||||
private ?string $reuse = null;
|
private ?string $reuse = null;
|
||||||
|
|
||||||
|
#[ORM\Column(name: 'giacimento', type: Types::BIGINT, nullable: true)]
|
||||||
|
private ?string $underwater = null;
|
||||||
|
|
||||||
#[ORM\Column(name: 'ordine', type: Types::SMALLINT)]
|
#[ORM\Column(name: 'ordine', type: Types::SMALLINT)]
|
||||||
private ?int $sequence = null;
|
private ?int $sequence = null;
|
||||||
|
|
||||||
@ -144,7 +147,7 @@ class Image implements \JsonSerializable
|
|||||||
|
|
||||||
public function getReuse(): ?string
|
public function getReuse(): ?string
|
||||||
{
|
{
|
||||||
return $this->prehistoric;
|
return $this->reuse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setReuse(?string $reuse): static
|
public function setReuse(?string $reuse): static
|
||||||
@ -154,6 +157,18 @@ class Image implements \JsonSerializable
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUnderwater(): ?string
|
||||||
|
{
|
||||||
|
return $this->underwater;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUnderwater(?string $underwater): static
|
||||||
|
{
|
||||||
|
$this->underwater = $underwater;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getSequence(): ?int
|
public function getSequence(): ?int
|
||||||
{
|
{
|
||||||
return $this->sequence;
|
return $this->sequence;
|
||||||
|
@ -41,6 +41,16 @@ class Underwater implements JsonSerializable
|
|||||||
|
|
||||||
private ?float $lng = null;
|
private ?float $lng = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Image[] $images
|
||||||
|
*/
|
||||||
|
private ?array $images = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Document[] $documents
|
||||||
|
*/
|
||||||
|
private ?array $documents = null;
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@ -161,6 +171,30 @@ class Underwater implements JsonSerializable
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getImages(): ?array
|
||||||
|
{
|
||||||
|
return $this->images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setImages(?array $images): static
|
||||||
|
{
|
||||||
|
$this->images = $images;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDocuments(): ?array
|
||||||
|
{
|
||||||
|
return $this->documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDocuments(?array $documents): static
|
||||||
|
{
|
||||||
|
$this->documents = $documents;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): array
|
public function jsonSerialize(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -173,6 +207,8 @@ class Underwater implements JsonSerializable
|
|||||||
'shortDescription' => $this->shortDescription,
|
'shortDescription' => $this->shortDescription,
|
||||||
'author' => $this->author,
|
'author' => $this->author,
|
||||||
'label' => $this->label,
|
'label' => $this->label,
|
||||||
|
'images' => $this->images,
|
||||||
|
'documents' => $this->documents,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,48 @@ class DocumentRepository extends ServiceEntityRepository
|
|||||||
|
|
||||||
return $entities;
|
return $entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Document[] Returns an array of Document objects
|
||||||
|
*/
|
||||||
|
public function findByUnderwater(int $underwaterId): array
|
||||||
|
{
|
||||||
|
$conn = $this->getEntityManager()->getConnection();
|
||||||
|
|
||||||
|
$sql = '
|
||||||
|
SELECT
|
||||||
|
d.id,
|
||||||
|
d.titolo,
|
||||||
|
d.filename,
|
||||||
|
d.descrizione,
|
||||||
|
d.autori,
|
||||||
|
d.tipo,
|
||||||
|
d.luogo
|
||||||
|
FROM documento d
|
||||||
|
INNER JOIN giacimento_documento gd ON gd.id_documento = d.id
|
||||||
|
WHERE gd.id_giacimento = :underwaterId
|
||||||
|
ORDER BY d.titolo ASC
|
||||||
|
';
|
||||||
|
|
||||||
|
$stmt = $conn->prepare($sql);
|
||||||
|
$results = $stmt->executeQuery(['underwaterId' => $underwaterId])->fetchAllAssociative();
|
||||||
|
|
||||||
|
$entities = [];
|
||||||
|
|
||||||
|
foreach ($results as $row) {
|
||||||
|
$document = new Document();
|
||||||
|
$document->setId($row['id']);
|
||||||
|
$document->setTitle($row['titolo']);
|
||||||
|
$document->setFilename($row['filename']);
|
||||||
|
$document->setDescription($row['descrizione']);
|
||||||
|
$document->setConservationPlace($row['luogo']);
|
||||||
|
$document->setType($row['tipo']);
|
||||||
|
$document->setAuthors($row['autori']);
|
||||||
|
$entities[] = $document;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entities;
|
||||||
|
}
|
||||||
// /**
|
// /**
|
||||||
// * @return Document[] Returns an array of Document objects
|
// * @return Document[] Returns an array of Document objects
|
||||||
// */
|
// */
|
||||||
|
Loading…
Reference in New Issue
Block a user