getUser()) { return true; } // Only users with administrative role may edit assignments if (static::EDIT === $attribute) { return $this->security->isGranted('ROLE_ADMINISTRATIVE'); } // Only users with administrative role may publish assignments currently in draft if (static::PUBLISH === $attribute) { return Assignment::STATUS_DRAFT === $assignment->getStatus() && $this->security->isGranted('ROLE_ADMINISTRATIVE'); } // Only users with administrative role may call off assignments if (static::CALL_OFF === $attribute) { return Assignment::STATUS_CALLED_OFF !== $assignment->getStatus() && $this->security->isGranted('ROLE_ADMINISTRATIVE'); } // Only allow applications to published, not deleted and not called off assignments if ( true === in_array($assignment->getStatus(), [ Assignment::STATUS_DRAFT, Assignment::STATUS_DELETED, Assignment::STATUS_CALLED_OFF, ])) { return false; } // Only allow applications on empty slots $availableSlots = (int) $assignment->getAvailableDispositions(); if (0 < $availableSlots) { return $assignment->getDispositions()->count() < $availableSlots; } // Only teamers without existing applications may apply to the assignment if ($this->security->isGranted('ROLE_TEAMER')) { /** @var User $user */ $user = $token->getUser(); $teamer = $user->getTeamer(); $application = $this ->entityManager ->getRepository(Application::class) ->findOneBy(['teamer' => $teamer, 'assignment' => $assignment]); return null === $application; } return false; } }