Add BuildingTech

This commit is contained in:
2026-05-22 17:01:35 +02:00
parent e0869c3869
commit 692d150b53
4 changed files with 271 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
<?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\BuildingTech;
class BuildingTechController extends AbstractController
{
#[Route('/building_techs', name: 'app_techs')]
public function index(EntityManagerInterface $em): JsonResponse
{
$repo = $em->getRepository(BuildingTech::class);
$techs = $repo->findAll();
//dd($techs);
foreach($techs as $key => $tech) {
$coords = $repo->coordinates($tech->getId());
$tech->setLat($coords['lat']);
$tech->setLng($coords['lng']);
$techs[$key] = $tech;
}
return $this->json($techs);
}
#[Route('/building_techs/{id<\d+>}', name: 'app_tech')]
public function record(BuildingTech $finding, EntityManagerInterface $em): JsonResponse
{
$repo = $em->getRepository(BuildingTech::class);
$coords = $repo->coordinates($finding->getId());
$finding->setLat($coords['lat']);
$finding->setLng($coords['lng']);
return $this->json($finding);
}
}

161
src/Entity/BuildingTech.php Normal file
View File

@@ -0,0 +1,161 @@
<?php
namespace App\Entity;
use App\Repository\BuildingTechRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: BuildingTechRepository::class)]
#[ORM\Table(name: 'tecniche_murarie')]
class BuildingTech implements \JsonSerializable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, name: 'tecnica')]
private ?string $technique = null;
#[ORM\Column(length: 200, nullable: true, name: 'materiale')]
private ?string $material = null;
#[ORM\ManyToOne(targetEntity: Site::class)]
#[ORM\JoinColumn(name: 'sito', referencedColumnName: 'id', nullable: true)]
private ?Site $site = null;
#[ORM\Column(length: 255, nullable: true, name: 'descrizione')]
private ?string $description = null;
#[ORM\Column(name: 'comune', length: 10, nullable: false)]
private ?string $municipality = null;
#[ORM\Column(name: 'funzione', length: 255, nullable: true)]
private ?string $function = 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 getMaterial(): ?string
{
return $this->material;
}
public function setMaterial(?string $material): static
{
$this->material = $material;
return $this;
}
public function getTechnique(): ?string
{
return $this->technique;
}
public function setTechnique(?string $technique): static
{
$this->technique = $technique;
return $this;
}
public function getSite(): ?Site
{
return $this->site;
}
public function setSite(?Site $site): static
{
$this->site = $site;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getFunction(): ?string
{
return $this->function;
}
public function setFunction(?string $function): static
{
$this->function = $function;
return $this;
}
public function getMunicipality(): ?string
{
return $this->municipality;
}
public function setMunicipality(?string $municipality): static
{
$this->municipality = $municipality;
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,
'technique' => $this->technique,
'material' => $this->material,
'description' => $this->description,
'function' => $this->function,
'municipality' => $this->municipality,
'coordinates' => [$this->lat, $this->lng],
'site' => $this->site?->toSummary(),
];
}
}

View File

@@ -457,6 +457,15 @@ class Site implements JsonSerializable
return $this; return $this;
} }
// Needed for search results purposes (see BuldingTech as well)
public function toSummary(): array
{
return [
'id' => $this->id,
'label' => $this->label,
];
}
public function jsonSerialize(): array public function jsonSerialize(): array
{ {
return [ return [
@@ -483,7 +492,7 @@ class Site implements JsonSerializable
'description' => $this->description, 'description' => $this->description,
'shortDescription' => $this->shortDescription, 'shortDescription' => $this->shortDescription,
'ownership' => $this->ownership, 'ownership' => $this->ownership,
'images' => $this->images->toArray(), 'images' => $this->images?->toArray(),
'documents' => $this->documents, 'documents' => $this->documents,
'bibliography' => $this->bibliography, 'bibliography' => $this->bibliography,
'techniques' => $this->techniques, 'techniques' => $this->techniques,

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Repository;
use App\Entity\BuildingTech;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<BuildingTech>
*/
class BuildingTechRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, BuildingTech::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
tecniche_murarie
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()
// ;
// }
}