113 lines
4.0 KiB
PHP
113 lines
4.0 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 getUpcomingQuery(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 getRecentQuery(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.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 getCurrentByAssignment(Assignment $assignment): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'teamer')
|
|
->innerJoin('disposition.teamer', 'teamer')
|
|
->where($qb->expr()->eq('disposition.assignment', ':assignment'))
|
|
->setParameter('assignment', $assignment)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function getRecentByTeamer(Teamer $teamer, int $limit = 5): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'destination')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->where($qb->expr()->eq('disposition.teamer', ':teamer'))
|
|
->setParameter('teamer', $teamer)
|
|
->orderBy('destination.dateFrom', 'DESC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
}
|