← Back
Editing: AgencyRepository.php
<?php namespace App\Repository; use App\Entity\Agency; use App\Entity\Organization; use App\Service\SolutionService; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ManagerRegistry; /** * @method Agency|null find($id, $lockMode = null, $lockVersion = null) * @method Agency|null findOneBy(array $criteria, array $orderBy = null) * @method Agency[] findAll() * @method Agency[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class AgencyRepository extends ServiceEntityRepository { use OptionsTrait; private SolutionService $splutionService; public function __construct(ManagerRegistry $registry, SolutionService $solutionService) { $this->splutionService = $solutionService; parent::__construct($registry, Agency::class); } /** * @return Agency[] */ public function getAgencysWithSearch($name = null): array { $qb = $this->createQueryBuilder('a'); $qb->leftJoin('a.solutions', 's') ->where('s = :solution'); if ($name) { $qb->andWhere('a.nom LIKE :nom') ->setParameter('nom', '%'.$name.'%'); } $qb->setParameter('solution', $this->splutionService->getCurrent()) ->orderBy('a.nom', 'ASC'); return $qb->getQuery()->getResult(); } public function getAgenciesByOrganizationQueryBuilder(Organization $organization): QueryBuilder { return $this->createQueryBuilder('a') ->leftJoin('a.solutions', 's') ->where('s = :solution') ->andWhere('a.organization = :organization') ->setParameter('organization', $organization) ->setParameter('solution', $this->splutionService->getCurrent()) ->orderBy('a.nom', 'ASC'); } public function getAgenciesByOrganizationByMonth(Organization $organization): mixed { $qb = $this->createQueryBuilder('acy') ->select('acy.nom as name') ->addSelect('DATE_FORMAT(c.dateRealisation, \'%Y-%m\') as month') ->addSelect('acy.id as id') ->addSelect('COUNT(c.id) as cnt') ->leftJoin('acy.adresses', 'a'); $qb = $this->leftJoinControlsWithOptions($qb, 'a.controles'); $qb ->andWhere('acy.organization = :organization') ->groupBy('month') ->addGroupBy('acy') ->orderBy('month') ->setParameter('organization', $organization); $qb = $this->addOptions($qb); return $qb->getQuery()->getResult(); } /** * @return Agency[] */ public function getByOrganizationByControl( Organization $organization, ?int $limit = null, ?array $sort = null ): array { $qb = $this->createQueryBuilder('acy'); $qb ->select('acy.nom as name') ->addSelect('acy.id as id') ->addSelect('COUNT(c.id) as cnt') ->leftJoin('acy.adresses', 'a') ->leftJoin('a.controles', 'c') ->andWhere('acy.organization = :organization') ->groupBy('acy') ->setParameter('organization', $organization); if (null !== $limit) { $qb ->setMaxResults($limit); } if (null !== $sort) { $qb->orderBy($sort[0], $sort[1]); } $qb = $this->addOptions($qb); return $qb->getQuery()->getResult(); } /** * @return Agency[] */ public function findWithoutDefaultAddressItems(): array { $qb = $this->createQueryBuilder('acy') ->leftJoin('acy.defaultAddressItems', 'a') ->groupBy('acy') ->having('COUNT(a.id) = 0'); return $qb->getQuery()->getResult(); } }
Save File
Cancel