mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add email and mobile number to person: last modif and translations
This commit is contained in:
parent
e9698f2cbc
commit
e96da0c641
@ -39,12 +39,12 @@ class PersonController extends Controller
|
||||
* @var SimilarPersonMatcher
|
||||
*/
|
||||
protected $similarPersonMatcher;
|
||||
|
||||
|
||||
public function __construct(SimilarPersonMatcher $similarPersonMatcher)
|
||||
{
|
||||
$this->similarPersonMatcher = $similarPersonMatcher;
|
||||
}
|
||||
|
||||
|
||||
public function getCFGroup()
|
||||
{
|
||||
$cFGroup = null;
|
||||
@ -119,7 +119,7 @@ class PersonController extends Controller
|
||||
|
||||
if ( ! $form->isValid() ) {
|
||||
$this->get('session')
|
||||
->getFlashBag()->add('error', 'Thp person data provided'
|
||||
->getFlashBag()->add('error', 'The person data provided'
|
||||
. ' are not valid');
|
||||
|
||||
return $this->render('ChillPersonBundle:Person:edit.html.twig',
|
||||
|
@ -34,33 +34,34 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var CustomFieldProvider
|
||||
*/
|
||||
protected $customFieldProvider;
|
||||
|
||||
|
||||
protected $fields = array(
|
||||
'id', 'firstName', 'lastName', 'birthdate',
|
||||
'placeOfBirth', 'gender', 'memo', 'email', 'phonenumber',
|
||||
'countryOfBirth', 'nationality', 'address_street_address_1',
|
||||
'address_street_address_2', 'address_valid_from', 'address_postcode_label',
|
||||
'address_postcode_code', 'address_country_name', 'address_country_code'
|
||||
'mobilenumber', 'contactInfo', 'countryOfBirth', 'nationality',
|
||||
'address_street_address_1', 'address_street_address_2',
|
||||
'address_valid_from', 'address_postcode_label', 'address_postcode_code',
|
||||
'address_country_name', 'address_country_code'
|
||||
);
|
||||
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
TranslatorInterface $translator,
|
||||
@ -72,23 +73,23 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->customFieldProvider = $customFieldProvider;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param FormBuilderInterface $builder
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$choices = array_combine($this->fields, $this->fields);
|
||||
|
||||
|
||||
foreach ($this->getCustomFields() as $cf) {
|
||||
$choices
|
||||
[$this->translatableStringHelper->localize($cf->getName())]
|
||||
=
|
||||
[$this->translatableStringHelper->localize($cf->getName())]
|
||||
=
|
||||
$cf->getSlug();
|
||||
}
|
||||
|
||||
|
||||
// Add a checkbox to select fields
|
||||
$builder->add('fields', ChoiceType::class, array(
|
||||
'multiple' => true,
|
||||
@ -114,7 +115,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
}
|
||||
))]
|
||||
));
|
||||
|
||||
|
||||
// add a date field for addresses
|
||||
$builder->add('address_date', DateType::class, array(
|
||||
'label' => "Address valid at this date",
|
||||
@ -126,14 +127,14 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
'block_name' => 'list_export_form_address_date'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
{
|
||||
// get the field starting with address_
|
||||
$addressFields = array_filter(function($el) {
|
||||
return substr($el, 0, 8) === 'address_';
|
||||
}, $this->fields);
|
||||
|
||||
|
||||
// check if there is one field starting with address in data
|
||||
if (count(array_intersect($data['fields'], $addressFields)) > 0) {
|
||||
// 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
|
||||
*
|
||||
*
|
||||
* @return CustomField[]
|
||||
*/
|
||||
private function getCustomFields()
|
||||
@ -167,7 +168,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public function getAllowedFormattersTypes()
|
||||
@ -177,7 +178,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
@ -187,7 +188,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param type $key
|
||||
* @param array $values
|
||||
* @param type $data
|
||||
@ -201,65 +202,65 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
// to format the date correctly.
|
||||
return function($value) {
|
||||
if ($value === '_header') { return 'birthdate'; }
|
||||
|
||||
|
||||
if (empty($value))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
$date = \DateTime::createFromFormat('Y-m-d', $value);
|
||||
// check that the creation could occurs.
|
||||
if ($date === false) {
|
||||
if ($date === false) {
|
||||
throw new \Exception(sprintf("The value %s could "
|
||||
. "not be converted to %s", $value, \DateTime::class));
|
||||
}
|
||||
|
||||
return $date->format('d-m-Y');
|
||||
|
||||
return $date->format('d-m-Y');
|
||||
};
|
||||
case 'gender' :
|
||||
// for gender, we have to translate men/women statement
|
||||
return function($value) {
|
||||
if ($value === '_header') { return 'gender'; }
|
||||
|
||||
|
||||
return $this->translator->trans($value);
|
||||
};
|
||||
case 'countryOfBirth':
|
||||
case 'nationality':
|
||||
$countryRepository = $this->entityManager
|
||||
->getRepository('ChillMainBundle:Country');
|
||||
|
||||
|
||||
// load all countries in a single query
|
||||
$countryRepository->findBy(array('countryCode' => $values));
|
||||
|
||||
|
||||
return function($value) use ($key, $countryRepository) {
|
||||
if ($value === '_header') { return \strtolower($key); }
|
||||
|
||||
if ($value === NULL) {
|
||||
|
||||
if ($value === NULL) {
|
||||
return $this->translator->trans('no data');
|
||||
}
|
||||
|
||||
|
||||
$country = $countryRepository->find($value);
|
||||
|
||||
|
||||
return $this->translatableStringHelper->localize(
|
||||
$country->getName());
|
||||
};
|
||||
case 'address_country_name':
|
||||
return function($value) use ($key) {
|
||||
if ($value === '_header') { return \strtolower($key); }
|
||||
|
||||
|
||||
if ($value === NULL) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
return $this->translatableStringHelper->localize(json_decode($value, true));
|
||||
};
|
||||
default:
|
||||
// for fields which are associated with person
|
||||
if (in_array($key, $this->fields)) {
|
||||
return function($value) use ($key) {
|
||||
if ($value === '_header') { return \strtolower($key); }
|
||||
if ($value === '_header') { return \strtolower($key); }
|
||||
|
||||
return $value;
|
||||
return $value;
|
||||
|
||||
};
|
||||
} else {
|
||||
@ -268,31 +269,31 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
$cf = $this->entityManager
|
||||
->getRepository(CustomField::class)
|
||||
->findOneBy(array('slug' => $this->DQLToSlug($key)));
|
||||
|
||||
|
||||
return function($value) use ($cf) {
|
||||
if ($value === '_header') {
|
||||
return $this->translatableStringHelper->localize($cf->getName());
|
||||
return $this->translatableStringHelper->localize($cf->getName());
|
||||
}
|
||||
|
||||
|
||||
return $this->customFieldProvider
|
||||
->getCustomFieldByType($cf->getType())
|
||||
->render(json_decode($value, true), $cf, 'csv');
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param type $data
|
||||
* @return type
|
||||
*/
|
||||
public function getQueryKeys($data)
|
||||
{
|
||||
$fields = array();
|
||||
|
||||
|
||||
foreach ($data['fields'] as $key) {
|
||||
if (in_array($key, $this->fields)) {
|
||||
$fields[] = $key;
|
||||
@ -301,21 +302,21 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
$fields[] = $this->slugToDQL($key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* clean a slug to be usable by DQL
|
||||
*
|
||||
* @param string $slugsanitize
|
||||
*
|
||||
* @param string $slugsanitize
|
||||
* @return string
|
||||
*/
|
||||
private function slugToDQL($slug)
|
||||
{
|
||||
return "cf____".\str_replace("-", "____", $slug);
|
||||
}
|
||||
|
||||
|
||||
private function DQLToSlug($cleanedSlug)
|
||||
{
|
||||
return \str_replace("____", "-", \substr($cleanedSlug, 6));
|
||||
@ -323,7 +324,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function getResult($query, $data)
|
||||
{
|
||||
@ -332,7 +333,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
@ -342,7 +343,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
@ -351,20 +352,20 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = array())
|
||||
{
|
||||
$centers = array_map(function($el) { return $el['center']; }, $acl);
|
||||
|
||||
|
||||
// throw an error if any fields are present
|
||||
if (!\array_key_exists('fields', $data)) {
|
||||
throw new \Doctrine\DBAL\Exception\InvalidArgumentException("any fields "
|
||||
. "have been checked");
|
||||
}
|
||||
|
||||
|
||||
$qb = $this->entityManager->createQueryBuilder();
|
||||
|
||||
|
||||
foreach ($this->fields as $f) {
|
||||
if (in_array($f, $data['fields'])) {
|
||||
switch ($f) {
|
||||
@ -383,7 +384,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
$qb->addSelect(sprintf(
|
||||
'GET_PERSON_ADDRESS_%s(person.id, :address_date) AS %s',
|
||||
// get the part after address_
|
||||
strtoupper(substr($f, 8)),
|
||||
strtoupper(substr($f, 8)),
|
||||
$f));
|
||||
$qb->setParameter('address_date', $data['address_date']);
|
||||
break;
|
||||
@ -392,31 +393,31 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->getCustomFields() as $cf) {
|
||||
if (in_array($cf->getSlug(), $data['fields'])) {
|
||||
$slug = $this->slugToDQL($cf->getSlug());
|
||||
$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));
|
||||
$qb->setParameter(sprintf('slug%s', $slug), $cf->getSlug());
|
||||
//$qb->setParameter(sprintf('name%s', $slug), $cf->getSlug());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$qb
|
||||
->from('ChillPersonBundle:Person', 'person')
|
||||
->join('person.center', 'center')
|
||||
->andWhere('center IN (:authorized_centers)')
|
||||
->setParameter('authorized_centers', $centers);
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function requiredRole()
|
||||
@ -425,7 +426,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsModifiers()
|
||||
|
@ -33,13 +33,18 @@ Chill\PersonBundle\Entity\Person:
|
||||
email:
|
||||
- Email:
|
||||
groups: [general, creation]
|
||||
message: 'The email "{{ value }}" is not a valid email.'
|
||||
message: 'The email is not valid'
|
||||
checkMX: true
|
||||
phonenumber:
|
||||
- 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: +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:
|
||||
|
@ -40,7 +40,7 @@ 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'
|
||||
'Notes on contact information': 'Remarques sur les informations de contact'
|
||||
'Remarks': 'Remarques'
|
||||
'{0} Born the %date% | {1} Born the %date%': '{0} Né le %date% | {1} Née le %date%'
|
||||
'Spoken languages': 'Langues parlées'
|
||||
|
@ -12,7 +12,9 @@
|
||||
'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 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
|
||||
|
||||
#export list
|
||||
|
@ -66,7 +66,7 @@
|
||||
</fieldset>
|
||||
{%- 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>
|
||||
<legend><h2>{{ 'Contact information'|trans }}</h2></legend>
|
||||
{%- if form.email is defined -%}
|
||||
@ -78,8 +78,8 @@
|
||||
{%- 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'}) }}
|
||||
{%- if form.contactInfo is defined -%}
|
||||
{{ form_row(form.contactInfo, {'label': 'Notes on contact information'}) }}
|
||||
{%- endif -%}
|
||||
</fieldset>
|
||||
{%- endif -%}
|
||||
|
@ -162,7 +162,7 @@ This view should receive those arguments:
|
||||
</figure>
|
||||
</div>
|
||||
{%- 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">
|
||||
<figure class="person-details">
|
||||
<h2 class="chill-blue"><i class="fa fa-envelope-o"></i> {{ 'Contact information'|trans }}</h2>
|
||||
@ -217,8 +217,8 @@ This view should receive those arguments:
|
||||
{% endif %}
|
||||
{%- if chill_person.fields.contact_info == 'visible' -%}
|
||||
<dl>
|
||||
<dt>{{ 'Remarks'|trans }} :</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>
|
||||
<dt>{{ 'Notes on contact information'|trans }} :</dt>
|
||||
<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>
|
||||
{%- endif -%}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user