Add site-biblio relation
This commit is contained in:
parent
78bd3ab85f
commit
5706cab551
@ -5,6 +5,7 @@ namespace App\Controller;
|
|||||||
use App\Entity\Site;
|
use App\Entity\Site;
|
||||||
use App\Entity\Image;
|
use App\Entity\Image;
|
||||||
use App\Entity\Document;
|
use App\Entity\Document;
|
||||||
|
use App\Entity\Bibliography;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
@ -32,9 +33,12 @@ class SiteController extends AbstractController
|
|||||||
);
|
);
|
||||||
$repo = $em->getRepository(Document::class);
|
$repo = $em->getRepository(Document::class);
|
||||||
$documents = $repo->findBySite($site->getId());
|
$documents = $repo->findBySite($site->getId());
|
||||||
|
$repo = $em->getRepository(Bibliography::class);
|
||||||
|
$bibliography = $repo->findAllBySite($site->getId());
|
||||||
|
|
||||||
$site->setImages($images);
|
$site->setImages($images);
|
||||||
$site->setDocuments($documents);
|
$site->setDocuments($documents);
|
||||||
|
$site->setBibliography($bibliography);
|
||||||
$site->setLat((float) $coords['lat']);
|
$site->setLat((float) $coords['lat']);
|
||||||
$site->setLng((float) $coords['lng']);
|
$site->setLng((float) $coords['lng']);
|
||||||
|
|
||||||
|
@ -86,8 +86,16 @@ class Site implements JsonSerializable
|
|||||||
|
|
||||||
private ?ArrayCollection $images;
|
private ?ArrayCollection $images;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Document[] $documents
|
||||||
|
*/
|
||||||
private ?array $documents;
|
private ?array $documents;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Bibliography[] $bibliography
|
||||||
|
*/
|
||||||
|
private ?array $bibliography;
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@ -398,6 +406,18 @@ class Site implements JsonSerializable
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getBibliography(): ?array
|
||||||
|
{
|
||||||
|
return $this->bibliography;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBibliography(array $bibliography): static
|
||||||
|
{
|
||||||
|
$this->bibliography = $bibliography;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): array
|
public function jsonSerialize(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -424,6 +444,7 @@ class Site implements JsonSerializable
|
|||||||
'ownedBy' => $this->ownedBy,
|
'ownedBy' => $this->ownedBy,
|
||||||
'images' => $this->images->toArray(),
|
'images' => $this->images->toArray(),
|
||||||
'documents' => $this->documents,
|
'documents' => $this->documents,
|
||||||
|
'bibliography' => $this->bibliography,
|
||||||
'techniques' => $this->techniques,
|
'techniques' => $this->techniques,
|
||||||
'author' => $this->author,
|
'author' => $this->author,
|
||||||
];
|
];
|
||||||
|
@ -17,6 +17,31 @@ class BibliographyRepository extends ServiceEntityRepository
|
|||||||
parent::__construct($registry, Bibliography::class);
|
parent::__construct($registry, Bibliography::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Bibliography[]
|
||||||
|
*/
|
||||||
|
public function findAllBySite(int $siteId): 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_sito
|
||||||
|
ON id_bibliografia = b.id
|
||||||
|
WHERE id_sito = :id
|
||||||
|
ORDER BY ordine ASC',
|
||||||
|
$rsm
|
||||||
|
);
|
||||||
|
|
||||||
|
$query->setParameter('id', $siteId);
|
||||||
|
|
||||||
|
return $query->getResult();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @return Bibliography[]
|
* @return Bibliography[]
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user