From 54332fab4294ced3aab3d0513e96f2b89968dacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Fri, 15 Nov 2024 16:14:43 +0100 Subject: [PATCH] Add image type + NotConserved --- src/Controller/NotConservedController.php | 33 +++++ src/Controller/SiteController.php | 7 +- src/Entity/Document.php | 103 ++++++++++++++++ src/Entity/Image.php | 19 +++ src/Entity/NotConserved.php | 144 ++++++++++++++++++++++ src/Entity/Site.php | 1 + src/ImageType.php | 9 ++ src/Repository/DocumentRepository.php | 43 +++++++ src/Repository/NotConservedRepository.php | 59 +++++++++ 9 files changed, 416 insertions(+), 2 deletions(-) create mode 100644 src/Controller/NotConservedController.php create mode 100644 src/Entity/Document.php create mode 100644 src/Entity/NotConserved.php create mode 100644 src/ImageType.php create mode 100644 src/Repository/DocumentRepository.php create mode 100644 src/Repository/NotConservedRepository.php diff --git a/src/Controller/NotConservedController.php b/src/Controller/NotConservedController.php new file mode 100644 index 0000000..393c928 --- /dev/null +++ b/src/Controller/NotConservedController.php @@ -0,0 +1,33 @@ +getRepository(NotConserved::class); + + $records = $repo->findAll(); + + foreach ($records as $key => $record) { + $record->setLat($repo->coordinates($record->getId())['lat']); + $record->setLng($repo->coordinates($record->getId())['lng']); + $records[$key] = $record; + } + + return $this->json([ + 'message' => 'All records for not conserved archaeological assets', + 'records' => $records + ], + headers: ['Access-Control-Allow-Origin' => '*'] + ); + } +} diff --git a/src/Controller/SiteController.php b/src/Controller/SiteController.php index 6ae00dc..94fed19 100644 --- a/src/Controller/SiteController.php +++ b/src/Controller/SiteController.php @@ -26,7 +26,7 @@ class SiteController extends AbstractController $images = new ArrayCollection( $repo->findBy( ['site' => $site->getId()], - ['sequence' => 'DESC'] + ['sequence' => 'ASC'] ) ); $site->setImages($images); @@ -34,6 +34,9 @@ class SiteController extends AbstractController $site->setLat((float) $coords['lat']); $site->setLng((float) $coords['lng']); - return $this->json( $site ); + return $this->json( + $site, + headers: ['Access-Control-Allow-Origin' => '*'] + ); } } diff --git a/src/Entity/Document.php b/src/Entity/Document.php new file mode 100644 index 0000000..e91784f --- /dev/null +++ b/src/Entity/Document.php @@ -0,0 +1,103 @@ +id; + } + + public function setId(string $id): static + { + $this->id = $id; + + return $this; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): static + { + $this->title = $title; + + return $this; + } + + public function getFilename(): ?string + { + return $this->filename; + } + + public function setFilename(string $filename): static + { + $this->filename = $filename; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): static + { + $this->description = $description; + + return $this; + } + + public function getAuthors(): ?string + { + return $this->authors; + } + + public function setAuthors(?string $authors): static + { + $this->authors = $authors; + + return $this; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(?string $type): static + { + $this->type = $type; + + return $this; + } +} diff --git a/src/Entity/Image.php b/src/Entity/Image.php index f20af6e..7965df7 100644 --- a/src/Entity/Image.php +++ b/src/Entity/Image.php @@ -2,6 +2,7 @@ namespace App\Entity; +use App\ImageType; use App\Repository\ImageRepository; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; @@ -30,6 +31,9 @@ class Image implements \JsonSerializable #[ORM\Column(name: 'ordine', type: Types::SMALLINT)] private ?int $sequence = null; + #[ORM\Column(name: 'tipo')] + private ?string $type = null; + public function getId(): ?int { return $this->id; @@ -102,6 +106,20 @@ class Image implements \JsonSerializable return $this; } + public function getType(): string + { + $type = ImageType::from($this->type); + + return $type->name; + } + + public function setType(ImageType $type): static + { + $this->type = $type->value; + + return $this; + } + public function jsonSerialize(): array { return [ @@ -109,6 +127,7 @@ class Image implements \JsonSerializable 'filename' => $this->filename, 'caption' => $this->caption, 'author' => $this->author, + 'type' => $this->getType(), ]; } } diff --git a/src/Entity/NotConserved.php b/src/Entity/NotConserved.php new file mode 100644 index 0000000..fb281ef --- /dev/null +++ b/src/Entity/NotConserved.php @@ -0,0 +1,144 @@ +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 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 getBibliographies(): ?int + { + return $this->bibliographies; + } + + public function setBibliographies(int $bibliographies): static + { + $this->bibliographies = $bibliographies; + + return $this; + } + + public function getPeriod(): ?string + { + return $this->period; + } + + public function setPeriod(?string $period): static + { + $this->period = $period; + + return $this; + } + + public function getGenericLocation(): ?string + { + return $this->genericLocation; + } + + public function setGenericLocation(?string $genericLocation): static + { + $this->genericLocation = $genericLocation; + + return $this; + } + + public function getShortDescription(): ?string + { + return $this->shortDescription; + } + + public function setShortDescription(?string $shortDescription): static + { + $this->shortDescription = $shortDescription; + + return $this; + } + + public function jsonSerialize(): array + { + return [ + 'denomination' => $this->denomination, + 'genericLocation' => $this->genericLocation, + 'period' => $this->period, + 'shortDescription' => $this->shortDescription, + //'bibliografia' => $this->bibliographies, + 'coordinates' => [$this->lat, $this->lng], + ]; + } +} diff --git a/src/Entity/Site.php b/src/Entity/Site.php index d47a175..d3f3b2d 100644 --- a/src/Entity/Site.php +++ b/src/Entity/Site.php @@ -361,6 +361,7 @@ class Site implements JsonSerializable 'place' => $this->place, 'genericPlace' => $this->genericPlace, 'address' => $this->address, + 'municipality' => $this->municipality, 'localization' => $this->localization, 'coordinates' => [$this->lat, $this->lng], 'denomination' => $this->denomination, diff --git a/src/ImageType.php b/src/ImageType.php new file mode 100644 index 0000000..ff91d9c --- /dev/null +++ b/src/ImageType.php @@ -0,0 +1,9 @@ + + */ +class DocumentRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Document::class); + } + + // /** + // * @return Document[] Returns an array of Document objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('d') + // ->andWhere('d.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('d.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Document + // { + // return $this->createQueryBuilder('d') + // ->andWhere('d.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/NotConservedRepository.php b/src/Repository/NotConservedRepository.php new file mode 100644 index 0000000..51e4237 --- /dev/null +++ b/src/Repository/NotConservedRepository.php @@ -0,0 +1,59 @@ + + */ +class NotConservedRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, NotConserved::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 + non_conserv + WHERE id = :id + '; + + return $conn->executeQuery($sql, ['id' => $id]) + ->fetchAssociative(); + } + // /** + // * @return NotConserved[] Returns an array of NotConserved objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('n') + // ->andWhere('n.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('n.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?NotConserved + // { + // return $this->createQueryBuilder('n') + // ->andWhere('n.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +}