Use manual hydration for many-to-many to avoid problems with caching
This commit is contained in:
parent
660de08377
commit
7ab75a30fb
@ -27,23 +27,23 @@ class SiteController extends AbstractController
|
|||||||
$coords = $repo->coordinates($site->getId());
|
$coords = $repo->coordinates($site->getId());
|
||||||
$site->setLat($coords['lat']);
|
$site->setLat($coords['lat']);
|
||||||
$site->setLng($coords['lng']);
|
$site->setLng($coords['lng']);
|
||||||
$sites[$key] = $site;
|
$repoImg = $em->getRepository(Image::class);
|
||||||
$repo = $em->getRepository(Image::class);
|
|
||||||
$images = new ArrayCollection(
|
$images = new ArrayCollection(
|
||||||
$repo->findBy(
|
$repoImg->findBy(
|
||||||
['site' => $site->getId()],
|
['site' => $site->getId()],
|
||||||
['sequence' => 'ASC']
|
['sequence' => 'ASC']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$repo = $em->getRepository(Document::class);
|
$repoDocs = $em->getRepository(Document::class);
|
||||||
$documents = $repo->findBySite($site->getId());
|
$documents = $repoDocs->findBySite($site->getId());
|
||||||
$repo = $em->getRepository(Bibliography::class);
|
$repoBib = $em->getRepository(Bibliography::class);
|
||||||
$bibliography = $repo->findAllBySite($site->getId());
|
$bibliography = $repoBib->findAllBySite($site->getId());
|
||||||
|
|
||||||
$site->setImages($images);
|
$site->setImages($images);
|
||||||
$site->setDocuments($documents);
|
$site->setDocuments($documents);
|
||||||
$site->setBibliography($bibliography);
|
$site->setBibliography($bibliography);
|
||||||
$repo = $em->getRepository(Site::class);
|
|
||||||
|
$sites[$key] = $site;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->json($sites);
|
return $this->json($sites);
|
||||||
|
@ -22,25 +22,35 @@ class BibliographyRepository extends ServiceEntityRepository
|
|||||||
*/
|
*/
|
||||||
public function findAllBySite(int $siteId): array
|
public function findAllBySite(int $siteId): array
|
||||||
{
|
{
|
||||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
$conn = $this->getEntityManager()->getConnection();
|
||||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Bibliography', 'b');
|
|
||||||
$query = $this->getEntityManager()->createNativeQuery(
|
$sql = '
|
||||||
'SELECT
|
SELECT
|
||||||
id,
|
b.id,
|
||||||
citazione,
|
b.citazione,
|
||||||
riferimento,
|
b.riferimento,
|
||||||
pagine
|
bs.pagine
|
||||||
FROM bibliografia b
|
FROM bibliografia b
|
||||||
JOIN bibliografia_sito
|
INNER JOIN bibliografia_sito bs ON bs.id_bibliografia = b.id
|
||||||
ON id_bibliografia = b.id
|
WHERE bs.id_sito = :siteId
|
||||||
WHERE id_sito = :id
|
ORDER BY bs.ordine ASC
|
||||||
ORDER BY ordine ASC',
|
';
|
||||||
$rsm
|
|
||||||
);
|
|
||||||
|
|
||||||
$query->setParameter('id', $siteId);
|
$stmt = $conn->prepare($sql);
|
||||||
|
$results = $stmt->executeQuery(['siteId' => $siteId])->fetchAllAssociative();
|
||||||
|
|
||||||
return $query->getResult();
|
$entities = [];
|
||||||
|
|
||||||
|
foreach ($results as $row) {
|
||||||
|
$biblio = new Bibliography();
|
||||||
|
$biblio->setId($row['id']);
|
||||||
|
$biblio->setCitation($row['citazione']);
|
||||||
|
$biblio->setReference($row['riferimento']);
|
||||||
|
$biblio->setPages($row['pagine']);
|
||||||
|
$entities[] = $biblio;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entities;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return Bibliography[]
|
* @return Bibliography[]
|
||||||
|
@ -22,28 +22,40 @@ class DocumentRepository extends ServiceEntityRepository
|
|||||||
*/
|
*/
|
||||||
public function findBySite(int $siteId): array
|
public function findBySite(int $siteId): array
|
||||||
{
|
{
|
||||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
$conn = $this->getEntityManager()->getConnection();
|
||||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Document', 'd');
|
|
||||||
$query = $this->getEntityManager()->createNativeQuery(
|
|
||||||
'SELECT
|
|
||||||
id,
|
|
||||||
titolo,
|
|
||||||
filename,
|
|
||||||
descrizione,
|
|
||||||
autori,
|
|
||||||
luogo,
|
|
||||||
tipo
|
|
||||||
FROM documento d
|
|
||||||
JOIN sito_documento
|
|
||||||
ON id_documento = d.id
|
|
||||||
WHERE id_sito = :id
|
|
||||||
',
|
|
||||||
$rsm
|
|
||||||
);
|
|
||||||
|
|
||||||
$query->setParameter('id', $siteId);
|
$sql = '
|
||||||
|
SELECT
|
||||||
|
d.id,
|
||||||
|
d.titolo,
|
||||||
|
d.filename,
|
||||||
|
d.descrizione,
|
||||||
|
d.autori,
|
||||||
|
d.tipo,
|
||||||
|
d.luogo
|
||||||
|
FROM documento d
|
||||||
|
INNER JOIN sito_documento sd ON sd.id_documento = d.id
|
||||||
|
WHERE sd.id_sito = :siteId
|
||||||
|
';
|
||||||
|
|
||||||
return $query->getResult();
|
$stmt = $conn->prepare($sql);
|
||||||
|
$results = $stmt->executeQuery(['siteId' => $siteId])->fetchAllAssociative();
|
||||||
|
|
||||||
|
$entities = [];
|
||||||
|
|
||||||
|
foreach ($results as $row) {
|
||||||
|
$document = new Document();
|
||||||
|
$document->setId($row['id']);
|
||||||
|
$document->setTitle($row['titolo']);
|
||||||
|
$document->setFilename($row['filename']);
|
||||||
|
$document->setDescription($row['descrizione']);
|
||||||
|
$document->setConservationPlace($row['luogo']);
|
||||||
|
$document->setType($row['tipo']);
|
||||||
|
$document->setAuthors($row['autori']);
|
||||||
|
$entities[] = $document;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user