Add image type + NotConserved

This commit is contained in:
Nicolò P 2024-11-15 16:14:43 +01:00
parent b1c9fdbdf7
commit 54332fab42
9 changed files with 416 additions and 2 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace App\Controller;
use App\Entity\NotConserved;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
class NotConservedController extends AbstractController
{
#[Route('/not_conserved', name: 'app_not_conserved')]
public function index(EntityManagerInterface $em): JsonResponse
{
$repo = $em->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' => '*']
);
}
}

View File

@ -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' => '*']
);
}
}

103
src/Entity/Document.php Normal file
View File

@ -0,0 +1,103 @@
<?php
namespace App\Entity;
use App\Repository\DocumentRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: DocumentRepository::class)]
#[ORM\Table('documento')]
class Document
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, name: 'titolo')]
private ?string $title = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $filename = null;
#[ORM\Column(length: 255, nullable: true, name: 'descrizione')]
private ?string $description = null;
#[ORM\Column(length: 400, nullable: true, name: 'autori')]
private ?string $authors = null;
#[ORM\Column(length: 20, nullable: true, name: 'tipo')]
private ?string $type = null;
public function getId(): ?int
{
return $this->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;
}
}

View File

@ -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(),
];
}
}

144
src/Entity/NotConserved.php Normal file
View File

@ -0,0 +1,144 @@
<?php
namespace App\Entity;
use App\Repository\NotConservedRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: NotConservedRepository::class)]
#[ORM\Table(name: 'non_conserv')]
class NotConserved implements \JsonSerializable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 400, name: 'denominazione')]
private ?string $denomination = null;
private ?float $lat = null;
private ?float $lng = null;
private ?ArrayCollection $bibliographies = null;
#[ORM\Column(length: 255, nullable: true, name: 'periodo')]
private ?string $period = null;
#[ORM\Column(length: 255, nullable: true, name: 'localita_generica')]
private ?string $genericLocation = null;
#[ORM\Column(type: Types::TEXT, nullable: true, name: 'descrizione_breve')]
private ?string $shortDescription = null;
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 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],
];
}
}

View File

@ -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,

9
src/ImageType.php Normal file
View File

@ -0,0 +1,9 @@
<?php
namespace App;
enum ImageType: string
{
case Photo = 'foto';
case Survey = 'rilievo';
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Document;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Document>
*/
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()
// ;
// }
}

View File

@ -0,0 +1,59 @@
<?php
namespace App\Repository;
use App\Entity\NotConserved;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<NotConserved>
*/
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()
// ;
// }
}