Add underwater sites
This commit is contained in:
parent
b84d4589fe
commit
2fa1d2d99e
28
src/Controller/UnderwaterController.php
Normal file
28
src/Controller/UnderwaterController.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use App\Entity\Underwater;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
class UnderwaterController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/underwater', name: 'app_underwater')]
|
||||||
|
public function index(EntityManagerInterface $em): JsonResponse
|
||||||
|
{
|
||||||
|
$repo = $em->getRepository(Underwater::class);
|
||||||
|
|
||||||
|
$underwater = $repo->findAll();
|
||||||
|
|
||||||
|
foreach ($underwater as $under) {
|
||||||
|
$coords = $repo->coordinates($under->getId());
|
||||||
|
$under->setLat($coords['lat']);
|
||||||
|
$under->setLng($coords['lng']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->json($underwater);
|
||||||
|
}
|
||||||
|
}
|
162
src/Entity/Underwater.php
Normal file
162
src/Entity/Underwater.php
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\UnderwaterRepository;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use JsonSerializable;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: UnderwaterRepository::class)]
|
||||||
|
#[ORM\Table(name: 'giacimento')]
|
||||||
|
class Underwater implements JsonSerializable
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, name: 'denominazione')]
|
||||||
|
private ?string $denomination = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true, name: 'loc_generica')]
|
||||||
|
private ?string $genericPlace = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 100, nullable: true, name: 'periodo')]
|
||||||
|
private ?string $period = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::TEXT, nullable: true, name: 'descrizione_breve')]
|
||||||
|
private ?string $shortDescription = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 100, nullable: true, name: 'conservazione')]
|
||||||
|
private ?string $conservationState = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 80, nullable: true, name: 'autore_scheda')]
|
||||||
|
private ?string $author = 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 getDenomination(): ?string
|
||||||
|
{
|
||||||
|
return $this->denomination;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDenomination(string $denomination): static
|
||||||
|
{
|
||||||
|
$this->denomination = $denomination;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGenericPlace(): ?string
|
||||||
|
{
|
||||||
|
return $this->genericPlace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setGenericPlace(?string $genericPlace): static
|
||||||
|
{
|
||||||
|
$this->genericPlace = $genericPlace;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPeriod(): ?string
|
||||||
|
{
|
||||||
|
return $this->period;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPeriod(?string $period): static
|
||||||
|
{
|
||||||
|
$this->period = $period;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getShortDescription(): ?string
|
||||||
|
{
|
||||||
|
return $this->shortDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setShortDescription(?string $shortDescription): static
|
||||||
|
{
|
||||||
|
$this->shortDescription = $shortDescription;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConservationState(): ?string
|
||||||
|
{
|
||||||
|
return $this->conservationState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setConservationState(?string $conservationState): static
|
||||||
|
{
|
||||||
|
$this->conservationState = $conservationState;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAuthor(): ?string
|
||||||
|
{
|
||||||
|
return $this->author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAuthor(?string $author): static
|
||||||
|
{
|
||||||
|
$this->author = $author;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLat(): ?float
|
||||||
|
{
|
||||||
|
return $this->lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLat(?float $latitude): static
|
||||||
|
{
|
||||||
|
$this->lat = $latitude;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLng(): ?float
|
||||||
|
{
|
||||||
|
return $this->lng;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLng(?float $longitude): static
|
||||||
|
{
|
||||||
|
$this->lng = $longitude;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'genericPlace' => $this->genericPlace,
|
||||||
|
'coordinates' => [$this->lat, $this->lng],
|
||||||
|
'denomination' => $this->denomination,
|
||||||
|
'period' => $this->period,
|
||||||
|
'conservationState' => $this->conservationState,
|
||||||
|
'shortDescription' => $this->shortDescription,
|
||||||
|
'author' => $this->author,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
61
src/Repository/UnderwaterRepository.php
Normal file
61
src/Repository/UnderwaterRepository.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Underwater;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<Underwater>
|
||||||
|
*/
|
||||||
|
class UnderwaterRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Underwater::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
|
||||||
|
giacimento
|
||||||
|
WHERE id = :id
|
||||||
|
';
|
||||||
|
|
||||||
|
return $conn
|
||||||
|
->executeQuery($sql, ['id' => $id])
|
||||||
|
->fetchAssociative();
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return Underwater[] Returns an array of Underwater objects
|
||||||
|
// */
|
||||||
|
// public function findByExampleField($value): array
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('u')
|
||||||
|
// ->andWhere('u.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->orderBy('u.id', 'ASC')
|
||||||
|
// ->setMaxResults(10)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function findOneBySomeField($value): ?Underwater
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('u')
|
||||||
|
// ->andWhere('u.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getOneOrNullResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user