diff --git a/migrations/Version20231103093456.php b/migrations/Version20231103093456.php new file mode 100644 index 0000000..7343a32 --- /dev/null +++ b/migrations/Version20231103093456.php @@ -0,0 +1,37 @@ +addSql('ALTER TABLE assignment ADD status VARCHAR(64) NOT NULL'); + } + + public function postUp(Schema $schema): void + { + $this->connection->executeQuery('UPDATE assignment SET status=?', [Assignment::STATUS_OPEN]); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE assignment DROP status'); + } +} diff --git a/src/Entity/Assignment.php b/src/Entity/Assignment.php index eb42e98..a10127f 100644 --- a/src/Entity/Assignment.php +++ b/src/Entity/Assignment.php @@ -21,6 +21,9 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa use TimestampableEntity; use SoftDeletableEntity; + public const STATUS_OPEN = 'open'; + public const STATUS_CLOSED = 'closed'; + #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] @@ -84,9 +87,13 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa #[ORM\ManyToOne] private ?User $owner = null; + #[ORM\Column(length: 64)] + private ?string $status; + public function __construct() { $this->uuid = Uuid::v4(); + $this->status = static::STATUS_OPEN; $this->fees = new ArrayCollection(); $this->applications = new ArrayCollection(); $this->dispositions = new ArrayCollection(); @@ -436,4 +443,16 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa return $this; } + + public function getStatus(): ?string + { + return $this->status; + } + + public function setStatus(string $status): static + { + $this->status = $status; + + return $this; + } } diff --git a/src/Form/AssignmentType.php b/src/Form/AssignmentType.php index 058f2f7..11854a4 100644 --- a/src/Form/AssignmentType.php +++ b/src/Form/AssignmentType.php @@ -12,6 +12,7 @@ use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\TextareaType; @@ -23,6 +24,13 @@ class AssignmentType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder + ->add('status', ChoiceType::class, [ + 'label' => 'Status', + 'choices' => [ + 'offen' => Assignment::STATUS_OPEN, + 'geschlossen' => Assignment::STATUS_CLOSED, + ], + ]) ->add('availableDispositions', IntegerType::class, [ 'label' => 'zu vergeben', 'required' => false, diff --git a/src/Security/Voter/AssignmentVoter.php b/src/Security/Voter/AssignmentVoter.php index b28dae8..e84a8e4 100644 --- a/src/Security/Voter/AssignmentVoter.php +++ b/src/Security/Voter/AssignmentVoter.php @@ -43,6 +43,11 @@ class AssignmentVoter extends Voter /** @var Assignment $assignment */ $assignment = $subject; + // Only allow applications to open assignments + if (Assignment::STATUS_CLOSED === $assignment->getStatus()) { + return false; + } + // Only allow applications on empty slots $availableSlots = (int) $assignment->getAvailableDispositions(); if (0 < $availableSlots) { diff --git a/templates/admin/assignment/_form.html.twig b/templates/admin/assignment/_form.html.twig index 1638925..b7452ff 100644 --- a/templates/admin/assignment/_form.html.twig +++ b/templates/admin/assignment/_form.html.twig @@ -12,10 +12,11 @@ {{ form_start(form) }}
-
+
{{ form_row(form.destination) }}
+ {{ form_row(form.status) }} {{ form_row(form.availableDispositions) }}