Add Finding (WIP)
This commit is contained in:
parent
e5d5f826ce
commit
766cf988e4
29
src/Controller/FindingController.php
Normal file
29
src/Controller/FindingController.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
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;
|
||||
|
||||
class FindingController extends AbstractController
|
||||
{
|
||||
#[Route('/finding', name: 'app_finding')]
|
||||
public function index(EntityManagerInterface $em): JsonResponse
|
||||
{
|
||||
$repo = $em->getRepository(Finding::class);
|
||||
|
||||
$findings = $repo->findAll();
|
||||
|
||||
foreach($findings as $key => $finding) {
|
||||
$coords = $repo->coordinates($finding->getId());
|
||||
$finding->setLat($coords['lat']);
|
||||
$finding->setLng($coords['lng']);
|
||||
$findings[$key] = $finding;
|
||||
}
|
||||
|
||||
return $this->json($findings);
|
||||
}
|
||||
}
|
256
src/Entity/Finding.php
Normal file
256
src/Entity/Finding.php
Normal file
@ -0,0 +1,256 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\FindingRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FindingRepository::class)]
|
||||
#[ORM\Table(name: 'rinvenimento')]
|
||||
class Finding implements \JsonSerializable
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 200, name: 'oggetto')]
|
||||
private ?string $object = null;
|
||||
|
||||
#[ORM\Column(length: 200, nullable: true, name: 'materia')]
|
||||
private ?string $material = null;
|
||||
|
||||
#[ORM\Column(length: 30, nullable: true, name: 'inventario')]
|
||||
private ?string $inventory = null;
|
||||
|
||||
#[ORM\Column(length: 100, nullable: true, name: 'luogo_rinv')]
|
||||
private ?string $place = null;
|
||||
|
||||
#[ORM\Column(nullable: true, name: 'anno_rinv')]
|
||||
private ?int $year = null;
|
||||
|
||||
#[ORM\Column(length: 200, nullable: true, name: 'datazione')]
|
||||
private ?string $dating = null;
|
||||
|
||||
#[ORM\Column(type: Types::BIGINT, nullable: true, name: 'sito')]
|
||||
#[ORM\ManyToOne(Site::class)]
|
||||
private ?string $site = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true, name: 'stato_conserv')]
|
||||
private ?string $conservationState = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true, name: 'luogo_conserv')]
|
||||
private ?string $conservationPlace = null;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true, name: 'descrizione')]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true, name: 'autore_scheda')]
|
||||
private ?string $author = null;
|
||||
|
||||
#[ORM\Column(length: 40, nullable: true, name: 'misure')]
|
||||
private ?string $measurements = null;
|
||||
|
||||
private ?float $lat = null;
|
||||
|
||||
private ?float $lng = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(string $id): static
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getObject(): ?string
|
||||
{
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
public function setObject(string $object): static
|
||||
{
|
||||
$this->object = $object;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMaterial(): ?string
|
||||
{
|
||||
return $this->material;
|
||||
}
|
||||
|
||||
public function setMaterial(?string $material): static
|
||||
{
|
||||
$this->material = $material;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInventory(): ?string
|
||||
{
|
||||
return $this->inventory;
|
||||
}
|
||||
|
||||
public function setInventory(?string $inventory): static
|
||||
{
|
||||
$this->inventory = $inventory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPlace(): ?string
|
||||
{
|
||||
return $this->place;
|
||||
}
|
||||
|
||||
public function setPlace(?string $place): static
|
||||
{
|
||||
$this->place = $place;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getYear(): ?int
|
||||
{
|
||||
return $this->year;
|
||||
}
|
||||
|
||||
public function setYear(?int $year): static
|
||||
{
|
||||
$this->year = $year;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDating(): ?string
|
||||
{
|
||||
return $this->dating;
|
||||
}
|
||||
|
||||
public function setDating(?string $dating): static
|
||||
{
|
||||
$this->dating = $dating;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSite(): ?string
|
||||
{
|
||||
return $this->site;
|
||||
}
|
||||
|
||||
public function setSite(?string $site): static
|
||||
{
|
||||
$this->site = $site;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConservationState(): ?string
|
||||
{
|
||||
return $this->conservationState;
|
||||
}
|
||||
|
||||
public function setConservationState(?string $conservationState): static
|
||||
{
|
||||
$this->conservationState = $conservationState;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConservationPlace(): ?string
|
||||
{
|
||||
return $this->conservationPlace;
|
||||
}
|
||||
|
||||
public function setConservationPlace(?string $conservationPlace): static
|
||||
{
|
||||
$this->conservationPlace = $conservationPlace;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(?string $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAuthor(): ?string
|
||||
{
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
public function setAuthor(string $author): static
|
||||
{
|
||||
$this->author = $author;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMeasurements(): ?string
|
||||
{
|
||||
return $this->measurements;
|
||||
}
|
||||
|
||||
public function setMeasurements(?string $measurements): static
|
||||
{
|
||||
$this->measurements = $measurements;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLat(): ?float
|
||||
{
|
||||
return $this->lat;
|
||||
}
|
||||
|
||||
public function setLat(float $lat): static
|
||||
{
|
||||
$this->lat = $lat;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLng(): ?float
|
||||
{
|
||||
return $this->lng;
|
||||
}
|
||||
|
||||
public function setLng(float $lng): static
|
||||
{
|
||||
$this->lng = $lng;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'object' => $this->object,
|
||||
'material' => $this->material,
|
||||
'measurements' => $this->measurements,
|
||||
'inventory' => $this->inventory,
|
||||
'place' => $this->place,
|
||||
'year' => $this->year,
|
||||
'dating' => $this->dating,
|
||||
'conservationState' => $this->conservationState,
|
||||
'conservationPlace' => $this->conservationPlace,
|
||||
'description' => $this->description,
|
||||
'author' => $this->author,
|
||||
'coordinates' => [$this->lat, $this->lng],
|
||||
];
|
||||
}
|
||||
}
|
59
src/Repository/FindingRepository.php
Normal file
59
src/Repository/FindingRepository.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Finding;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Finding>
|
||||
*/
|
||||
class FindingRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Finding::class);
|
||||
}
|
||||
|
||||
public function coordinates(int $id)
|
||||
{
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
ST_X(ST_AsText(coordinate)) as lng,
|
||||
ST_Y(ST_AsText(coordinate)) as lat
|
||||
FROM
|
||||
rinvenimento
|
||||
WHERE id = :id
|
||||
';
|
||||
|
||||
return $conn->executeQuery($sql, ['id' => $id])
|
||||
->fetchAssociative();
|
||||
}
|
||||
// /**
|
||||
// * @return Finding[] Returns an array of Finding objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('f')
|
||||
// ->andWhere('f.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('f.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Finding
|
||||
// {
|
||||
// return $this->createQueryBuilder('f')
|
||||
// ->andWhere('f.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue
Block a user