Feat: Add status to assignments to control applications
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user