feat: exclude unavailable assignments from list for teamer
This commit is contained in:
@@ -350,6 +350,19 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
|
|||||||
return $this->applications;
|
return $this->applications;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getApplicationByTeamer(Teamer $teamer): ?Application
|
||||||
|
{
|
||||||
|
$applications = $this->applications->filter(function (Application $application) use ($teamer) {
|
||||||
|
return $application->getTeamer() === $teamer;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (0 === count($applications)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $applications->first();
|
||||||
|
}
|
||||||
|
|
||||||
public function getValidApplications(): Collection
|
public function getValidApplications(): Collection
|
||||||
{
|
{
|
||||||
return $this->applications->filter(function (Application $application) {
|
return $this->applications->filter(function (Application $application) {
|
||||||
|
|||||||
@@ -50,6 +50,33 @@ class AssignmentRepository extends ServiceEntityRepository
|
|||||||
|
|
||||||
public function getListQueryForTeamer(Teamer $teamer, AssignmentFilterDto $filterDto): Query
|
public function getListQueryForTeamer(Teamer $teamer, AssignmentFilterDto $filterDto): Query
|
||||||
{
|
{
|
||||||
|
// Find ids of assignments with available slots first
|
||||||
|
$qb = $this->createQueryBuilder('assignment');
|
||||||
|
|
||||||
|
$availableAssignments = $qb
|
||||||
|
->select('assignment.id')
|
||||||
|
->leftJoin('assignment.dispositions', 'disposition')
|
||||||
|
->innerJoin('assignment.destination', 'destination')
|
||||||
|
->where($qb->expr()->andX(
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->gt('destination.dateFrom', ':now'),
|
||||||
|
$qb->expr()->andX(
|
||||||
|
$qb->expr()->isNotNull('assignment.dateFrom'),
|
||||||
|
$qb->expr()->gt('assignment.dateFrom', ':now')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
$qb->expr()->isNull('assignment.deletedAt')
|
||||||
|
))
|
||||||
|
->groupBy('assignment')
|
||||||
|
->having($qb->expr()->gt('assignment.availableDispositions', $qb->expr()->count('disposition.id')))
|
||||||
|
->setParameter('now', new \DateTimeImmutable())
|
||||||
|
->getQuery()
|
||||||
|
->getArrayResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
// Extract ids of available assignments for the following query
|
||||||
|
$availableAssignmentsIds = array_column($availableAssignments, 'id');
|
||||||
|
|
||||||
$qb = $this->createQueryBuilder('assignment');
|
$qb = $this->createQueryBuilder('assignment');
|
||||||
|
|
||||||
$qb
|
$qb
|
||||||
@@ -64,7 +91,8 @@ class AssignmentRepository extends ServiceEntityRepository
|
|||||||
$qb->expr()->gt('assignment.dateFrom', ':now')
|
$qb->expr()->gt('assignment.dateFrom', ':now')
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
$qb->expr()->isNull('assignment.deletedAt')
|
$qb->expr()->isNull('assignment.deletedAt'),
|
||||||
|
$qb->expr()->in('assignment.id', $availableAssignmentsIds)
|
||||||
))
|
))
|
||||||
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->eq('application.teamer', ':teamer'))
|
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->eq('application.teamer', ':teamer'))
|
||||||
->leftJoin('assignment.dispositions', 'disposition', Join::WITH, $qb->expr()->eq('disposition.teamer', ':teamer'))
|
->leftJoin('assignment.dispositions', 'disposition', Join::WITH, $qb->expr()->eq('disposition.teamer', ':teamer'))
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{% if assignment.applications|length %}
|
{% if assignment.applications|length %}
|
||||||
{% set application = assignment.applications[0] %}
|
{% set application = assignment.applicationByTeamer(teamer) %}
|
||||||
{% if application.status == constant('App\\Entity\\Application::STATUS_REJECTED') %}
|
{% if application.status == constant('App\\Entity\\Application::STATUS_REJECTED') %}
|
||||||
<a href="{{ path('app_teamer_assignment_detail', { 'uuid': assignment.uuid, 'r': return_url() }) }}"
|
<a href="{{ path('app_teamer_assignment_detail', { 'uuid': assignment.uuid, 'r': return_url() }) }}"
|
||||||
class="btn btn--small flex items-center space-x-2 bg-gray-100 text-gray-800 hover:bg-gray-50">
|
class="btn btn--small flex items-center space-x-2 bg-gray-100 text-gray-800 hover:bg-gray-50">
|
||||||
|
|||||||
Reference in New Issue
Block a user