Biblio and images for Finding
This commit is contained in:
parent
766cf988e4
commit
5e3b4da7c0
@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Bibliography;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\Finding;
|
||||
use App\Entity\Image;
|
||||
|
||||
class FindingController extends AbstractController
|
||||
{
|
||||
@ -26,4 +28,25 @@ class FindingController extends AbstractController
|
||||
|
||||
return $this->json($findings);
|
||||
}
|
||||
|
||||
#[Route('/finding/{id<\d+>}', name: 'app_finding_record')]
|
||||
public function record(Finding $finding, EntityManagerInterface $em): JsonResponse
|
||||
{
|
||||
$repo = $em->getRepository(Finding::class);
|
||||
$coords = $repo->coordinates($finding->getId());
|
||||
$finding->setLat($coords['lat']);
|
||||
$finding->setLng($coords['lng']);
|
||||
$repo = $em->getRepository(Bibliography::class);
|
||||
$biblio = $repo->findAllByFinding($finding->getId());
|
||||
$repo = $em->getRepository(Image::class);
|
||||
$images = $repo->findBy(
|
||||
['finding' => $finding->getId()],
|
||||
['sequence' => 'ASC']
|
||||
);
|
||||
|
||||
$finding->setBibliography($biblio);
|
||||
$finding->setImages($images);
|
||||
|
||||
return $this->json($finding);
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,16 @@ class Finding implements \JsonSerializable
|
||||
|
||||
private ?float $lng = null;
|
||||
|
||||
/**
|
||||
* @var Bibliography[] $bibliography
|
||||
*/
|
||||
private ?array $bibliography = null;
|
||||
|
||||
/**
|
||||
* @var Bibliography[] $images
|
||||
*/
|
||||
private ?array $images = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@ -236,9 +246,34 @@ class Finding implements \JsonSerializable
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBibliography(): ?array
|
||||
{
|
||||
return $this->bibliography;
|
||||
}
|
||||
|
||||
public function setBibliography(array $bibliography): static
|
||||
{
|
||||
$this->bibliography = $bibliography;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImages(): ?array
|
||||
{
|
||||
return $this->images;
|
||||
}
|
||||
|
||||
public function setImages(array $images): static
|
||||
{
|
||||
$this->images = $images;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'object' => $this->object,
|
||||
'material' => $this->material,
|
||||
'measurements' => $this->measurements,
|
||||
@ -251,6 +286,8 @@ class Finding implements \JsonSerializable
|
||||
'description' => $this->description,
|
||||
'author' => $this->author,
|
||||
'coordinates' => [$this->lat, $this->lng],
|
||||
'bibliography' => $this->bibliography,
|
||||
'images' => $this->images,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ class Image implements \JsonSerializable
|
||||
#[ORM\Column(name: 'sito', type: Types::BIGINT, nullable: true)]
|
||||
private ?string $site = null;
|
||||
|
||||
#[ORM\Column(name: 'rinvenimento', type: Types::BIGINT, nullable: true)]
|
||||
private ?string $finding = null;
|
||||
|
||||
#[ORM\Column(name: 'ordine', type: Types::SMALLINT)]
|
||||
private ?int $sequence = null;
|
||||
|
||||
@ -94,6 +97,18 @@ class Image implements \JsonSerializable
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFinding(): ?string
|
||||
{
|
||||
return $this->finding;
|
||||
}
|
||||
|
||||
public function setFinding(?string $finding): static
|
||||
{
|
||||
$this->finding = $finding;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSequence(): ?int
|
||||
{
|
||||
return $this->sequence;
|
||||
|
@ -40,6 +40,31 @@ class BibliographyRepository extends ServiceEntityRepository
|
||||
|
||||
$query->setParameter('id', $notConserId);
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
/**
|
||||
* @return Bibliography[]
|
||||
*/
|
||||
public function findAllByFinding(int $findingId): array
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Bibliography', 'b');
|
||||
$query = $this->getEntityManager()->createNativeQuery(
|
||||
'SELECT
|
||||
id,
|
||||
citazione,
|
||||
riferimento,
|
||||
pagine
|
||||
FROM bibliografia b
|
||||
JOIN bibliografia_rinvenim
|
||||
ON id_bibliografia = b.id
|
||||
WHERE id_rinvenimento = :id
|
||||
ORDER BY ordine ASC',
|
||||
$rsm
|
||||
);
|
||||
|
||||
$query->setParameter('id', $findingId);
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user