Add Document and Bibliography
This commit is contained in:
parent
54332fab42
commit
3f9b1faabf
@ -3,6 +3,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\NotConserved;
|
||||
use App\Entity\Bibliography;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
@ -14,20 +15,44 @@ class NotConservedController extends AbstractController
|
||||
public function index(EntityManagerInterface $em): JsonResponse
|
||||
{
|
||||
$repo = $em->getRepository(NotConserved::class);
|
||||
$repoBib = $em->getRepository(Bibliography::class);
|
||||
|
||||
$records = $repo->findAll();
|
||||
|
||||
// Terrible? N+1..
|
||||
foreach ($records as $key => $record) {
|
||||
$record->setLat($repo->coordinates($record->getId())['lat']);
|
||||
$record->setLng($repo->coordinates($record->getId())['lng']);
|
||||
$id = $record->getId();
|
||||
$record->setLat($repo->coordinates($id)['lat']);
|
||||
$record->setLng($repo->coordinates($id)['lng']);
|
||||
$record->setBibliographies($repoBib->findAllByNotConserved($id));
|
||||
$records[$key] = $record;
|
||||
}
|
||||
|
||||
return $this->json([
|
||||
'message' => 'All records for not conserved archaeological assets',
|
||||
'records' => $records
|
||||
],
|
||||
headers: ['Access-Control-Allow-Origin' => '*']
|
||||
);
|
||||
'message' => 'All records for not conserved archaeological assets',
|
||||
'records' => $records
|
||||
],
|
||||
headers: ['Access-Control-Allow-Origin' => '*']
|
||||
);
|
||||
}
|
||||
|
||||
#[Route('/not_conserved/{id<\d+>}', name: 'app_not_conserved_record')]
|
||||
public function record(NotConserved $notConserved, EntityManagerInterface $em): JsonResponse
|
||||
{
|
||||
$repo = $em->getRepository(NotConserved::class);
|
||||
$coordinates = $repo->coordinates($notConserved->getId());
|
||||
$repo = $em->getRepository(Bibliography::class);
|
||||
|
||||
$biblio = $repo->findAllByNotConserved($notConserved->getId());
|
||||
|
||||
$notConserved->setBibliographies($biblio);
|
||||
|
||||
$notConserved->setLat($coordinates['lat']);
|
||||
$notConserved->setLng($coordinates['lng']);
|
||||
|
||||
return $this->json(
|
||||
$notConserved,
|
||||
headers: ['Access-Control-Allow-Origin' => '*']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace App\Controller;
|
||||
|
||||
use App\Entity\Site;
|
||||
use App\Entity\Image;
|
||||
use App\Entity\Document;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@ -29,8 +30,11 @@ class SiteController extends AbstractController
|
||||
['sequence' => 'ASC']
|
||||
)
|
||||
);
|
||||
$site->setImages($images);
|
||||
$repo = $em->getRepository(Document::class);
|
||||
$documents = $repo->findBySite($site->getId());
|
||||
|
||||
$site->setImages($images);
|
||||
$site->setDocuments($documents);
|
||||
$site->setLat((float) $coords['lat']);
|
||||
$site->setLng((float) $coords['lng']);
|
||||
|
||||
|
83
src/Entity/Bibliography.php
Normal file
83
src/Entity/Bibliography.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\BibliographyRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: BibliographyRepository::class)]
|
||||
#[ORM\Table('bibliografia')]
|
||||
class Bibliography implements \JsonSerializable
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(name: 'citazione', length: 255)]
|
||||
private ?string $citation = null;
|
||||
|
||||
#[ORM\Column(name: 'riferimento', length: 400, nullable: true)]
|
||||
private ?string $reference = null;
|
||||
|
||||
#[ORM\Column(name: 'pagine', length: 20, nullable: true)]
|
||||
private ?string $pages = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(string $id): static
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCitation(): ?string
|
||||
{
|
||||
return $this->citation;
|
||||
}
|
||||
|
||||
public function setCitation(string $citation): static
|
||||
{
|
||||
$this->citation = $citation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReference(): ?string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
public function setReference(?string $reference): static
|
||||
{
|
||||
$this->reference = $reference;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPages(): ?string
|
||||
{
|
||||
return $this->pages;
|
||||
}
|
||||
|
||||
public function setPages(?string $pages): static
|
||||
{
|
||||
$this->pages = $pages;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'citation' => $this->citation,
|
||||
'reference' => $this->reference,
|
||||
'pages' => $this->pages,
|
||||
];
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: DocumentRepository::class)]
|
||||
#[ORM\Table('documento')]
|
||||
class Document
|
||||
class Document implements \JsonSerializable
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
@ -100,4 +100,16 @@ class Document
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'filename' => $this->filename,
|
||||
'description' => $this->description,
|
||||
'authors' => $this->authors,
|
||||
'type' => $this->type,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,10 @@ class NotConserved implements \JsonSerializable
|
||||
|
||||
private ?float $lng = null;
|
||||
|
||||
private ?ArrayCollection $bibliographies = null;
|
||||
/**
|
||||
* @var Bibliography[] $bibliographies
|
||||
*/
|
||||
private ?array $bibliographies = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true, name: 'periodo')]
|
||||
private ?string $period = null;
|
||||
@ -82,12 +85,12 @@ class NotConserved implements \JsonSerializable
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBibliographies(): ?int
|
||||
public function getBibliographies(): ?array
|
||||
{
|
||||
return $this->bibliographies;
|
||||
}
|
||||
|
||||
public function setBibliographies(int $bibliographies): static
|
||||
public function setBibliographies(array $bibliographies): static
|
||||
{
|
||||
$this->bibliographies = $bibliographies;
|
||||
|
||||
@ -133,12 +136,13 @@ class NotConserved implements \JsonSerializable
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'coordinates' => [$this->lat, $this->lng],
|
||||
'denomination' => $this->denomination,
|
||||
'genericLocation' => $this->genericLocation,
|
||||
'period' => $this->period,
|
||||
'shortDescription' => $this->shortDescription,
|
||||
//'bibliografia' => $this->bibliographies,
|
||||
'coordinates' => [$this->lat, $this->lng],
|
||||
'bibliography' => $this->bibliographies,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ class Site implements JsonSerializable
|
||||
|
||||
private ?ArrayCollection $images;
|
||||
|
||||
private ?array $documents;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@ -354,6 +356,18 @@ class Site implements JsonSerializable
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDocuments(): ?array
|
||||
{
|
||||
return $this->documents;
|
||||
}
|
||||
|
||||
public function setDocuments(array $documents): static
|
||||
{
|
||||
$this->documents = $documents;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
@ -378,6 +392,7 @@ class Site implements JsonSerializable
|
||||
'shortDescription' => $this->shortDescription,
|
||||
'ownedBy' => $this->ownedBy,
|
||||
'images' => $this->images->toArray(),
|
||||
'documents' => $this->documents,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
44
src/Repository/BibliographyRepository.php
Normal file
44
src/Repository/BibliographyRepository.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Bibliography;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Bibliography>
|
||||
*/
|
||||
class BibliographyRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Bibliography::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Bibliography[]
|
||||
*/
|
||||
public function findAllByNotConserved(int $notConserId): array
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Bibliography', 'b');
|
||||
$query = $this->getEntityManager()->createNativeQuery(
|
||||
'SELECT
|
||||
id,
|
||||
citazione,
|
||||
riferimento,
|
||||
pagine
|
||||
FROM bibliografia b
|
||||
JOIN bibliografia_non_conser
|
||||
ON id_bibliografia = b.id
|
||||
WHERE id_non_conser = :id',
|
||||
$rsm
|
||||
);
|
||||
|
||||
$query->setParameter('id', $notConserId);
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ namespace App\Repository;
|
||||
use App\Entity\Document;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Document>
|
||||
@ -16,6 +17,34 @@ class DocumentRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, Document::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Document[] Returns an array of Document objects
|
||||
*/
|
||||
public function findBySite(int $siteId): array
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Document', 'd');
|
||||
$query = $this->getEntityManager()->createNativeQuery(
|
||||
'SELECT
|
||||
id,
|
||||
titolo,
|
||||
filename,
|
||||
descrizione,
|
||||
autori,
|
||||
tipo
|
||||
FROM documento d
|
||||
JOIN sito_documento
|
||||
ON id_documento = d.id
|
||||
WHERE id_sito = :id
|
||||
',
|
||||
$rsm
|
||||
);
|
||||
|
||||
$query->setParameter('id', $siteId);
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Document[] Returns an array of Document objects
|
||||
// */
|
||||
|
Loading…
Reference in New Issue
Block a user