From 692d150b5380135075b48464100cfbdea1be61ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Fri, 22 May 2026 17:01:35 +0200 Subject: [PATCH] Add BuildingTech --- src/Controller/BuildingTechController.php | 41 ++++++ src/Entity/BuildingTech.php | 161 ++++++++++++++++++++++ src/Entity/Site.php | 11 +- src/Repository/BuildingTechRepository.php | 59 ++++++++ 4 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 src/Controller/BuildingTechController.php create mode 100644 src/Entity/BuildingTech.php create mode 100644 src/Repository/BuildingTechRepository.php diff --git a/src/Controller/BuildingTechController.php b/src/Controller/BuildingTechController.php new file mode 100644 index 0000000..ca7569a --- /dev/null +++ b/src/Controller/BuildingTechController.php @@ -0,0 +1,41 @@ +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); + } +} diff --git a/src/Entity/BuildingTech.php b/src/Entity/BuildingTech.php new file mode 100644 index 0000000..cd64e63 --- /dev/null +++ b/src/Entity/BuildingTech.php @@ -0,0 +1,161 @@ +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(), + ]; + } +} diff --git a/src/Entity/Site.php b/src/Entity/Site.php index 2ec476b..8d3be92 100644 --- a/src/Entity/Site.php +++ b/src/Entity/Site.php @@ -457,6 +457,15 @@ class Site implements JsonSerializable 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 { return [ @@ -483,7 +492,7 @@ class Site implements JsonSerializable 'description' => $this->description, 'shortDescription' => $this->shortDescription, 'ownership' => $this->ownership, - 'images' => $this->images->toArray(), + 'images' => $this->images?->toArray(), 'documents' => $this->documents, 'bibliography' => $this->bibliography, 'techniques' => $this->techniques, diff --git a/src/Repository/BuildingTechRepository.php b/src/Repository/BuildingTechRepository.php new file mode 100644 index 0000000..3787d59 --- /dev/null +++ b/src/Repository/BuildingTechRepository.php @@ -0,0 +1,59 @@ + + */ +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() + // ; + // } +}