Test relations for bibliography
This commit is contained in:
		
							parent
							
								
									0a41ff4a7b
								
							
						
					
					
						commit
						a2f518ee15
					
				| @ -3,6 +3,7 @@ | |||||||
| namespace App\Controller; | namespace App\Controller; | ||||||
| 
 | 
 | ||||||
| use App\Entity\Bibliography; | use App\Entity\Bibliography; | ||||||
|  | use App\Entity\Collection; | ||||||
| use App\Form\BibliographyType; | use App\Form\BibliographyType; | ||||||
| //use App\Security\Voter\VocabVoter;
 | //use App\Security\Voter\VocabVoter;
 | ||||||
| use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||||
| @ -17,6 +18,11 @@ class BibliographyController extends AbstractController | |||||||
|     #[Route('/bibliography/{id<\d+>}', name: 'app_bibliography')]
 |     #[Route('/bibliography/{id<\d+>}', name: 'app_bibliography')]
 | ||||||
|     public function index(Bibliography $bibliography, EntityManagerInterface $em): Response |     public function index(Bibliography $bibliography, EntityManagerInterface $em): Response | ||||||
|     { |     { | ||||||
|  |         $repo = $em->getRepository(Collection::class); | ||||||
|  |         $collections = $repo->findAllByBibliography($bibliography->getId()); | ||||||
|  | 
 | ||||||
|  |         $bibliography->setCollections($collections); | ||||||
|  | 
 | ||||||
|         return $this->render('bibliography/index.html.twig', [ |         return $this->render('bibliography/index.html.twig', [ | ||||||
|             'controller_name' => 'BibliographyController', |             'controller_name' => 'BibliographyController', | ||||||
|             'record' => $bibliography, |             'record' => $bibliography, | ||||||
|  | |||||||
| @ -14,7 +14,8 @@ class CollectionController extends AbstractController | |||||||
|     #[Route('/collection/{id<\d+>}', name: 'app_collection')]
 |     #[Route('/collection/{id<\d+>}', name: 'app_collection')]
 | ||||||
|     public function index(Collection $collection, EntityManagerInterface $em): Response |     public function index(Collection $collection, EntityManagerInterface $em): Response | ||||||
|     { |     { | ||||||
|         $bibliographies = $em->getRepository(Bibliography::class)->findAllCollection($collection->getId()); |         $repo = $em->getRepository(Bibliography::class); | ||||||
|  |         $bibliographies = $repo->findAllByCollection($collection->getId()); | ||||||
| 
 | 
 | ||||||
|         $collection->setBibliographies($bibliographies); |         $collection->setBibliographies($bibliographies); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,15 +2,14 @@ | |||||||
| 
 | 
 | ||||||
| namespace App\Entity; | namespace App\Entity; | ||||||
| 
 | 
 | ||||||
| //use App\Repository\UserRepository;
 | use App\Repository\CollectionRepository; | ||||||
| 
 |  | ||||||
| use DateTimeImmutable; | use DateTimeImmutable; | ||||||
| use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||||
| use Doctrine\DBAL\Types\Types; | use Doctrine\DBAL\Types\Types; | ||||||
| use App\RecordStatus; | use App\RecordStatus; | ||||||
| use Doctrine\Common\Collections\Collection as DoctrineCollection; | use Doctrine\Common\Collections\Collection as DoctrineCollection; | ||||||
| 
 | 
 | ||||||
| #[ORM\Entity()]
 | #[ORM\Entity(repositoryClass: CollectionRepository::class)]
 | ||||||
| #[ORM\Table(name: 'collection')]
 | #[ORM\Table(name: 'collection')]
 | ||||||
| class Collection | class Collection | ||||||
| { | { | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ class BibliographyRepository extends ServiceEntityRepository | |||||||
|         parent::__construct($registry, Bibliography::class); |         parent::__construct($registry, Bibliography::class); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function findAllCollection(int $collectionId): ?ArrayCollection |     public function findAllByCollection(int $collectionId): ?ArrayCollection | ||||||
|     { |     { | ||||||
|         $rsm = new ResultSetMappingBuilder($this->getEntityManager()); |         $rsm = new ResultSetMappingBuilder($this->getEntityManager()); | ||||||
|         $rsm->addRootEntityFromClassMetadata('App\Entity\Bibliography', 'b'); |         $rsm->addRootEntityFromClassMetadata('App\Entity\Bibliography', 'b'); | ||||||
|  | |||||||
| @ -3,9 +3,10 @@ | |||||||
| namespace App\Repository; | namespace App\Repository; | ||||||
| 
 | 
 | ||||||
| use App\Entity\Collection; | use App\Entity\Collection; | ||||||
| use App\Repository\BibliographyRepository; |  | ||||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||||
| use Doctrine\Persistence\ManagerRegistry; | use Doctrine\Persistence\ManagerRegistry; | ||||||
|  | use Doctrine\Common\Collections\ArrayCollection; | ||||||
|  | use Doctrine\ORM\Query\ResultSetMappingBuilder; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @extends ServiceEntityRepository<Collection> |  * @extends ServiceEntityRepository<Collection> | ||||||
| @ -16,5 +17,24 @@ class CollectionRepository extends ServiceEntityRepository | |||||||
|     { |     { | ||||||
|         parent::__construct($registry, Collection::class); |         parent::__construct($registry, Collection::class); | ||||||
|     } |     } | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
|  |     public function findAllByBibliography(int $biblioId): ?ArrayCollection | ||||||
|  |     { | ||||||
|  |         $rsm = new ResultSetMappingBuilder($this->getEntityManager()); | ||||||
|  |         $rsm->addRootEntityFromClassMetadata('App\Entity\Collection', 'c'); | ||||||
|  | 
 | ||||||
|  |         $query = $this->getEntityManager()->createNativeQuery( | ||||||
|  |             "SELECT id, stato, editor, tit_coll, data_coll
 | ||||||
|  |             FROM collection c | ||||||
|  |             JOIN rel_riferimento_collezione | ||||||
|  |             ON Collezione_id_coll = id | ||||||
|  |             WHERE Bibliografia_id_bib = :biblioId",
 | ||||||
|  |             $rsm | ||||||
|  |         ); | ||||||
|  |         $query->setParameter('biblioId', $biblioId); | ||||||
|  | 
 | ||||||
|  |         $collections = new ArrayCollection($query->getResult()); | ||||||
|  | 
 | ||||||
|  |         return $collections; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user