add email and phonenumber: wrote migration file, changed templates, changed validation rules

This commit is contained in:
nobohan 2018-05-18 17:41:33 +02:00
parent 3eb96c4479
commit e9698f2cbc
9 changed files with 118 additions and 16 deletions

View File

@ -12,7 +12,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
*/
class Configuration implements ConfigurationInterface
{
private $validationBirthdateNotAfterInfos = "The period before today during which"
. " any birthdate is not allowed. The birthdate is expressed as ISO8601 : "
. "https://en.wikipedia.org/wiki/ISO_8601#Durations";
@ -23,7 +23,7 @@ class Configuration implements ConfigurationInterface
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('cl_chill_person');
$rootNode
->canBeDisabled()
->children()
@ -50,14 +50,14 @@ class Configuration implements ConfigurationInterface
$interval = new \DateInterval($period);
} catch (\Exception $ex) {
return true;
}
}
return false;
})
->thenInvalid('Invalid period for birthdate validation : "%s" '
. 'The parameter should match duration as defined by ISO8601 : '
. 'https://en.wikipedia.org/wiki/ISO_8601#Durations')
->end() // birthdate_not_after, parent = children of validation
->end() // children for 'validation', parent = validation
->end() //validation, parent = children of root
->end() // children of root, parent = root
@ -67,6 +67,8 @@ class Configuration implements ConfigurationInterface
->append($this->addFieldNode('place_of_birth'))
->append($this->addFieldNode('email'))
->append($this->addFieldNode('phonenumber'))
->append($this->addFieldNode('mobilenumber'))
->append($this->addFieldNode('contact_info'))
->append($this->addFieldNode('nationality'))
->append($this->addFieldNode('country_of_birth'))
->append($this->addFieldNode('marital_status'))
@ -76,22 +78,22 @@ class Configuration implements ConfigurationInterface
->end() // person_fields, parent = children of root
->end() // children of 'root', parent = root
;
return $treeBuilder;
}
private function addFieldNode($key)
{
$tree = new TreeBuilder();
$node = $tree->root($key, 'enum');
$node
->values(array('hidden', 'visible'))
->defaultValue('visible')
->info("If the field $key must be shown")
->end();
return $node;
}
}

View File

@ -66,6 +66,9 @@ class Person implements HasCenterInterface {
//TO-ADD : address
/** @var string Contact information for contacting the person */
private $contactInfo = '';
/** @var string The person's email */
private $email = '';
@ -456,6 +459,32 @@ class Person implements HasCenterInterface {
return $this->maritalStatus;
}
/**
* Set contactInfo
*
* @param string $contactInfo
* @return Person
*/
public function setcontactInfo($contactInfo)
{
if ($contactInfo === null) {
$contactInfo = '';
}
$this->contactInfo = $contactInfo;
return $this;
}
/**
* Get contactInfo
*
* @return string
*/
public function getcontactInfo()
{
return $this->contactInfo;
}
/**
* Set email

View File

@ -76,9 +76,17 @@ class PersonType extends AbstractType
$builder->add('placeOfBirth', TextType::class, array('required' => false));
}
if ($this->config['contact_info'] === 'visible') {
$builder->add('contactInfo', TextareaType::class, array('required' => false));
}
if ($this->config['phonenumber'] === 'visible') {
$builder->add('phonenumber', TextareaType::class, array('required' => false));
}
if ($this->config['mobilenumber'] === 'visible') {
$builder->add('mobilenumber', TextareaType::class, array('required' => false));
}
if ($this->config['email'] === 'visible') {
$builder->add('email', EmailType::class, array('required' => false));

View File

@ -31,8 +31,12 @@ Chill\PersonBundle\Entity\Person:
memo:
type: text
default: ''
contactInfo:
type: text
nullable: true
email:
type: text
nullable: true
proxyAccompanyingPeriodOpenState:
type: boolean
name: proxy_open
@ -41,6 +45,11 @@ Chill\PersonBundle\Entity\Person:
phonenumber:
type: text
nullable: true
length: 40
mobilenumber:
type: text
nullable: true
length: 40
manyToOne:
countryOfBirth:
targetEntity: Chill\MainBundle\Entity\Country

View File

@ -34,11 +34,12 @@ Chill\PersonBundle\Entity\Person:
- Email:
groups: [general, creation]
message: 'The email "{{ value }}" is not a valid email.'
checkMX: true
phonenumber:
- Regex:
pattern: '/^([\+{1}]|[0])([0-9\s*]{4,20})$/'
pattern: '/^([\+{1}])([0-9\s*]{4,20})$/'
groups: [general, creation]
message: 'Invalid phone number: it should begin with "0" or "+", hold only digits and be smaller than 20 characters '
message: 'Invalid phone number: it should begin with the international prefix starting with "+", hold only digits and be smaller than 20 characters. Ex: +33123456789 '
constraints:

View File

@ -0,0 +1,32 @@
<?php declare(strict_types=1);
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Add a contactInfo and a mobilenumber columns on person. Change the email column.
*/
final class Version20180518144221 extends AbstractMigration
{
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_person_person ADD contactInfo TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_person ADD mobilenumber TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_person ALTER email DROP NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_person_person DROP contactInfo');
$this->addSql('ALTER TABLE chill_person_person DROP mobilenumber');
$this->addSql('ALTER TABLE chill_person_person ALTER email SET NOT NULL');
}
}

View File

@ -38,6 +38,10 @@ Address: Adresse
Memo: Mémo
Phonenumber: 'Numéro de téléphone'
phonenumber: numéro de téléphone
Mobilenumber: 'Numéro de téléphone portable'
mobilenumber: numéro de téléphone portable
'Contact information: remarks': 'Remarques'
'Remarks': 'Remarques'
'{0} Born the %date% | {1} Born the %date%': '{0} Né le %date% | {1} Née le %date%'
'Spoken languages': 'Langues parlées'
'Unknown spoken languages': 'Langues parlées inconnues'
@ -194,4 +198,3 @@ Aggregate by age: Aggréger par âge
Calculate age in relation to this date: Calculer l'âge par rapport à cette date
Group people by country of birth: Aggréger les personnes par pays de naissance

View File

@ -21,7 +21,7 @@
{% block title %}{{ 'Update details for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %}
{% block personcontent %}
<h1>{{ 'Update details for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName|capitalize } ) }}</h1>
{% form_theme form 'ChillMainBundle:Form:fields.html.twig' %}
@ -66,7 +66,7 @@
</fieldset>
{%- endif -%}
{%- if form.email is defined or form.phonenumber is defined -%}
{%- if form.email is defined or form.phonenumber is defined or form.mobilenumber is defined or form.contact_info is defined-%}
<fieldset>
<legend><h2>{{ 'Contact information'|trans }}</h2></legend>
{%- if form.email is defined -%}
@ -75,6 +75,12 @@
{%- if form.phonenumber is defined -%}
{{ form_row(form.phonenumber, {'label': 'Phonenumber'}) }}
{%- endif -%}
{%- if form.mobilenumber is defined -%}
{{ form_row(form.mobilenumber, {'label': 'Mobilenumber'}) }}
{%- endif -%}
{%- if form.contact_info is defined -%}
{{ form_row(form.contact_info, {'label': 'Contact information: remarks'}) }}
{%- endif -%}
</fieldset>
{%- endif -%}
@ -93,4 +99,4 @@
{{ form_end(form) }}
{% endblock personcontent %}
{% endblock personcontent %}

View File

@ -173,7 +173,7 @@ This view should receive those arguments:
<dd>
{%- if person.lastAddress is not empty -%}
{{ address._render(person.lastAddress) }}
<ul class="record_actions record_actions_small">
<li>
<a href="{{ path('chill_person_address_edit', { 'person_id': person.id, 'address_id' : person.lastAddress.id } ) }}" class="sc-button has-hidden button-small bt-edit">
@ -196,6 +196,7 @@ This view should receive those arguments:
</dl>
{%- endif -%}
{%- if chill_person.fields.email == 'visible' -%}
<dl>
<dt>{{ 'Email'|trans }}&nbsp;:</dt>
@ -208,7 +209,18 @@ This view should receive those arguments:
<dd>{% if person.phonenumber is not empty %}<pre>{{ person.phonenumber}}</pre>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
</dl>
{% endif %}
{%- if chill_person.fields.mobilenumber == 'visible' -%}
<dl>
<dt>{{ 'Mobilenumber'|trans }}&nbsp;:</dt>
<dd>{% if person.mobilenumber is not empty %}<pre>{{ person.mobilenumber}}</pre>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
</dl>
{% endif %}
{%- if chill_person.fields.contact_info == 'visible' -%}
<dl>
<dt>{{ 'Remarks'|trans }}&nbsp;:</dt>
<dd>{% if person.contactInfo is not empty %}<blockquote class="chill-user-quote">{{ person.contactInfo|nl2br }}</blockquote>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>{% endif %}</dd>
</dl>
{%- endif -%}
{% if is_granted('CHILL_PERSON_UPDATE', person) %}
{{ include(edit_tmp_name, edit_tmp_args) }}