← Back
Editing: ZoneRepository.php
<?php namespace App\Repository; use App\Contract\EntityFinderInterface; use App\Entity\Agency; use App\Entity\Controle; use App\Entity\Organization; use App\Entity\Solution; use App\Entity\Zone; use App\Service\SolutionService; use Doctrine\ORM\EntityManagerInterface; use Gedmo\Tree\Entity\Repository\NestedTreeRepository; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Contracts\Service\Attribute\Required; /** * @method Zone|null find($id, $lockMode = null, $lockVersion = null) * @method Zone|null findOneBy(array $criteria, array $orderBy = null) * @method Zone[] findAll() * @method Zone[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class ZoneRepository extends NestedTreeRepository implements EntityFinderInterface { private SolutionService $solutionService; public function __construct(EntityManagerInterface $manager) { parent::__construct($manager, $manager->getClassMetadata(Zone::class)); } #[Required] public function setSolutionService(SolutionService $solutionService) { $this->solutionService = $solutionService; } /** * @return Zone[] */ public function findByOrganization(Organization $organization): array { $qb = $this->createQueryBuilder('z') ->leftJoin('z.root', 'zr') ->leftJoin('zr.thematic', 't') ->leftJoin('z.items', 'i') ->leftJoin('i.adresses', 'ad') ->leftJoin('ad.agency', 'ag') ->where('ag.organization = :organization') ->setParameter('organization', $organization) ->orderBy('z.id') ->groupBy('z'); if ($this->solutionService->getCurrent()) { $qb->andWhere('t.solution = :solution') ->setParameter('solution', $this->solutionService->getCurrent()); } return $qb ->getQuery() ->getResult(); } /** * @return Zone[] */ public function findByAgency(Agency $agency, ?Solution $solution = null): array { $qb = $this->createQueryBuilder('z') ->leftJoin('z.root', 'zr') ->leftJoin('zr.thematic', 't') ->leftJoin('z.items', 'i') ->leftJoin('i.adresses', 'ad') ->where('ad.agency = :agency') ->setParameter('agency', $agency) ->orderBy('z.id') ->groupBy('z'); if ($this->solutionService->getCurrent()) { $qb->andWhere('t.solution = :solution') ->setParameter('solution', $this->solutionService->getCurrent()); } if (null !== $solution) { $qb ->andWhere('t.solution = :solution') ->setParameter('solution', $solution); } return $qb ->getQuery() ->getResult(); } public function findByManager(UserInterface $manager) { $qb = $this->createQueryBuilder('z') ->leftJoin('z.root', 'zr') ->leftJoin('zr.thematic', 't') ->leftJoin('z.items', 'i') ->leftJoin('i.adresses', 'ad') ->where('ad.manager = :manager') ->setParameter('manager', $manager) ->orderBy('z.id') ->groupBy('z'); if ($this->solutionService->getCurrent()) { $qb->andWhere('t.solution = :solution') ->setParameter('solution', $this->solutionService->getCurrent()); } return $qb ->getQuery() ->getResult(); } public function findByControl(Controle $controle) { return $this->createQueryBuilder('z') ->leftJoin('z.items', 'i') ->leftJoin('i.adresses', 'a') ->leftJoin('a.controles', 'c') ->where('c = :controle') ->setParameter('controle', $controle) ->groupBy('z') ->orderBy('z.id') ->getQuery() ->getResult(); } public function save(Zone $entity, bool $flush = false): void { $this->getEntityManager()->persist($entity); if ($flush) { $this->getEntityManager()->flush(); } } public function remove(Zone $entity, bool $flush = false): void { $this->getEntityManager()->remove($entity); if ($flush) { $this->getEntityManager()->flush(); } } public function findForAgency(Agency $agency): array { return $this->createQueryBuilder('z') ->leftJoin('z.allChildren', 'zc') ->leftJoin('zc.items', 'i') ->leftJoin('i.adresses', 'a') ->where('a.agency = :agency') ->setParameter('agency', $agency) ->groupBy('z') ->orderBy('z.id') ->getQuery() ->getResult(); } public function findForOrganization(Organization $organization): array { return $this->createQueryBuilder('z') ->leftJoin('z.allChildren', 'zc') ->leftJoin('zc.items', 'i') ->leftJoin('i.adresses', 'a') ->leftJoin('a.agency', 'ag') ->where('ag.organization = :organization') ->setParameter('organization', $organization) ->groupBy('z') ->orderBy('z.id') ->getQuery() ->getResult(); } }
Save File
Cancel