* * @method Application|null find($id, $lockMode = null, $lockVersion = null) * @method Application|null findOneBy(array $criteria, array $orderBy = null) * @method Application[] findAll() * @method Application[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class ApplicationRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Application::class); } public function getPendingQuery(): Query { $qb = $this->createQueryBuilder('application'); return $qb ->select('application', 'assignment', 'destination', 'job_profile', 'teamer') ->innerJoin('application.assignment', 'assignment') ->innerJoin('assignment.destination', 'destination') ->innerJoin('assignment.jobProfile', 'job_profile') ->innerJoin('application.teamer', 'teamer') ->where($qb->expr()->neq('application.status', ':status')) ->setParameter('status', Application::STATUS_REJECTED) ->getQuery() ; } public function getPendingForTeamerQuery(Teamer $teamer): Query { $qb = $this->createQueryBuilder('application'); return $qb ->select('application', 'assignment', 'destination', 'job_profile') ->innerJoin('application.assignment', 'assignment') ->innerJoin('assignment.destination', 'destination') ->innerJoin('assignment.jobProfile', 'job_profile') ->where($qb->expr()->andX( $qb->expr()->eq('application.teamer', ':teamer'), $qb->expr()->orX( $qb->expr()->neq('application.status', ':status'), $qb->expr()->andX( $qb->expr()->eq('application.status', ':status'), $qb->expr()->gt('destination.dateFrom', ':today') ) ) )) ->setParameter('teamer', $teamer) ->setParameter('status', Application::STATUS_REJECTED) ->setParameter('today', new \DateTime()) ->getQuery() ; } public function getPendingForTeamer(Teamer $teamer, int $limit = 5): array { return $this ->getPendingForTeamerQuery($teamer) ->setMaxResults($limit) ->getResult() ; } public function getCurrentByAssignment(Assignment $assignment): array { $qb = $this->createQueryBuilder('application'); return $qb ->select('application', 'teamer', 'feedback') ->innerJoin('application.teamer', 'teamer') ->leftJoin('teamer.feedback', 'feedback') ->where($qb->expr()->eq('application.assignment', ':assignment')) ->setParameter('assignment', $assignment) ->getQuery() ->getResult() ; } public function getNew(int $limit = 5): array { $qb = $this->createQueryBuilder('application'); return $qb ->select('application', 'assignment', 'destination', 'job_profile', 'teamer') ->innerJoin('application.assignment', 'assignment') ->innerJoin('assignment.destination', 'destination') ->innerJoin('assignment.jobProfile', 'job_profile') ->innerJoin('application.teamer', 'teamer') ->where($qb->expr()->neq('application.status', ':status')) ->orderBy('application.createdAt', 'DESC') ->setParameter('status', Application::STATUS_REJECTED) ->setMaxResults($limit) ->getQuery() ->getResult() ; } public function getCountByStatus(string $status): ?int { $qb = $this->createQueryBuilder('application'); return $qb ->select($qb->expr()->count('application')) ->where($qb->expr()->eq('application.status', ':status')) ->setParameter('status', $status) ->getQuery() ->getSingleScalarResult() ; } }