Retrieve ordered results
This commit is contained in:
@@ -55,51 +55,71 @@ class BibliographyRepository extends ServiceEntityRepository
|
||||
/**
|
||||
* @return Bibliography[]
|
||||
*/
|
||||
public function findAllByNotConserved(int $notConserId): array
|
||||
public function findAllByNotConserved(int $notConservedId): array
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Bibliography', 'b');
|
||||
$query = $this->getEntityManager()->createNativeQuery(
|
||||
'SELECT
|
||||
id,
|
||||
citazione,
|
||||
riferimento,
|
||||
pagine
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
b.id,
|
||||
b.citazione,
|
||||
b.riferimento,
|
||||
bs.pagine
|
||||
FROM bibliografia b
|
||||
JOIN bibliografia_non_conser
|
||||
ON id_bibliografia = b.id
|
||||
WHERE id_non_conser = :id
|
||||
ORDER BY ordine ASC',
|
||||
$rsm
|
||||
);
|
||||
INNER JOIN bibliografia_non_conser bs ON bs.id_bibliografia = b.id
|
||||
WHERE bs.id_non_conser = :notConservedId
|
||||
ORDER BY bs.ordine ASC
|
||||
';
|
||||
|
||||
$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[]
|
||||
*/
|
||||
public function findAllByFinding(int $findingId): array
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Bibliography', 'b');
|
||||
$query = $this->getEntityManager()->createNativeQuery(
|
||||
'SELECT
|
||||
id,
|
||||
citazione,
|
||||
riferimento,
|
||||
pagine
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
b.id,
|
||||
b.citazione,
|
||||
b.riferimento,
|
||||
bs.pagine
|
||||
FROM bibliografia b
|
||||
JOIN bibliografia_rinvenim
|
||||
ON id_bibliografia = b.id
|
||||
WHERE id_rinvenimento = :id
|
||||
ORDER BY ordine ASC',
|
||||
$rsm
|
||||
);
|
||||
INNER JOIN bibliografia_rinvenim bs ON bs.id_bibliografia = b.id
|
||||
WHERE bs.id_rinvenimento = :findingId
|
||||
ORDER BY bs.ordine ASC
|
||||
';
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user