mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
add email and mobile number to person: last modif and translations
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user