add email and mobile number to person: last modif and translations

This commit is contained in:
nobohan 2018-05-21 09:56:46 +02:00
parent e9698f2cbc
commit e96da0c641
7 changed files with 86 additions and 78 deletions

View File

@ -39,12 +39,12 @@ class PersonController extends Controller
* @var SimilarPersonMatcher * @var SimilarPersonMatcher
*/ */
protected $similarPersonMatcher; protected $similarPersonMatcher;
public function __construct(SimilarPersonMatcher $similarPersonMatcher) public function __construct(SimilarPersonMatcher $similarPersonMatcher)
{ {
$this->similarPersonMatcher = $similarPersonMatcher; $this->similarPersonMatcher = $similarPersonMatcher;
} }
public function getCFGroup() public function getCFGroup()
{ {
$cFGroup = null; $cFGroup = null;
@ -119,7 +119,7 @@ class PersonController extends Controller
if ( ! $form->isValid() ) { if ( ! $form->isValid() ) {
$this->get('session') $this->get('session')
->getFlashBag()->add('error', 'Thp person data provided' ->getFlashBag()->add('error', 'The person data provided'
. ' are not valid'); . ' are not valid');
return $this->render('ChillPersonBundle:Person:edit.html.twig', return $this->render('ChillPersonBundle:Person:edit.html.twig',

View File

@ -34,33 +34,34 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
* @var EntityManagerInterface * @var EntityManagerInterface
*/ */
protected $entityManager; protected $entityManager;
/** /**
* *
* @var TranslatorInterface * @var TranslatorInterface
*/ */
protected $translator; protected $translator;
/** /**
* *
* @var TranslatableStringHelper * @var TranslatableStringHelper
*/ */
protected $translatableStringHelper; protected $translatableStringHelper;
/** /**
* *
* @var CustomFieldProvider * @var CustomFieldProvider
*/ */
protected $customFieldProvider; protected $customFieldProvider;
protected $fields = array( protected $fields = array(
'id', 'firstName', 'lastName', 'birthdate', 'id', 'firstName', 'lastName', 'birthdate',
'placeOfBirth', 'gender', 'memo', 'email', 'phonenumber', 'placeOfBirth', 'gender', 'memo', 'email', 'phonenumber',
'countryOfBirth', 'nationality', 'address_street_address_1', 'mobilenumber', 'contactInfo', 'countryOfBirth', 'nationality',
'address_street_address_2', 'address_valid_from', 'address_postcode_label', 'address_street_address_1', 'address_street_address_2',
'address_postcode_code', 'address_country_name', 'address_country_code' 'address_valid_from', 'address_postcode_label', 'address_postcode_code',
'address_country_name', 'address_country_code'
); );
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
TranslatorInterface $translator, TranslatorInterface $translator,
@ -72,23 +73,23 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->customFieldProvider = $customFieldProvider; $this->customFieldProvider = $customFieldProvider;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @param FormBuilderInterface $builder * @param FormBuilderInterface $builder
*/ */
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$choices = array_combine($this->fields, $this->fields); $choices = array_combine($this->fields, $this->fields);
foreach ($this->getCustomFields() as $cf) { foreach ($this->getCustomFields() as $cf) {
$choices $choices
[$this->translatableStringHelper->localize($cf->getName())] [$this->translatableStringHelper->localize($cf->getName())]
= =
$cf->getSlug(); $cf->getSlug();
} }
// Add a checkbox to select fields // Add a checkbox to select fields
$builder->add('fields', ChoiceType::class, array( $builder->add('fields', ChoiceType::class, array(
'multiple' => true, 'multiple' => true,
@ -114,7 +115,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
} }
))] ))]
)); ));
// add a date field for addresses // add a date field for addresses
$builder->add('address_date', DateType::class, array( $builder->add('address_date', DateType::class, array(
'label' => "Address valid at this date", 'label' => "Address valid at this date",
@ -126,14 +127,14 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
'block_name' => 'list_export_form_address_date' 'block_name' => 'list_export_form_address_date'
)); ));
} }
public function validateForm($data, ExecutionContextInterface $context) public function validateForm($data, ExecutionContextInterface $context)
{ {
// get the field starting with address_ // get the field starting with address_
$addressFields = array_filter(function($el) { $addressFields = array_filter(function($el) {
return substr($el, 0, 8) === 'address_'; return substr($el, 0, 8) === 'address_';
}, $this->fields); }, $this->fields);
// check if there is one field starting with address in data // check if there is one field starting with address in data
if (count(array_intersect($data['fields'], $addressFields)) > 0) { if (count(array_intersect($data['fields'], $addressFields)) > 0) {
// if a field address is checked, the date must not be empty // if a field address is checked, the date must not be empty
@ -145,10 +146,10 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
} }
} }
} }
/** /**
* Get custom fields associated with person * Get custom fields associated with person
* *
* @return CustomField[] * @return CustomField[]
*/ */
private function getCustomFields() private function getCustomFields()
@ -167,7 +168,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @return type * @return type
*/ */
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
@ -177,7 +178,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @return string * @return string
*/ */
public function getDescription() public function getDescription()
@ -187,7 +188,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @param type $key * @param type $key
* @param array $values * @param array $values
* @param type $data * @param type $data
@ -201,65 +202,65 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
// to format the date correctly. // to format the date correctly.
return function($value) { return function($value) {
if ($value === '_header') { return 'birthdate'; } if ($value === '_header') { return 'birthdate'; }
if (empty($value)) if (empty($value))
{ {
return ""; return "";
} }
$date = \DateTime::createFromFormat('Y-m-d', $value); $date = \DateTime::createFromFormat('Y-m-d', $value);
// check that the creation could occurs. // check that the creation could occurs.
if ($date === false) { if ($date === false) {
throw new \Exception(sprintf("The value %s could " throw new \Exception(sprintf("The value %s could "
. "not be converted to %s", $value, \DateTime::class)); . "not be converted to %s", $value, \DateTime::class));
} }
return $date->format('d-m-Y'); return $date->format('d-m-Y');
}; };
case 'gender' : case 'gender' :
// for gender, we have to translate men/women statement // for gender, we have to translate men/women statement
return function($value) { return function($value) {
if ($value === '_header') { return 'gender'; } if ($value === '_header') { return 'gender'; }
return $this->translator->trans($value); return $this->translator->trans($value);
}; };
case 'countryOfBirth': case 'countryOfBirth':
case 'nationality': case 'nationality':
$countryRepository = $this->entityManager $countryRepository = $this->entityManager
->getRepository('ChillMainBundle:Country'); ->getRepository('ChillMainBundle:Country');
// load all countries in a single query // load all countries in a single query
$countryRepository->findBy(array('countryCode' => $values)); $countryRepository->findBy(array('countryCode' => $values));
return function($value) use ($key, $countryRepository) { return function($value) use ($key, $countryRepository) {
if ($value === '_header') { return \strtolower($key); } if ($value === '_header') { return \strtolower($key); }
if ($value === NULL) { if ($value === NULL) {
return $this->translator->trans('no data'); return $this->translator->trans('no data');
} }
$country = $countryRepository->find($value); $country = $countryRepository->find($value);
return $this->translatableStringHelper->localize( return $this->translatableStringHelper->localize(
$country->getName()); $country->getName());
}; };
case 'address_country_name': case 'address_country_name':
return function($value) use ($key) { return function($value) use ($key) {
if ($value === '_header') { return \strtolower($key); } if ($value === '_header') { return \strtolower($key); }
if ($value === NULL) { if ($value === NULL) {
return ''; return '';
} }
return $this->translatableStringHelper->localize(json_decode($value, true)); return $this->translatableStringHelper->localize(json_decode($value, true));
}; };
default: default:
// for fields which are associated with person // for fields which are associated with person
if (in_array($key, $this->fields)) { if (in_array($key, $this->fields)) {
return function($value) use ($key) { return function($value) use ($key) {
if ($value === '_header') { return \strtolower($key); } if ($value === '_header') { return \strtolower($key); }
return $value; return $value;
}; };
} else { } else {
@ -268,31 +269,31 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
$cf = $this->entityManager $cf = $this->entityManager
->getRepository(CustomField::class) ->getRepository(CustomField::class)
->findOneBy(array('slug' => $this->DQLToSlug($key))); ->findOneBy(array('slug' => $this->DQLToSlug($key)));
return function($value) use ($cf) { return function($value) use ($cf) {
if ($value === '_header') { if ($value === '_header') {
return $this->translatableStringHelper->localize($cf->getName()); return $this->translatableStringHelper->localize($cf->getName());
} }
return $this->customFieldProvider return $this->customFieldProvider
->getCustomFieldByType($cf->getType()) ->getCustomFieldByType($cf->getType())
->render(json_decode($value, true), $cf, 'csv'); ->render(json_decode($value, true), $cf, 'csv');
}; };
} }
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @param type $data * @param type $data
* @return type * @return type
*/ */
public function getQueryKeys($data) public function getQueryKeys($data)
{ {
$fields = array(); $fields = array();
foreach ($data['fields'] as $key) { foreach ($data['fields'] as $key) {
if (in_array($key, $this->fields)) { if (in_array($key, $this->fields)) {
$fields[] = $key; $fields[] = $key;
@ -301,21 +302,21 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
$fields[] = $this->slugToDQL($key); $fields[] = $this->slugToDQL($key);
} }
} }
return $fields; return $fields;
} }
/** /**
* clean a slug to be usable by DQL * clean a slug to be usable by DQL
* *
* @param string $slugsanitize * @param string $slugsanitize
* @return string * @return string
*/ */
private function slugToDQL($slug) private function slugToDQL($slug)
{ {
return "cf____".\str_replace("-", "____", $slug); return "cf____".\str_replace("-", "____", $slug);
} }
private function DQLToSlug($cleanedSlug) private function DQLToSlug($cleanedSlug)
{ {
return \str_replace("____", "-", \substr($cleanedSlug, 6)); return \str_replace("____", "-", \substr($cleanedSlug, 6));
@ -323,7 +324,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
*/ */
public function getResult($query, $data) public function getResult($query, $data)
{ {
@ -332,7 +333,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @return string * @return string
*/ */
public function getTitle() public function getTitle()
@ -342,7 +343,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
*/ */
public function getType() public function getType()
{ {
@ -351,20 +352,20 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
*/ */
public function initiateQuery(array $requiredModifiers, array $acl, array $data = array()) public function initiateQuery(array $requiredModifiers, array $acl, array $data = array())
{ {
$centers = array_map(function($el) { return $el['center']; }, $acl); $centers = array_map(function($el) { return $el['center']; }, $acl);
// throw an error if any fields are present // throw an error if any fields are present
if (!\array_key_exists('fields', $data)) { if (!\array_key_exists('fields', $data)) {
throw new \Doctrine\DBAL\Exception\InvalidArgumentException("any fields " throw new \Doctrine\DBAL\Exception\InvalidArgumentException("any fields "
. "have been checked"); . "have been checked");
} }
$qb = $this->entityManager->createQueryBuilder(); $qb = $this->entityManager->createQueryBuilder();
foreach ($this->fields as $f) { foreach ($this->fields as $f) {
if (in_array($f, $data['fields'])) { if (in_array($f, $data['fields'])) {
switch ($f) { switch ($f) {
@ -383,7 +384,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
$qb->addSelect(sprintf( $qb->addSelect(sprintf(
'GET_PERSON_ADDRESS_%s(person.id, :address_date) AS %s', 'GET_PERSON_ADDRESS_%s(person.id, :address_date) AS %s',
// get the part after address_ // get the part after address_
strtoupper(substr($f, 8)), strtoupper(substr($f, 8)),
$f)); $f));
$qb->setParameter('address_date', $data['address_date']); $qb->setParameter('address_date', $data['address_date']);
break; break;
@ -392,31 +393,31 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
} }
} }
} }
foreach ($this->getCustomFields() as $cf) { foreach ($this->getCustomFields() as $cf) {
if (in_array($cf->getSlug(), $data['fields'])) { if (in_array($cf->getSlug(), $data['fields'])) {
$slug = $this->slugToDQL($cf->getSlug()); $slug = $this->slugToDQL($cf->getSlug());
$qb->addSelect( $qb->addSelect(
sprintf('GET_JSON_FIELD_BY_KEY(person.cFData, :slug%s) AS %s', sprintf('GET_JSON_FIELD_BY_KEY(person.cFData, :slug%s) AS %s',
$slug, $slug)); $slug, $slug));
$qb->setParameter(sprintf('slug%s', $slug), $cf->getSlug()); $qb->setParameter(sprintf('slug%s', $slug), $cf->getSlug());
//$qb->setParameter(sprintf('name%s', $slug), $cf->getSlug()); //$qb->setParameter(sprintf('name%s', $slug), $cf->getSlug());
} }
} }
$qb $qb
->from('ChillPersonBundle:Person', 'person') ->from('ChillPersonBundle:Person', 'person')
->join('person.center', 'center') ->join('person.center', 'center')
->andWhere('center IN (:authorized_centers)') ->andWhere('center IN (:authorized_centers)')
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
; ;
return $qb; return $qb;
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
public function requiredRole() public function requiredRole()
@ -425,7 +426,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
public function supportsModifiers() public function supportsModifiers()

View File

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

View File

@ -40,7 +40,7 @@ Phonenumber: 'Numéro de téléphone'
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'
mobilenumber: numéro de téléphone portable mobilenumber: numéro de téléphone portable
'Contact information: remarks': 'Remarques' 'Notes on contact information': 'Remarques sur les informations de contact'
'Remarks': 'Remarques' 'Remarks': 'Remarques'
'{0} Born the %date% | {1} Born the %date%': '{0} Né le %date% | {1} Née le %date%' '{0} Born the %date% | {1} Born the %date%': '{0} Né le %date% | {1} Née le %date%'
'Spoken languages': 'Langues parlées' 'Spoken languages': 'Langues parlées'

View File

@ -12,7 +12,9 @@
'Closing date can not be null': 'La date de fermeture ne peut être nulle' 'Closing date can not be null': 'La date de fermeture ne peut être nulle'
The date of closing is before the date of opening: La période de fermeture est après la période d'ouverture The date of closing is before the date of opening: La période de fermeture est après la période d'ouverture
The birthdate must be before %date%: La date de naissance doit être avant le %date% The birthdate must be before %date%: La date de naissance doit être avant le %date%
'Invalid phone number: it should begin with the international prefix starting with "+", hold only digits and be smaller than 20 characters. Ex: +33123456789': 'Numéro de téléphone invalide: il doit commencer par le préfixe international précédé de "+", ne comporter que des chiffres et faire moins de 20 caractères. Ex: +31623456789'
'Invalid phone number: it should begin with the international prefix starting with "+", hold only digits and be smaller than 20 characters. Ex: +33623456789': 'Numéro de téléphone invalide: il doit commencer par le préfixe international précédé de "+", ne comporter que des chiffres et faire moins de 20 caractères. Ex: +33623456789'
'The email is not valid': 'Le courriel n''est pas valide'
Two addresses has the same validFrom date: La date de validité est identique à celle d'une autre adresse Two addresses has the same validFrom date: La date de validité est identique à celle d'une autre adresse
#export list #export list

View File

@ -66,7 +66,7 @@
</fieldset> </fieldset>
{%- endif -%} {%- endif -%}
{%- if form.email is defined or form.phonenumber is defined or form.mobilenumber is defined or form.contact_info is defined-%} {%- if form.email is defined or form.phonenumber is defined or form.mobilenumber is defined or form.contactInfo is defined-%}
<fieldset> <fieldset>
<legend><h2>{{ 'Contact information'|trans }}</h2></legend> <legend><h2>{{ 'Contact information'|trans }}</h2></legend>
{%- if form.email is defined -%} {%- if form.email is defined -%}
@ -78,8 +78,8 @@
{%- if form.mobilenumber is defined -%} {%- if form.mobilenumber is defined -%}
{{ form_row(form.mobilenumber, {'label': 'Mobilenumber'}) }} {{ form_row(form.mobilenumber, {'label': 'Mobilenumber'}) }}
{%- endif -%} {%- endif -%}
{%- if form.contact_info is defined -%} {%- if form.contactInfo is defined -%}
{{ form_row(form.contact_info, {'label': 'Contact information: remarks'}) }} {{ form_row(form.contactInfo, {'label': 'Notes on contact information'}) }}
{%- endif -%} {%- endif -%}
</fieldset> </fieldset>
{%- endif -%} {%- endif -%}

View File

@ -162,7 +162,7 @@ This view should receive those arguments:
</figure> </figure>
</div> </div>
{%- endif -%} {%- endif -%}
{%- if chill_person.fields.email == 'visible' or chill_person.fields.phonenumber == 'visible' -%} {%- if chill_person.fields.email == 'visible' or chill_person.fields.phonenumber == 'visible' or chill_person.fields.mobilenumber == 'visible' or chill_person.fields.contact_info == 'visible' -%}
<div class="grid-6"> <div class="grid-6">
<figure class="person-details"> <figure class="person-details">
<h2 class="chill-blue"><i class="fa fa-envelope-o"></i>&nbsp;{{ 'Contact information'|trans }}</h2> <h2 class="chill-blue"><i class="fa fa-envelope-o"></i>&nbsp;{{ 'Contact information'|trans }}</h2>
@ -217,8 +217,8 @@ This view should receive those arguments:
{% endif %} {% endif %}
{%- if chill_person.fields.contact_info == 'visible' -%} {%- if chill_person.fields.contact_info == 'visible' -%}
<dl> <dl>
<dt>{{ 'Remarks'|trans }}&nbsp;:</dt> <dt>{{ 'Notes on contact information'|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> <dd>{% if person.contactInfo is not empty %}{{ person.contactInfo|nl2br }}{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>{% endif %}</dd>
</dl> </dl>
{%- endif -%} {%- endif -%}