feat: exclude unavailable assignments from list for teamer

This commit is contained in:
Björn Fromme
2024-06-19 10:21:49 +02:00
parent b03f6e377a
commit 8d8d6dacd3
3 changed files with 43 additions and 2 deletions
+13
View File
@@ -350,6 +350,19 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
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
{
return $this->applications->filter(function (Application $application) {
+29 -1
View File
@@ -50,6 +50,33 @@ class AssignmentRepository extends ServiceEntityRepository
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
@@ -64,7 +91,8 @@ class AssignmentRepository extends ServiceEntityRepository
$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.dispositions', 'disposition', Join::WITH, $qb->expr()->eq('disposition.teamer', ':teamer'))
+1 -1
View File
@@ -59,7 +59,7 @@
</div>
<div>
{% if assignment.applications|length %}
{% set application = assignment.applications[0] %}
{% set application = assignment.applicationByTeamer(teamer) %}
{% if application.status == constant('App\\Entity\\Application::STATUS_REJECTED') %}
<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">