← Back
Editing: AgencyPrestataireRepository.php
<?php namespace App\Repository; use App\Entity\Adresse; use App\Entity\Agency; use App\Entity\AgencyPrestataire; use App\Service\SolutionService; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Security\Core\User\UserInterface; /** * @method AgencyPrestataire|null find($id, $lockMode = null, $lockVersion = null) * @method AgencyPrestataire|null findOneBy(array $criteria, array $orderBy = null) * @method AgencyPrestataire[] findAll() * @method AgencyPrestataire[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class AgencyPrestataireRepository extends ServiceEntityRepository { protected SolutionService $solutionService; public function __construct(ManagerRegistry $registry, SolutionService $solutionService) { $this->solutionService = $solutionService; parent::__construct($registry, AgencyPrestataire::class); } /** * @return int|mixed|string * * @psalm-param 'ASC'|'DESC'|'asc' $order */ public function getPrestatairesByManager(UserInterface $manager, string $order = 'asc') { return $this->createQueryBuilder('cp') ->leftJoin('cp.prestataire', 'p') ->leftJoin('p.adresses', 'a') ->andWhere('a.manager = :manager') ->andWhere('p.solution = :solution') ->setParameter('manager', $manager) ->setParameter('solution', $this->solutionService->getCurrent()) ->groupBy('p') ->orderBy('p.nom', $order) ->getQuery() ->getResult(); } public function getPrestatairesByAgency(?Agency $agencyId) { return $this->createQueryBuilder('cp') ->select('cp', 'p') ->leftJoin('cp.prestataire', 'p') ->andWhere('cp.agency = :agencyId') ->andWhere('p.solution = :solution') ->setParameter('agencyId', $agencyId) ->setParameter('solution', $this->solutionService->getCurrent()) ->orderBy('p.nom', 'ASC') ->groupBy('p') ->getQuery() ->getResult(); } public function getPrestatairesByAgencyDesc($agencyId) { return $this->createQueryBuilder('cp') ->select('cp', 'p') ->leftJoin('cp.prestataire', 'p') ->andWhere('cp.agency = :agencyId') ->andWhere('p.solution = :solution') ->setParameter('agencyId', $agencyId) ->setParameter('solution', $this->solutionService->getCurrent()) ->orderBy('p.nom', 'DESC') ->getQuery() ->getResult(); } public function getPrestataireByAdresse(Adresse $adresse) { return $this->createQueryBuilder('cp') ->select('cp', 'p') ->leftJoin('cp.prestataire', 'p') ->leftJoin('p.adresses', 'a') ->andWhere('cp.agency = :agency') ->andWhere('a.id = :adresseId') ->andWhere('p.solution = :solution') ->setParameter('agency', $adresse->getAgency()) ->setParameter('adresseId', $adresse->getId()) ->setParameter('solution', $adresse->getSolution()) ->orderBy('p.nom', 'ASC') ->getQuery() ->getResult(); } }
Save File
Cancel