Prehistoric biblio
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Controller;
|
||||
|
||||
use App\Entity\Image;
|
||||
use App\Entity\Prehistoric;
|
||||
//use App\Entity\Bibliography;
|
||||
use App\Entity\Bibliography;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
@@ -48,10 +48,10 @@ class PrehistoricController extends AbstractController
|
||||
{
|
||||
$repo = $em->getRepository(Prehistoric::class);
|
||||
$coordinates = $repo->coordinates($prehistoric->getId());
|
||||
//$repo = $em->getRepository(Bibliography::class);
|
||||
$repo = $em->getRepository(Bibliography::class);
|
||||
|
||||
//$biblio = $repo->findAllByNotConserved($prehistoric->getId());
|
||||
//$notConserved->setBibliographies($biblio);
|
||||
$biblio = $repo->findAllByPrehistoric($prehistoric->getId());
|
||||
$prehistoric->setBibliography($biblio);
|
||||
|
||||
$prehistoric->setLat($coordinates['lat']);
|
||||
$prehistoric->setLng($coordinates['lng']);
|
||||
|
||||
@@ -48,6 +48,11 @@ class Prehistoric implements \JsonSerializable
|
||||
*/
|
||||
private ?array $images = null;
|
||||
|
||||
/**
|
||||
* @var Bibliography[] $bibliography
|
||||
*/
|
||||
private ?array $bibliography = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -198,6 +203,18 @@ class Prehistoric implements \JsonSerializable
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBibliography(): ?array
|
||||
{
|
||||
return $this->bibliography;
|
||||
}
|
||||
|
||||
public function setBibliography(array $bibliography): static
|
||||
{
|
||||
$this->bibliography = $bibliography;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
@@ -211,6 +228,7 @@ class Prehistoric implements \JsonSerializable
|
||||
'label' => $this->label,
|
||||
'municipality' => $this->municipality,
|
||||
'coordinates' => [$this->lat, $this->lng],
|
||||
'bibliography' => $this->bibliography,
|
||||
'images' => $this->images,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -155,6 +155,41 @@ class BibliographyRepository extends ServiceEntityRepository
|
||||
$entities[] = $biblio;
|
||||
}
|
||||
|
||||
return $entities;
|
||||
}
|
||||
/**
|
||||
* @return Bibliography[]
|
||||
*/
|
||||
public function findAllByPrehistoric(int $prehistoricId): array
|
||||
{
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
b.id,
|
||||
b.citazione,
|
||||
b.riferimento,
|
||||
br.pagine
|
||||
FROM bibliografia b
|
||||
INNER JOIN bibliografia_preistoria br ON br.id_bibliografia = b.id
|
||||
WHERE br.id_preistoria = :prehistoricId
|
||||
ORDER BY br.ordine ASC
|
||||
';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$results = $stmt->executeQuery(['prehistoricId' => $prehistoricId])->fetchAllAssociative();
|
||||
|
||||
$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