Feat: Add status to assignments to control applications
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use App\Entity\Assignment;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20231103093456 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -12,10 +12,11 @@
|
||||
|
||||
{{ form_start(form) }}
|
||||
<div class="flex flex-col space-y-4 pb-8">
|
||||
<div class="grid lg:grid-cols-5 gap-x-8 gap-y-4">
|
||||
<div class="grid lg:grid-cols-6 gap-x-4 gap-y-4">
|
||||
<div class="lg:col-span-3">
|
||||
{{ form_row(form.destination) }}
|
||||
</div>
|
||||
{{ form_row(form.status) }}
|
||||
{{ form_row(form.availableDispositions) }}
|
||||
<div>
|
||||
<h4 class="font-bold pb-2">
|
||||
|
||||
Reference in New Issue
Block a user