* * @method Upload|null find($id, $lockMode = null, $lockVersion = null) * @method Upload|null findOneBy(array $criteria, array $orderBy = null) * @method Upload[] findAll() * @method Upload[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class UploadRepository extends ServiceEntityRepository { use QueryHelperTrait; public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Upload::class); } public function getGlobalListQuery(): Query { $qb = $this->createQueryBuilder('upload'); return $qb ->where($qb->expr()->eq('upload.type', ':type')) ->setParameter('type', Upload::TYPE_DOCUMENT) ->getQuery() ; } public function getGlobal(): array { return $this ->getGlobalListQuery() ->getResult() ; } public function getAutocompletionData(string $search): array { $qb = $this->createQueryBuilder('upload'); $documents = $qb ->where($qb->expr()->orX( $qb->expr()->like('upload.originalFilename', ':filename'), $qb->expr()->like('upload.displayName', ':filename') )) ->setParameter('filename', '%'.$this->escapeLikeWildcards($search).'%') ->orderBy('upload.originalFilename', 'ASC') ->getQuery() ->getResult() ; $data = [ [ 'value' => '', 'text' => '...', ], ]; foreach ($documents as $document) { /** @var Upload $document */ $data[] = [ 'value' => $document->getId(), 'text' => $document->getDisplayName() ?? $document->getOriginalFilename(), ]; } return $data; } public function getUploadListQuery(DocumentFilterDto $filterDto): Query { $qb = $this->createQueryBuilder('upload'); $qb ->select('upload', 'disposition', 'assignment', 'job_profile', 'destination', 'teamer') ->innerJoin('upload.disposition', 'disposition') ->innerJoin('disposition.assignment', 'assignment') ->innerJoin('assignment.jobProfile', 'job_profile') ->innerJoin('assignment.destination', 'destination') ->innerJoin('disposition.teamer', 'teamer') ->addOrderBy('FIELD(upload.status, :new, :checked)', 'ASC') ->setParameter('new', Upload::STATUS_NEW) ->setParameter('checked', Upload::STATUS_CHECKED) ; if (null !== $teamer = $filterDto->getTeamer()) { $qb ->andWhere($qb->expr()->eq('upload.teamer', ':teamer')) ->setParameter('teamer', $teamer) ; } if (null !== $type = $filterDto->getType()) { $qb ->andWhere($qb->expr()->eq('upload.type', ':type')) ->setParameter('type', $type) ; } if (null !== $dateFrom = $filterDto->getDateFrom()) { $qb ->andWhere($qb->expr()->gte('destination.dateFrom', ':dateFrom')) ->setParameter('dateFrom', $dateFrom) ; } if (null !== $dateTo = $filterDto->getDateTo()) { $qb ->andWhere($qb->expr()->lte('destination.dateTo', ':dateTo')) ->setParameter('dateTo', $dateTo) ; } return $qb->getQuery(); } public function getNew(int $limit = 5): array { $qb = $this->createQueryBuilder('upload'); return $qb ->select('upload', 'owner', 'teamer', 'disposition', 'assignment') ->innerJoin('upload.owner', 'owner') ->innerJoin('owner.teamer', 'teamer') ->leftJoin('upload.disposition', 'disposition') ->leftJoin('disposition.assignment', 'assignment') ->where($qb->expr()->andX( $qb->expr()->in('upload.type', ':type'), $qb->expr()->in('upload.status', ':status') )) ->orderBy('upload.createdAt', 'DESC') ->setParameter('type', [Upload::TYPE_CONTRACT, Upload::TYPE_INVOICE]) ->setParameter('status', [Upload::STATUS_NEW, Upload::STATUS_PENDING]) ->setMaxResults($limit) ->getQuery() ->getResult() ; } public function getCountByStatus(string $status): ?int { $qb = $this->createQueryBuilder('upload'); return $qb ->select($qb->expr()->count('upload')) ->where($qb->expr()->andX( $qb->expr()->in('upload.type', ':type'), $qb->expr()->eq('upload.status', ':status') )) ->setParameter('type', [Upload::TYPE_CONTRACT, Upload::TYPE_INVOICE]) ->setParameter('status', $status) ->getQuery() ->getSingleScalarResult() ; } }