diff --git a/src/Controller/FindingController.php b/src/Controller/FindingController.php new file mode 100644 index 0000000..e655948 --- /dev/null +++ b/src/Controller/FindingController.php @@ -0,0 +1,29 @@ +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); + } +} diff --git a/src/Entity/Finding.php b/src/Entity/Finding.php new file mode 100644 index 0000000..458bca2 --- /dev/null +++ b/src/Entity/Finding.php @@ -0,0 +1,256 @@ +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], + ]; + } +} diff --git a/src/Repository/FindingRepository.php b/src/Repository/FindingRepository.php new file mode 100644 index 0000000..b59de6b --- /dev/null +++ b/src/Repository/FindingRepository.php @@ -0,0 +1,59 @@ + + */ +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() + // ; + // } +}