112 lines
3.5 KiB
PHP
112 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Assignment;
|
|
use App\Entity\Teamer;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\ORM\Query;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Assignment>
|
|
*
|
|
* @method Assignment|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method Assignment|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method Assignment[] findAll()
|
|
* @method Assignment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class AssignmentRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Assignment::class);
|
|
}
|
|
|
|
public function getListQuery(Teamer $teamer = null): Query
|
|
{
|
|
$qb = $this->createQueryBuilder('assignment');
|
|
|
|
$qb
|
|
->select('assignment', 'destination', 'job_profile', 'application', 'disposition')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->innerJoin('assignment.jobProfile', 'job_profile')
|
|
->leftJoin('assignment.applications', 'application')
|
|
->leftJoin('assignment.dispositions', 'disposition')
|
|
;
|
|
|
|
if (null !== $teamer) {
|
|
$qb
|
|
->where($qb->expr()->eq('application.teamer', ':teamer'))
|
|
->setParameter('teamer', $teamer)
|
|
;
|
|
}
|
|
|
|
return $qb->getQuery();
|
|
}
|
|
|
|
public function getBookmarkQueryForTeamer(Teamer $teamer): Query
|
|
{
|
|
$qb = $this->createQueryBuilder('assignment');
|
|
|
|
$qb
|
|
->select('assignment', 'destination', 'job_profile')
|
|
->innerJoin('assignment.teamers', 'teamer', 'WITH', 'teamer = :teamer')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->innerJoin('assignment.jobProfile', 'job_profile')
|
|
->leftJoin('assignment.applications', 'application')
|
|
->setParameter('teamer', $teamer)
|
|
;
|
|
|
|
return $qb->getQuery();
|
|
}
|
|
|
|
public function getFilterOptions(): array
|
|
{
|
|
$options = [];
|
|
|
|
// Date range
|
|
$qb = $this->createQueryBuilder('assignment');
|
|
$result = $qb
|
|
->select('MIN(destination.dateFrom) minDate', 'MAX(destination.dateTo) maxDate')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->getQuery()
|
|
->getSingleResult()
|
|
;
|
|
|
|
$options['minDate'] = $result['minDate'];
|
|
$options['maxDate'] = $result['maxDate'];
|
|
|
|
// Job-profiles
|
|
$qb = $this->createQueryBuilder('assignment');
|
|
$result = $qb
|
|
->select('job_profile.id', 'job_profile.name')
|
|
->innerJoin('assignment.jobProfile', 'job_profile')
|
|
->orderBy('job_profile.name', 'ASC')
|
|
->getQuery()
|
|
->getArrayResult()
|
|
;
|
|
|
|
foreach ($result as $row) {
|
|
$options['jobProfiles'][$row['id']] = $row['name'];
|
|
}
|
|
|
|
// Products
|
|
$qb = $this->createQueryBuilder('assignment');
|
|
$result = $qb
|
|
->select('destination.id id', 'destination.product product', 'destination.hotel hotel')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->orderBy('destination.product', 'ASC')
|
|
->groupBy('destination.id')
|
|
->getQuery()
|
|
->getArrayResult()
|
|
;
|
|
|
|
foreach ($result as $row) {
|
|
$options['products'][$row['id']] = $row['product'];
|
|
}
|
|
|
|
return $options;
|
|
}
|
|
}
|