Retrieve ordered results
This commit is contained in:
parent
7ab75a30fb
commit
321a6a4bea
@ -17,7 +17,7 @@ class FindingController extends AbstractController
|
|||||||
{
|
{
|
||||||
$repo = $em->getRepository(Finding::class);
|
$repo = $em->getRepository(Finding::class);
|
||||||
|
|
||||||
$findings = $repo->findAll();
|
$findings = $repo->findBy([], ['label' => 'ASC']);
|
||||||
|
|
||||||
foreach($findings as $key => $finding) {
|
foreach($findings as $key => $finding) {
|
||||||
$coords = $repo->coordinates($finding->getId());
|
$coords = $repo->coordinates($finding->getId());
|
||||||
|
@ -20,7 +20,7 @@ class NotConservedController extends AbstractController
|
|||||||
//$repoBib = $em->getRepository(Bibliography::class);
|
//$repoBib = $em->getRepository(Bibliography::class);
|
||||||
$repoImg = $em->getRepository(Image::class);
|
$repoImg = $em->getRepository(Image::class);
|
||||||
|
|
||||||
$records = $repo->findBy([], ['id' => 'ASC']);
|
$records = $repo->findBy([], ['label' => 'ASC']);
|
||||||
|
|
||||||
// Terrible? N+1..
|
// Terrible? N+1..
|
||||||
foreach ($records as $key => $record) {
|
foreach ($records as $key => $record) {
|
||||||
|
@ -18,7 +18,7 @@ class PrehistoricController extends AbstractController
|
|||||||
$repo = $em->getRepository(Prehistoric::class);
|
$repo = $em->getRepository(Prehistoric::class);
|
||||||
//$repoBib = $em->getRepository(Bibliography::class);
|
//$repoBib = $em->getRepository(Bibliography::class);
|
||||||
|
|
||||||
$records = $repo->findBy([], ['id' => 'ASC']);
|
$records = $repo->findBy([], ['label' => 'ASC']);
|
||||||
|
|
||||||
// Terrible? N+1..
|
// Terrible? N+1..
|
||||||
foreach ($records as $key => $record) {
|
foreach ($records as $key => $record) {
|
||||||
|
@ -20,7 +20,7 @@ class SiteController extends AbstractController
|
|||||||
{
|
{
|
||||||
$repo = $em->getRepository(Site::class);
|
$repo = $em->getRepository(Site::class);
|
||||||
|
|
||||||
$sites = $repo->findAll();
|
$sites = $repo->findBy([], ['label' => 'ASC']);
|
||||||
|
|
||||||
// TODO N+1...
|
// TODO N+1...
|
||||||
foreach($sites as $key => $site) {
|
foreach($sites as $key => $site) {
|
||||||
|
@ -55,51 +55,71 @@ class BibliographyRepository extends ServiceEntityRepository
|
|||||||
/**
|
/**
|
||||||
* @return Bibliography[]
|
* @return Bibliography[]
|
||||||
*/
|
*/
|
||||||
public function findAllByNotConserved(int $notConserId): array
|
public function findAllByNotConserved(int $notConservedId): 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_non_conser
|
INNER JOIN bibliografia_non_conser bs ON bs.id_bibliografia = b.id
|
||||||
ON id_bibliografia = b.id
|
WHERE bs.id_non_conser = :notConservedId
|
||||||
WHERE id_non_conser = :id
|
ORDER BY bs.ordine ASC
|
||||||
ORDER BY ordine ASC',
|
';
|
||||||
$rsm
|
|
||||||
);
|
|
||||||
|
|
||||||
$query->setParameter('id', $notConserId);
|
$stmt = $conn->prepare($sql);
|
||||||
|
$results = $stmt->executeQuery(['notConservedId' => $notConservedId])->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[]
|
||||||
*/
|
*/
|
||||||
public function findAllByFinding(int $findingId): array
|
public function findAllByFinding(int $findingId): 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_rinvenim
|
INNER JOIN bibliografia_rinvenim bs ON bs.id_bibliografia = b.id
|
||||||
ON id_bibliografia = b.id
|
WHERE bs.id_rinvenimento = :findingId
|
||||||
WHERE id_rinvenimento = :id
|
ORDER BY bs.ordine ASC
|
||||||
ORDER BY ordine ASC',
|
';
|
||||||
$rsm
|
|
||||||
);
|
|
||||||
|
|
||||||
$query->setParameter('id', $findingId);
|
$stmt = $conn->prepare($sql);
|
||||||
|
$results = $stmt->executeQuery(['findingId' => $findingId])->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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ class DocumentRepository extends ServiceEntityRepository
|
|||||||
FROM documento d
|
FROM documento d
|
||||||
INNER JOIN sito_documento sd ON sd.id_documento = d.id
|
INNER JOIN sito_documento sd ON sd.id_documento = d.id
|
||||||
WHERE sd.id_sito = :siteId
|
WHERE sd.id_sito = :siteId
|
||||||
|
ORDER BY d.titolo ASC
|
||||||
';
|
';
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
@ -63,28 +64,41 @@ class DocumentRepository extends ServiceEntityRepository
|
|||||||
*/
|
*/
|
||||||
public function findByNotConserved(int $notConservedId): array
|
public function findByNotConserved(int $notConservedId): 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 non_conserv_documento
|
|
||||||
ON id_documento = d.id
|
|
||||||
WHERE id_non_conserv = :id
|
|
||||||
',
|
|
||||||
$rsm
|
|
||||||
);
|
|
||||||
|
|
||||||
$query->setParameter('id', $notConservedId);
|
$sql = '
|
||||||
|
SELECT
|
||||||
|
d.id,
|
||||||
|
d.titolo,
|
||||||
|
d.filename,
|
||||||
|
d.descrizione,
|
||||||
|
d.autori,
|
||||||
|
d.tipo,
|
||||||
|
d.luogo
|
||||||
|
FROM documento d
|
||||||
|
INNER JOIN non_conserv_documento sd ON sd.id_documento = d.id
|
||||||
|
WHERE sd.id_non_conserv = :notConservedId
|
||||||
|
ORDER BY d.titolo ASC
|
||||||
|
';
|
||||||
|
|
||||||
return $query->getResult();
|
$stmt = $conn->prepare($sql);
|
||||||
|
$results = $stmt->executeQuery(['notConservedId' => $notConservedId])->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;
|
||||||
}
|
}
|
||||||
// /**
|
// /**
|
||||||
// * @return Document[] Returns an array of Document objects
|
// * @return Document[] Returns an array of Document objects
|
||||||
|
Loading…
Reference in New Issue
Block a user