243 lines
8.7 KiB
PHP
243 lines
8.7 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Assignment;
|
|
use App\Entity\Disposition;
|
|
use App\Entity\Teamer;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\ORM\Query;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Disposition>
|
|
*
|
|
* @method Disposition|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method Disposition|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method Disposition[] findAll()
|
|
* @method Disposition[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class DispositionRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Disposition::class);
|
|
}
|
|
|
|
public function getUpcomingDispositionsByTeamerQuery(Teamer $teamer): Query
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'job_profile', 'destination')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.jobProfile', 'job_profile')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->eq('disposition.teamer', ':teamer'),
|
|
$qb->expr()->orX(
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNull('assignment.dateFrom'),
|
|
$qb->expr()->gte('destination.dateFrom', ':date')
|
|
),
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNotNull('assignment.dateFrom'),
|
|
$qb->expr()->gte('assignment.dateFrom', ':date')
|
|
)
|
|
)
|
|
))
|
|
->setParameter('teamer', $teamer)
|
|
->setParameter('date', new \DateTimeImmutable())
|
|
->getQuery()
|
|
;
|
|
}
|
|
|
|
public function getUpcomingDispositionsByTeamer(Teamer $teamer, int $limit = 5): array
|
|
{
|
|
return $this
|
|
->getUpcomingDispositionsByTeamerQuery($teamer)
|
|
->setMaxResults($limit)
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function getRecentDispositionsByTeamerQuery(Teamer $teamer): Query
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'job_profile', 'destination', 'feedback')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.jobProfile', 'job_profile')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->leftJoin('disposition.feedback', 'feedback')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->eq('disposition.teamer', ':teamer'),
|
|
$qb->expr()->orX(
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNull('assignment.dateTo'),
|
|
$qb->expr()->lte('destination.dateTo', ':date')
|
|
),
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNotNull('assignment.dateTo'),
|
|
$qb->expr()->lte('assignment.dateTo', ':date')
|
|
)
|
|
)
|
|
))
|
|
->setParameter('teamer', $teamer)
|
|
->setParameter('date', new \DateTimeImmutable())
|
|
->getQuery()
|
|
;
|
|
}
|
|
|
|
public function findCurrentDispositionsByAssignment(Assignment $assignment): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'teamer', 'feedback')
|
|
->innerJoin('disposition.teamer', 'teamer')
|
|
->leftJoin('teamer.feedback', 'feedback')
|
|
->where($qb->expr()->eq('disposition.assignment', ':assignment'))
|
|
->setParameter('assignment', $assignment)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findRecentDispositionsByTeamer(Teamer $teamer, int $limit = 5): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'destination', 'feedback')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->leftJoin('disposition.feedback', 'feedback')
|
|
->where($qb->expr()->eq('disposition.teamer', ':teamer'))
|
|
->setParameter('teamer', $teamer)
|
|
->orderBy('destination.dateFrom', 'DESC')
|
|
->setMaxResults($limit)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findCurrentDispositionsByTeamer(Teamer $teamer): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'destination')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->eq('disposition.teamer', ':teamer'),
|
|
$qb->expr()->in('disposition.status', ':status')
|
|
))
|
|
->setParameter('teamer', $teamer)
|
|
->setParameter('status', [
|
|
Disposition::STATUS_NEW,
|
|
Disposition::STATUS_CONFIRMED,
|
|
])
|
|
->orderBy('destination.dateFrom', 'ASC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findNewDispositionsByHotelBusProIds(array $hotelBusProIds): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'destination')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->in('destination.hotelBusProId', ':hotelBusProIds'),
|
|
$qb->expr()->gte('destination.dateTo', ':dateTo'),
|
|
$qb->expr()->eq('disposition.status', ':status')
|
|
))
|
|
->setParameter('hotelBusProIds', $hotelBusProIds)
|
|
->setParameter('dateTo', new \DateTimeImmutable())
|
|
->setParameter('status', Disposition::STATUS_NEW)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function getDispositionsWithPendingFeedbackQuery(array $hotelBusProIds = null): Query
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
$qb
|
|
->select('disposition', 'assignment', 'destination', 'feedback')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->leftJoin('disposition.feedback', 'feedback')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->eq('disposition.status', ':status'),
|
|
$qb->expr()->isNull('feedback'),
|
|
$qb->expr()->lt('destination.dateTo', ':dateTo')
|
|
))
|
|
->setParameter('status', Disposition::STATUS_COMPLETED)
|
|
->setParameter('dateTo', new \DateTimeImmutable())
|
|
;
|
|
|
|
if (null !== $hotelBusProIds) {
|
|
$qb
|
|
->andWhere($qb->expr()->in('destination.hotelBusProId', ':hotelBusProIds'))
|
|
->setParameter('hotelBusProIds', $hotelBusProIds)
|
|
;
|
|
}
|
|
|
|
return $qb->getQuery();
|
|
}
|
|
|
|
public function findDispositionsWithPendingFeedback(): array
|
|
{
|
|
return $this
|
|
->getDispositionsWithPendingFeedbackQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findDispositionsWithPendingFeedbackByHotelBusProIds(array $hotelBusProIds): array
|
|
{
|
|
return $this
|
|
->getDispositionsWithPendingFeedbackQuery($hotelBusProIds)
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* @return Disposition[]|array
|
|
*/
|
|
public function findEndedDispositions(): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->neq('disposition.status', ':status'),
|
|
$qb->expr()->orX(
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNotNull('assignment.dateTo'),
|
|
$qb->expr()->lte('assignment.dateTo', ':dateTo')
|
|
),
|
|
$qb->expr()->lte('destination.dateTo', ':dateTo')
|
|
)
|
|
))
|
|
->setParameters([
|
|
'status' => Disposition::STATUS_COMPLETED,
|
|
'dateTo' => new \DateTimeImmutable(),
|
|
])
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
}
|