Skip to content

Commit

Permalink
added enum type in Client entity
Browse files Browse the repository at this point in the history
  • Loading branch information
msalakhov committed Apr 12, 2022
1 parent 96975a4 commit 3562d20
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
31 changes: 31 additions & 0 deletions app/migrations/Version20220412104652.php
Original file line number Diff line number Diff line change
@@ -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 Version20220412104652 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 client ADD gender VARCHAR(7) NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE client DROP gender');
}
}
22 changes: 22 additions & 0 deletions app/src/Entity/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

enum Gender: string
{
case Chose = '';
case Male = 'male';
case Female = 'female';
}

#[ORM\Entity(repositoryClass: ClientRepository::class)]
#[ORM\HasLifecycleCallbacks()]
class Client
Expand Down Expand Up @@ -39,6 +46,9 @@ class Client
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private $createdAt;

#[ORM\Column(type: 'string', length: 7, enumType: Gender::class)]
private $gender;

public function getId(): ?int
{
return $this->id;
Expand Down Expand Up @@ -124,4 +134,16 @@ public function setCreatedAtValue(): void
{
$this->createdAt = new \DateTimeImmutable();
}

public function getGender(): ?Gender
{
return $this->gender;
}

public function setGender(Gender $gender): self
{
$this->gender = $gender;

return $this;
}
}
2 changes: 0 additions & 2 deletions app/src/Entity/ClientInsurance.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App\Entity;

use App\Repository\ClientInsuranceRepository;
use DateTime;
use DateTimeInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down
3 changes: 3 additions & 0 deletions app/src/Form/CreateClientFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace App\Form;

use App\Entity\Client;
use App\Entity\Gender;
use DateTime;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Date;
Expand All @@ -30,6 +32,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
new Email(),
]
])
->add('gender', EnumType::class, ['class' => Gender::class])
->add('photo', FileType::class, [
'mapped' => false,
'required' => false,
Expand Down

0 comments on commit 3562d20

Please sign in to comment.