diff --git a/src/Controller/Teamer/IndexController.php b/src/Controller/Teamer/IndexController.php index fbc40cb..39950a0 100644 --- a/src/Controller/Teamer/IndexController.php +++ b/src/Controller/Teamer/IndexController.php @@ -91,4 +91,4 @@ class IndexController extends AbstractController return $dispositions; } -} \ No newline at end of file +} diff --git a/src/Entity/Assignment.php b/src/Entity/Assignment.php index 398516e..3a8cbfb 100644 --- a/src/Entity/Assignment.php +++ b/src/Entity/Assignment.php @@ -464,6 +464,19 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa return $this; } + public function getDispositionByTeamer(Teamer $teamer): ?Disposition + { + $dispositions = $this->dispositions->filter(function (Disposition $disposition) use ($teamer) { + return $disposition->getTeamer() === $teamer; + }); + + if (0 === count($dispositions)) { + return null; + } + + return $dispositions->first(); + } + public function getValidDispositions(): Collection { return $this->dispositions->filter(function (Disposition $disposition) { diff --git a/src/Repository/AssignmentRepository.php b/src/Repository/AssignmentRepository.php index ed896ff..dca991d 100644 --- a/src/Repository/AssignmentRepository.php +++ b/src/Repository/AssignmentRepository.php @@ -87,6 +87,13 @@ class AssignmentRepository extends ServiceEntityRepository ->setParameter('now', new \DateTimeImmutable()) ; + if (0 === $teamer->getTrainingAttendances()->count() && 0 === $teamer->getLicenses()->count()) { + $qb + ->andWhere($qb->expr()->eq($qb->expr()->count('job_profile.requiredLicenses'), 0)) + ->andWhere($qb->expr()->eq($qb->expr()->count('job_profile.requiredTrainings'), 0)) + ; + } + $this->applyFilterSettings($filterDto, $qb); return $qb->getQuery(); @@ -280,6 +287,13 @@ class AssignmentRepository extends ServiceEntityRepository ->setParameter('dateFrom', new \DateTimeImmutable()) ; + if (0 === $teamer->getTrainingAttendances()->count() && 0 === $teamer->getLicenses()->count()) { + $qb + ->andWhere($qb->expr()->eq($qb->expr()->count('job_profile.requiredLicenses'), 0)) + ->andWhere($qb->expr()->eq($qb->expr()->count('job_profile.requiredTrainings'), 0)) + ; + } + return $qb ->orderBy('assignment.createdAt', 'DESC') ->setMaxResults($limit) diff --git a/src/Repository/DispositionRepository.php b/src/Repository/DispositionRepository.php index d16273d..8e0c818 100644 --- a/src/Repository/DispositionRepository.php +++ b/src/Repository/DispositionRepository.php @@ -97,8 +97,9 @@ class DispositionRepository extends ServiceEntityRepository $qb = $this->createQueryBuilder('disposition'); return $qb - ->select('disposition', 'teamer', 'feedback') + ->select('disposition', 'teamer', 'user', 'feedback') ->innerJoin('disposition.teamer', 'teamer') + ->leftJoin('teamer.user', 'user') ->leftJoin('teamer.feedback', 'feedback') ->where($qb->expr()->eq('disposition.assignment', ':assignment')) ->setParameter('assignment', $assignment) diff --git a/src/Security/Voter/AssignmentVoter.php b/src/Security/Voter/AssignmentVoter.php index e52c322..de9e52c 100644 --- a/src/Security/Voter/AssignmentVoter.php +++ b/src/Security/Voter/AssignmentVoter.php @@ -74,13 +74,7 @@ class AssignmentVoter extends Voter // Only allow applications on empty slots $availableSlots = (int) $assignment->getAvailableDispositions(); if (0 < $availableSlots) { - $dispositions = $this - ->entityManager - ->getRepository(Disposition::class) - ->findCurrentDispositionsByAssignment($assignment) - ; - - return count($dispositions) < $availableSlots; + return $assignment->getDispositions()->count() < $availableSlots; } // Only teamers without existing applications may apply to the assignment @@ -98,4 +92,4 @@ class AssignmentVoter extends Voter return false; } -} \ No newline at end of file +} diff --git a/templates/teamer/assignment/index.html.twig b/templates/teamer/assignment/index.html.twig index d75e1b6..4f0c9cd 100644 --- a/templates/teamer/assignment/index.html.twig +++ b/templates/teamer/assignment/index.html.twig @@ -57,8 +57,9 @@ {% endif %}
- {% if assignment.applications|length %} - {% set application = assignment.applicationByTeamer(teamer) %} + {% set application = assignment.applications.first %} + {% set disposition = assignment.dispositions.first%} + {% if application %} {% if application.status == constant('App\\Entity\\Application::STATUS_REJECTED') %} @@ -72,8 +73,8 @@ in Bearbeitung {% endif %} - {% elseif assignment.dispositions|length %} - {{ icon('check', 'w-4 h-4 shrink-0') }} eingeteilt @@ -98,4 +99,4 @@ {% endfor %}
{{ knp_pagination_render(pagination, 'paginator/sliding_boxes.html.twig') }} -{% endblock %} \ No newline at end of file +{% endblock %}