← Back
Editing: PrestataireRepository.php
<?php namespace App\Repository; use App\Entity\Prestataire; use App\Entity\Solution; use App\Service\SolutionService; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ManagerRegistry; /** * @method Prestataire|null find($id, $lockMode = null, $lockVersion = null) * @method Prestataire|null findOneBy(array $criteria, array $orderBy = null) * @method Prestataire[] findAll() * @method Prestataire[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class PrestataireRepository extends ServiceEntityRepository { use OptionsTrait; private ?Solution $solution; public function __construct(ManagerRegistry $registry, SolutionService $solutionService) { $this->solution = $solutionService->getCurrent(); parent::__construct($registry, Prestataire::class); } public function fetchByAgencies(array $agenciesId): array { return $this->findProvidersByAgenciesQuery($agenciesId)->getQuery()->getResult(); } /** * Get data for perf graph (nb alerts and average note). */ public function fetchPerfByAgencies(array $agenciesId): array { $qb = $this->createQueryBuilder('p') ->select('AVG(c.averageNote) as avgNote') ->addSelect('COUNT(c.id) as nbControls') ->addSelect('COUNT(al.id) as nbAlerts') ->addSelect('p.id as customId') ->addSelect('p.nom as name') ->leftJoin('p.adresses', 'a') ->leftJoin('a.controles', 'c') ->leftJoin('c.alertes', 'al') ->where('a.agency IN ('.implode(',', $agenciesId).')') ->andWhere('c.valide = 1'); $this->addOptions($qb); $qb->groupBy('p'); return $qb ->getQuery() ->getResult(); } public function findProvidersByAgenciesQuery(array $agenciesId, ?Solution $solution = null): QueryBuilder { if (!$solution) { $solution = $this->solution; } return $this->createQueryBuilder('p') ->leftJoin('p.adresses', 'a') ->where('p.solution = :solution') ->andWhere('a.agency IN ('.implode(',', $agenciesId).')') ->setParameter('solution', $solution); } public function fetchNotesByAgencies(array $agenciesId) { $qb = $this->createQueryBuilder('p') ->select('AVG(n.note) as avgNote') ->addSelect('p as provider') ->leftJoin('p.agencyPrestataires', 'cp') ->leftJoin('p.adresses', 'a') ->leftJoin('a.controles', 'c') ->leftJoin('c.notes', 'n') ->where('cp.agency IN ('.implode(',', $agenciesId).')') ->groupBy('p'); $qb = $this->addOptions($qb); return $qb->getQuery()->getResult(); } }
Save File
Cancel