mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Fixed: [export][list person] use address from household for person list
This commit is contained in:
247
src/Bundle/ChillMainBundle/Export/Helper/ExportAddressHelper.php
Normal file
247
src/Bundle/ChillMainBundle/Export/Helper/ExportAddressHelper.php
Normal file
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Export\Helper;
|
||||
|
||||
use Chill\MainBundle\Repository\AddressRepository;
|
||||
use Chill\MainBundle\Templating\Entity\AddressRender;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use LogicException;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessor;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Helps to load addresses and format them in list
|
||||
*/
|
||||
class ExportAddressHelper
|
||||
{
|
||||
public const ATTRIBUTES = 0b01000000;
|
||||
|
||||
public const BUILDING = 0b00001000;
|
||||
|
||||
public const COUNTRY = 0b00000001;
|
||||
|
||||
public const GEOM = 0b00100000;
|
||||
|
||||
public const POSTAL_CODE = 0b00000010;
|
||||
|
||||
public const STREET = 0b00000100;
|
||||
|
||||
public const STRING = 0b00010000;
|
||||
|
||||
private const ALL = [
|
||||
'country' => self::COUNTRY,
|
||||
'postal_code' => self::POSTAL_CODE,
|
||||
'street' => self::STREET,
|
||||
'building' => self::BUILDING,
|
||||
'string' => self::STRING,
|
||||
'geom' => self::GEOM,
|
||||
'attributes' => self::ATTRIBUTES,
|
||||
];
|
||||
|
||||
private const COLUMN_MAPPING = [
|
||||
'country' => ['country'],
|
||||
'postal_code' => ['postcode_code', 'postcode_name'],
|
||||
'street' => ['street', 'streetNumber'],
|
||||
'building' => ['buildingName', 'corridor', 'distribution', 'extra', 'flat', 'floor'],
|
||||
'string' => ['_as_string'],
|
||||
'attributes' => ['isNoAddress', 'confidential', 'id'],
|
||||
'geom' => ['_lat', '_lon'],
|
||||
];
|
||||
|
||||
private AddressRender $addressRender;
|
||||
|
||||
private AddressRepository $addressRepository;
|
||||
|
||||
private PropertyAccessor $propertyAccess;
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
AddressRepository $addressRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper,
|
||||
AddressRender $addressRender
|
||||
) {
|
||||
$this->addressRepository = $addressRepository;
|
||||
$this->propertyAccess = PropertyAccess::createPropertyAccessor();
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->addressRender = $addressRender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function getKeys(int $params, string $prefix = ''): array
|
||||
{
|
||||
$prefixes = [];
|
||||
|
||||
foreach (self::ALL as $key => $bitmask) {
|
||||
if (($params & $bitmask) === $bitmask) {
|
||||
$prefixes = array_merge(
|
||||
$prefixes,
|
||||
array_map(
|
||||
static function ($item) use ($prefix) { return $prefix . $item; },
|
||||
self::COLUMN_MAPPING[$key]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $prefixes;
|
||||
}
|
||||
|
||||
public function getLabel($key, array $values, $data, string $prefix = '', string $translationPrefix = 'export.address_helper.'): callable
|
||||
{
|
||||
$sanitizedKey = substr($key, strlen($prefix));
|
||||
|
||||
switch ($sanitizedKey) {
|
||||
case 'id':
|
||||
case 'street':
|
||||
case 'streetNumber':
|
||||
case 'buildingName':
|
||||
case 'corridor':
|
||||
case 'distribution':
|
||||
case 'extra':
|
||||
case 'flat':
|
||||
case 'floor':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
return $this->propertyAccess->getValue($address, $sanitizedKey);
|
||||
};
|
||||
|
||||
case '_lat':
|
||||
case '_lon':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
$geom = $address->getPoint();
|
||||
|
||||
if (null === $geom) {
|
||||
return '';
|
||||
}
|
||||
|
||||
switch ($sanitizedKey) {
|
||||
case '_lat':
|
||||
return $geom->getLat();
|
||||
|
||||
case '_lon':
|
||||
return $geom->getLon();
|
||||
|
||||
default:
|
||||
throw new LogicException('only _lat or _lon accepted, given: ' . $sanitizedKey);
|
||||
}
|
||||
};
|
||||
|
||||
case 'isNoAddress':
|
||||
case 'confidential':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
switch ($val = $this->propertyAccess->getValue($address, $sanitizedKey)) {
|
||||
case null:
|
||||
return '';
|
||||
|
||||
case true:
|
||||
return 1;
|
||||
|
||||
case false:
|
||||
return 0;
|
||||
|
||||
default:
|
||||
throw new LogicException('this value is not supported for ' . $sanitizedKey . ': ' . $val);
|
||||
}
|
||||
};
|
||||
|
||||
case 'country':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
return $this->translatableStringHelper->localize($address->getPostcode()->getCountry()->getName());
|
||||
};
|
||||
|
||||
case '_as_string':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
return $this->addressRender->renderString($address, []);
|
||||
};
|
||||
|
||||
case 'postcode_code':
|
||||
case 'postcode_name':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
switch ($sanitizedKey) {
|
||||
case 'postcode_code':
|
||||
return $address->getPostcode()->getCode();
|
||||
|
||||
case 'postcode_name':
|
||||
return $address->getPostcode()->getName();
|
||||
|
||||
default:
|
||||
throw new LogicException('this key is not supported: ' . $sanitizedKey);
|
||||
}
|
||||
};
|
||||
|
||||
default:
|
||||
throw new LogicException('this key is not supported: ' . $sanitizedKey);
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,6 +3,9 @@ services:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Chill\MainBundle\Export\Helper\:
|
||||
resource: '../../Export/Helper'
|
||||
|
||||
chill.main.export_element_validator:
|
||||
class: Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraintValidator
|
||||
tags:
|
||||
|
@@ -79,17 +79,17 @@ Postal code: Code postal
|
||||
Valid from: Valide à partir du
|
||||
Choose a postal code: Choisir un code postal
|
||||
address:
|
||||
address_homeless: L'adresse est-elle celle d'un domicile fixe ?
|
||||
real address: Adresse d'un domicile
|
||||
consider homeless: Cette adresse est incomplète
|
||||
address_homeless: L'adresse est-elle celle d'un domicile fixe ?
|
||||
real address: Adresse d'un domicile
|
||||
consider homeless: Cette adresse est incomplète
|
||||
address more:
|
||||
floor: ét
|
||||
corridor: coul
|
||||
steps: esc
|
||||
flat: appart
|
||||
buildingName: résidence
|
||||
extra: ""
|
||||
distribution: cedex
|
||||
floor: ét
|
||||
corridor: coul
|
||||
steps: esc
|
||||
flat: appart
|
||||
buildingName: résidence
|
||||
extra: ""
|
||||
distribution: cedex
|
||||
Create a new address: Créer une nouvelle adresse
|
||||
Create an address: Créer une adresse
|
||||
Update address: Modifier l'adresse
|
||||
@@ -125,7 +125,7 @@ Location and location type: Localisations et types de localisation
|
||||
Back to the admin: Menu d'administration
|
||||
"Administration interface": Interface d'administration
|
||||
Welcome to the admin section !: >
|
||||
Bienvenue dans l'interface d'administration !
|
||||
Bienvenue dans l'interface d'administration !
|
||||
|
||||
#permissions
|
||||
Permissions Menu: Gestion des droits
|
||||
@@ -334,69 +334,69 @@ Impersonate: Incarner l'utilisateur
|
||||
Impersonate mode: Mode fantôme
|
||||
|
||||
crud:
|
||||
# general items
|
||||
new:
|
||||
button_action_form: Créer
|
||||
link_edit: Modifier
|
||||
save_and_close: Créer & fermer
|
||||
save_and_show: Créer & voir
|
||||
save_and_new: Créer & nouveau
|
||||
success: Les données ont été créées
|
||||
edit:
|
||||
button_action_form: Enregistrer
|
||||
back_to_view: Voir
|
||||
save_and_close: Enregistrer & fermer
|
||||
save_and_show: Enregistrer & voir
|
||||
success: Les données ont été modifiées
|
||||
delete:
|
||||
success: Les données ont été supprimées
|
||||
link_to_form: Supprimer
|
||||
default:
|
||||
success: Les données ont été enregistrées
|
||||
view:
|
||||
link_duplicate: Dupliquer
|
||||
admin_user:
|
||||
index:
|
||||
title: Utilisateurs
|
||||
add_new: Créer
|
||||
title_edit: Modifier un utilisateur
|
||||
title_new: Créer un utilisateur
|
||||
admin_user_job:
|
||||
index:
|
||||
title: Métiers
|
||||
add_new: Créer
|
||||
title_new: Nouveau métier
|
||||
title_edit: Modifier un métier
|
||||
main_location_type:
|
||||
index:
|
||||
title: Liste des types de localisations
|
||||
add_new: Ajouter un type de localisation
|
||||
title_new: Nouveau type de localisation
|
||||
title_edit: Modifier un type de localisation
|
||||
main_location:
|
||||
index:
|
||||
title: Liste des localisations
|
||||
add_new: Ajouter une localisation
|
||||
title_new: Nouvelle localisation
|
||||
title_edit: Modifier une localisation
|
||||
main_language:
|
||||
index:
|
||||
title: Liste des langues
|
||||
add_new: Ajouter une langue
|
||||
title_new: Nouvelle langue
|
||||
title_edit: Modifier une langue
|
||||
main_country:
|
||||
index:
|
||||
title: Liste des pays
|
||||
add_new: Ajouter un pays
|
||||
title_new: Nouveau pays
|
||||
title_edit: Modifier un pays
|
||||
main_civility:
|
||||
index:
|
||||
title: Liste des civilités
|
||||
add_new: Ajouter une civilité
|
||||
title_new: Nouvelle civilité
|
||||
title_edit: Modifier une civilité
|
||||
# general items
|
||||
new:
|
||||
button_action_form: Créer
|
||||
link_edit: Modifier
|
||||
save_and_close: Créer & fermer
|
||||
save_and_show: Créer & voir
|
||||
save_and_new: Créer & nouveau
|
||||
success: Les données ont été créées
|
||||
edit:
|
||||
button_action_form: Enregistrer
|
||||
back_to_view: Voir
|
||||
save_and_close: Enregistrer & fermer
|
||||
save_and_show: Enregistrer & voir
|
||||
success: Les données ont été modifiées
|
||||
delete:
|
||||
success: Les données ont été supprimées
|
||||
link_to_form: Supprimer
|
||||
default:
|
||||
success: Les données ont été enregistrées
|
||||
view:
|
||||
link_duplicate: Dupliquer
|
||||
admin_user:
|
||||
index:
|
||||
title: Utilisateurs
|
||||
add_new: Créer
|
||||
title_edit: Modifier un utilisateur
|
||||
title_new: Créer un utilisateur
|
||||
admin_user_job:
|
||||
index:
|
||||
title: Métiers
|
||||
add_new: Créer
|
||||
title_new: Nouveau métier
|
||||
title_edit: Modifier un métier
|
||||
main_location_type:
|
||||
index:
|
||||
title: Liste des types de localisations
|
||||
add_new: Ajouter un type de localisation
|
||||
title_new: Nouveau type de localisation
|
||||
title_edit: Modifier un type de localisation
|
||||
main_location:
|
||||
index:
|
||||
title: Liste des localisations
|
||||
add_new: Ajouter une localisation
|
||||
title_new: Nouvelle localisation
|
||||
title_edit: Modifier une localisation
|
||||
main_language:
|
||||
index:
|
||||
title: Liste des langues
|
||||
add_new: Ajouter une langue
|
||||
title_new: Nouvelle langue
|
||||
title_edit: Modifier une langue
|
||||
main_country:
|
||||
index:
|
||||
title: Liste des pays
|
||||
add_new: Ajouter un pays
|
||||
title_new: Nouveau pays
|
||||
title_edit: Modifier un pays
|
||||
main_civility:
|
||||
index:
|
||||
title: Liste des civilités
|
||||
add_new: Ajouter une civilité
|
||||
title_new: Nouvelle civilité
|
||||
title_edit: Modifier une civilité
|
||||
|
||||
No entities: Aucun élément
|
||||
|
||||
@@ -515,3 +515,22 @@ notification:
|
||||
Remove an email: Supprimer l'adresse email
|
||||
Email with access link: Adresse email ayant reçu un lien d'accès
|
||||
|
||||
export:
|
||||
address_helper:
|
||||
id: Identifiant de l'adresse
|
||||
street: Voie
|
||||
streetNumber: Numéro de voie
|
||||
buildingName: Résidence
|
||||
corridor: Couloir
|
||||
distribution: Distribution
|
||||
extra: Extra
|
||||
flat: Appartement
|
||||
floor: Étage
|
||||
postcode_code: Code postal
|
||||
postcode_name: Libellé du code postal
|
||||
country: Pays
|
||||
_as_string: Adresse formattée
|
||||
confidential: Adresse confidentielle ?
|
||||
isNoAddress: Adresse incomplète ?
|
||||
_lat: Latitude
|
||||
_lon: Longitude
|
||||
|
Reference in New Issue
Block a user