74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Document;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Document>
|
|
*/
|
|
class DocumentRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Document::class);
|
|
}
|
|
|
|
/**
|
|
* @return Document[] Returns an array of Document objects
|
|
*/
|
|
public function findBySite(int $siteId): array
|
|
{
|
|
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
|
$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);
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
// /**
|
|
// * @return Document[] Returns an array of Document objects
|
|
// */
|
|
// public function findByExampleField($value): array
|
|
// {
|
|
// return $this->createQueryBuilder('d')
|
|
// ->andWhere('d.exampleField = :val')
|
|
// ->setParameter('val', $value)
|
|
// ->orderBy('d.id', 'ASC')
|
|
// ->setMaxResults(10)
|
|
// ->getQuery()
|
|
// ->getResult()
|
|
// ;
|
|
// }
|
|
|
|
// public function findOneBySomeField($value): ?Document
|
|
// {
|
|
// return $this->createQueryBuilder('d')
|
|
// ->andWhere('d.exampleField = :val')
|
|
// ->setParameter('val', $value)
|
|
// ->getQuery()
|
|
// ->getOneOrNullResult()
|
|
// ;
|
|
// }
|
|
}
|