Add Prehistoric stuff...
This commit is contained in:
parent
faee735af8
commit
dc06764e36
53
src/Controller/PrehistoricController.php
Normal file
53
src/Controller/PrehistoricController.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Prehistoric;
|
||||||
|
//use App\Entity\Bibliography;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
class PrehistoricController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/prehistoric', name: 'app_prehistoric')]
|
||||||
|
public function index(EntityManagerInterface $em): JsonResponse
|
||||||
|
{
|
||||||
|
$repo = $em->getRepository(Prehistoric::class);
|
||||||
|
//$repoBib = $em->getRepository(Bibliography::class);
|
||||||
|
|
||||||
|
$records = $repo->findBy([], ['id' => 'ASC']);
|
||||||
|
|
||||||
|
// Terrible? N+1..
|
||||||
|
foreach ($records as $key => $record) {
|
||||||
|
$id = $record->getId();
|
||||||
|
$record->setLat($repo->coordinates($id)['lat']);
|
||||||
|
$record->setLng($repo->coordinates($id)['lng']);
|
||||||
|
$records[$key] = $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->json([
|
||||||
|
'message' => 'All records for prehistoric assets',
|
||||||
|
'records' => $records
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/prehistoric/{id<\d+>}', name: 'app_prehistoric_record')]
|
||||||
|
public function record(Prehistoric $prehistoric, EntityManagerInterface $em): JsonResponse
|
||||||
|
{
|
||||||
|
$repo = $em->getRepository(Prehistoric::class);
|
||||||
|
$coordinates = $repo->coordinates($prehistoric->getId());
|
||||||
|
//$repo = $em->getRepository(Bibliography::class);
|
||||||
|
|
||||||
|
//$biblio = $repo->findAllByNotConserved($prehistoric->getId());
|
||||||
|
//$notConserved->setBibliographies($biblio);
|
||||||
|
|
||||||
|
$prehistoric->setLat($coordinates['lat']);
|
||||||
|
$prehistoric->setLng($coordinates['lng']);
|
||||||
|
|
||||||
|
return $this->json($prehistoric);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
161
src/Entity/Prehistoric.php
Normal file
161
src/Entity/Prehistoric.php
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\PrehistoricRepository;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: PrehistoricRepository::class)]
|
||||||
|
#[ORM\Table(name: 'preistoria')]
|
||||||
|
class Prehistoric 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: 120, nullable: true, name: 'periodo')]
|
||||||
|
private ?string $period = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::TEXT, nullable: true, name: 'descrizione')]
|
||||||
|
private ?string $description = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true, name: 'conservazione')]
|
||||||
|
private ?string $conservation = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true, name: 'autore_scheda')]
|
||||||
|
private ?string $author = null;
|
||||||
|
|
||||||
|
private ?float $lat;
|
||||||
|
|
||||||
|
private ?float $lng;
|
||||||
|
|
||||||
|
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 getDescription(): ?string
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(?string $description): static
|
||||||
|
{
|
||||||
|
$this->description = $description;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConservation(): ?string
|
||||||
|
{
|
||||||
|
return $this->conservation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setConservation(?string $conservation): static
|
||||||
|
{
|
||||||
|
$this->conservation = $conservation;
|
||||||
|
|
||||||
|
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 $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 [
|
||||||
|
'id' => $this->id,
|
||||||
|
'denomination' => $this->denomination,
|
||||||
|
'genericPlace' => $this->genericPlace,
|
||||||
|
'period' => $this->period,
|
||||||
|
'conservation' => $this->conservation,
|
||||||
|
'author' => $this->author,
|
||||||
|
'description' => $this->description,
|
||||||
|
'coordinates' => [$this->lat, $this->lng],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
59
src/Repository/PrehistoricRepository.php
Normal file
59
src/Repository/PrehistoricRepository.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Prehistoric;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<Prehistoric>
|
||||||
|
*/
|
||||||
|
class PrehistoricRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Prehistoric::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function coordinates(int $id): array|bool
|
||||||
|
{
|
||||||
|
$conn = $this->getEntityManager()->getConnection();
|
||||||
|
|
||||||
|
$sql = '
|
||||||
|
SELECT
|
||||||
|
ST_X(ST_AsText(coordinate)) as lng,
|
||||||
|
ST_Y(ST_AsText(coordinate)) as lat
|
||||||
|
FROM
|
||||||
|
preistoria
|
||||||
|
WHERE id = :id
|
||||||
|
';
|
||||||
|
|
||||||
|
return $conn->executeQuery($sql, ['id' => $id])
|
||||||
|
->fetchAssociative();
|
||||||
|
}
|
||||||
|
// /**
|
||||||
|
// * @return Prehistoric[] Returns an array of Prehistoric objects
|
||||||
|
// */
|
||||||
|
// public function findByExampleField($value): array
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('p')
|
||||||
|
// ->andWhere('p.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->orderBy('p.id', 'ASC')
|
||||||
|
// ->setMaxResults(10)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function findOneBySomeField($value): ?Prehistoric
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('p')
|
||||||
|
// ->andWhere('p.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getOneOrNullResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user