add model + form to handle alt names

This commit is contained in:
2020-01-30 15:51:39 +01:00
parent 7b7ce4a604
commit 426458811c
14 changed files with 482 additions and 2 deletions

View File

@@ -74,6 +74,11 @@ Chill\PersonBundle\Entity\Person:
targetEntity: AccompanyingPeriod
mappedBy: person
cascade: [persist, remove, merge, detach]
altNames:
targetEntity: PersonAltName
mappedBy: person
cascade: [persist, remove, merge, detach]
orphanRemoval: true
manyToMany:
spokenLanguages:
targetEntity: Chill\MainBundle\Entity\Language

View File

@@ -0,0 +1,21 @@
Chill\PersonBundle\Entity\PersonAltName:
type: entity
table: chill_person_alt_name
repositoryClass: Chill\PersonBundle\Repository\PersonAltNameRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
key:
type: string
length: 255
label:
type: text
manyToOne:
person:
targetEntity: Person
inversedBy: altNames

View File

@@ -0,0 +1,4 @@
services:
Chill\PersonBundle\Config\ConfigPersonAltNamesHelper:
arguments:
$config: '%chill_person.person_fields.alt_names%'

View File

@@ -3,6 +3,7 @@ services:
class: Chill\PersonBundle\Form\PersonType
arguments:
- "%chill_person.person_fields%"
- '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper'
tags:
- { name: form.type }
@@ -29,3 +30,10 @@ services:
- '@Symfony\Component\Translation\TranslatorInterface'
tags:
- { name: form.type }
Chill\PersonBundle\Form\Type\PersonAltNameType:
arguments:
$configHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper'
$translatableStringHelper: '@chill.main.helper.translatable_string'
tags:
- { name: form.type }

View File

@@ -0,0 +1,31 @@
<?php declare(strict_types=1);
namespace Application\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add person alt name table
*/
final class Version20200128084445 extends AbstractMigration
{
public function up(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql("CREATE SEQUENCE chill_person_alt_name_id_seq INCREMENT BY 1 MINVALUE 1 START 1");
$this->addSql("CREATE TABLE chill_person_alt_name (id INT NOT NULL, person_id INT DEFAULT NULL, key VARCHAR(255) NOT NULL, label TEXT NOT NULL, PRIMARY KEY(id))");
$this->addSql("CREATE INDEX IDX_2628668E217BBB47 ON chill_person_alt_name (person_id)");
$this->addSql("ALTER TABLE chill_person_alt_name ADD CONSTRAINT FK_2628668E217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE");
}
public function down(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql("DROP INDEX IDX_2628668E217BBB47");
$this->addSql("DROP TABLE chill_person_alt_name");
$this->addSql("DROP SEQUENCE chill_person_alt_name_id_seq");
}
}

View File

@@ -39,6 +39,9 @@
<legend><h2>{{ 'General information'|trans }}</h2></legend>
{{ form_row(form.firstName, {'label' : 'First name'}) }}
{{ form_row(form.lastName, {'label' : 'Last name'}) }}
{% if form.altNames is defined %}
{{ form_widget(form.altNames, { 'label': 'Alternative names'}) }}
{% endif %}
{{ form_row(form.gender, {'label' : 'Gender'}) }}
</fieldset>