feat: category and phone number for contacts

This commit is contained in:
Björn Fromme
2024-04-04 09:19:04 +02:00
parent f596290960
commit d9a205cfd1
4 changed files with 82 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240404071550 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 contact ADD phone VARCHAR(255) NOT NULL, ADD category VARCHAR(64) NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE contact DROP phone, DROP category');
}
}
+37
View File
@@ -9,6 +9,10 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ContactRepository::class)]
class Contact
{
public const CATEGORY_MANAGEMENT = 'management';
public const CATEGORY_HOUSE_MANAGEMENT = 'house_management';
public const CATEGORY_HR = 'hr';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
@@ -23,6 +27,10 @@ class Contact
#[Assert\Email(message: 'Bitte gib eine gültige E-Mail-Adresse an', mode: 'strict')]
private ?string $email = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: 'Bitte gib die Telefonnummer an')]
private ?string $phone = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'], fetch: 'EAGER')]
#[Assert\NotNull(message: 'Bitte lade ein Foto hoch')]
private ?Upload $photo = null;
@@ -30,6 +38,11 @@ class Contact
#[ORM\Column(length: 255, nullable: true)]
private ?string $destination = null;
#[ORM\Column(length: 64)]
#[Assert\NotBlank(message: 'Bitte wähle die Kategorie')]
#[Assert\Choice(choices: [self::CATEGORY_HOUSE_MANAGEMENT, self::CATEGORY_MANAGEMENT, self::CATEGORY_HR], message: 'Die Kagegorie ist ungültig')]
private ?string $category = null;
#[ORM\OneToOne(mappedBy: 'contact', cascade: ['persist', 'remove'], fetch: 'EXTRA_LAZY')]
private ?User $user = null;
@@ -67,6 +80,18 @@ class Contact
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getPhoto(): ?Upload
{
return $this->photo;
@@ -91,6 +116,18 @@ class Contact
return $this;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(?string $category): static
{
$this->category = $category;
return $this;
}
public function getUser(): ?User
{
return $this->user;
+12
View File
@@ -5,6 +5,7 @@ namespace App\Form;
use App\Entity\Contact;
use App\Model\UploadSessionDto;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
@@ -21,6 +22,17 @@ class ContactType extends AbstractType
->add('email', EmailType::class, [
'label' => 'E-Mail',
])
->add('phone', TextType::class, [
'label' => 'Telefon',
])
->add('category', ChoiceType::class, [
'label' => 'Kategorie',
'choices' => [
'Reisemanagement' => Contact::CATEGORY_MANAGEMENT,
'Hausmanagement' => Contact::CATEGORY_HOUSE_MANAGEMENT,
'Personalplanung' => Contact::CATEGORY_HR,
],
])
->add('destination', TextType::class, [
'label' => 'Destination',
'required' => false,
@@ -1,7 +1,9 @@
{{ form_start(form, { 'attr': { 'hx-post': app.request.uri, 'hx-target': '#htmx-modal', 'hx-swap': 'outerHTML' } }) }}
<div class="flex flex-col space-y-4 pb-4">
{{ form_row(form.category) }}
{{ form_row(form.name) }}
{{ form_row(form.email) }}
{{ form_row(form.phone) }}
{{ form_row(form.destination) }}
<div>
<h4 class="font-bold pb-2">