mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add an export for person list
This commit is contained in:
parent
58398458c1
commit
60cb1e60f0
@ -55,6 +55,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services.yml');
|
||||
$loader->load('services/widgets.yml');
|
||||
$loader->load('services/exports.yml');
|
||||
}
|
||||
|
||||
private function handlePersonFieldsParameters(ContainerBuilder $container, $config)
|
||||
|
226
Export/Export/ListPerson.php
Normal file
226
Export/Export/ListPerson.php
Normal file
@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Export\Export;
|
||||
|
||||
use Chill\MainBundle\Export\ListInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Doctrine\ORM\Query;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\MainBundle\Export\FormatterInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* Render a list of peoples
|
||||
*
|
||||
* @author julien
|
||||
*/
|
||||
class ListPerson implements ListInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
protected $fields = array(
|
||||
'id', 'firstName', 'lastName', 'birthdate',
|
||||
'placeOfBirth', 'gender', 'memo', 'email', 'phonenumber'
|
||||
);
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
TranslatorInterface $translator
|
||||
)
|
||||
{
|
||||
$this->entityManager = $em;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param FormBuilderInterface $builder
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
|
||||
$builder->add('fields', ChoiceType::class, array(
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => array_combine($this->fields, $this->fields),
|
||||
'label' => 'Fields to include in export'
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public function getAllowedFormattersTypes()
|
||||
{
|
||||
return array(FormatterInterface::TYPE_LIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return "Create a list of people according to various filters.";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param type $key
|
||||
* @param array $values
|
||||
* @param type $data
|
||||
* @return type
|
||||
*/
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'birthdate':
|
||||
// for birthdate, we have to transform the string into a date
|
||||
// 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) {
|
||||
throw new \Exception(sprintf("The value %s could "
|
||||
. "not be converted to %s", $value, \DateTime::class));
|
||||
}
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
default:
|
||||
return function($value) use ($key) {
|
||||
if ($value === '_header') { return \strtolower($key); }
|
||||
|
||||
return $value;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param type $data
|
||||
* @return type
|
||||
*/
|
||||
public function getQueryKeys($data)
|
||||
{
|
||||
return $data['fields'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
public function getResult($query, $data)
|
||||
{
|
||||
return $query->getQuery()->getResult(Query::HYDRATE_SCALAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return "List peoples";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return Declarations::PERSON_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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'])) {
|
||||
$qb->addSelect(sprintf('person.%s as %s', $f, $f));
|
||||
}
|
||||
}
|
||||
|
||||
$qb
|
||||
->from('ChillPersonBundle:Person', 'person')
|
||||
->join('person.center', 'center')
|
||||
->andWhere('center IN (:authorized_centers)')
|
||||
->setParameter('authorized_centers', $centers);
|
||||
;
|
||||
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function requiredRole()
|
||||
{
|
||||
return new Role(PersonVoter::STATS);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsModifiers()
|
||||
{
|
||||
return array(Declarations::PERSON_TYPE);
|
||||
}
|
||||
}
|
@ -70,42 +70,6 @@ services:
|
||||
- "@chill.main.form.data_transformer.center_transformer"
|
||||
tags:
|
||||
- { name: form.type, alias: chill_personbundle_person_creation }
|
||||
|
||||
chill.person.export.export_count_person:
|
||||
class: Chill\PersonBundle\Export\Export\CountPerson
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
tags:
|
||||
- { name: chill.export, alias: count_person }
|
||||
|
||||
chill.person.export.filter_gender:
|
||||
class: Chill\PersonBundle\Export\Filter\GenderFilter
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: person_gender_filter }
|
||||
|
||||
|
||||
chill.person.export.filter_nationality:
|
||||
class: Chill\PersonBundle\Export\Filter\NationalityFilter
|
||||
arguments:
|
||||
- "@chill.main.helper.translatable_string"
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: person_nationality_filter }
|
||||
|
||||
chill.person.export.aggregator_nationality:
|
||||
class: Chill\PersonBundle\Export\Aggregator\NationalityAggregator
|
||||
arguments:
|
||||
- "@chill.main.countries_repository"
|
||||
- "@chill.main.helper.translatable_string"
|
||||
- "@translator"
|
||||
tags:
|
||||
- { name: chill.export_aggregator, alias: person_nationality_aggregator }
|
||||
|
||||
chill.person.export.aggregator_gender:
|
||||
class: Chill\PersonBundle\Export\Aggregator\GenderAggregator
|
||||
arguments:
|
||||
- "@translator"
|
||||
tags:
|
||||
- { name: chill.export_aggregator, alias: person_gender_aggregator }
|
||||
|
||||
chill.person.form.type.pick_person:
|
||||
class: Chill\PersonBundle\Form\Type\PickPersonType
|
||||
|
@ -1,16 +1,26 @@
|
||||
Edit: Modifier
|
||||
'First name': Prénom
|
||||
firstname: prénom
|
||||
firstName: prénom
|
||||
'Last name': Nom
|
||||
lastname: nom
|
||||
lastName: nom
|
||||
Name: Nom
|
||||
id: identifiant
|
||||
Birthdate: 'Date de naissance'
|
||||
birthdate: date de naissance
|
||||
'Date of birth': 'Date de naissance'
|
||||
dateOfBirth: date de naissance
|
||||
dateofbirth: date de naissance
|
||||
'Unknown date of birth': 'Date de naissance inconnue'
|
||||
Nationality: Nationalité
|
||||
'Without nationality': 'Sans nationalité'
|
||||
Gender: Genre
|
||||
gender: genre
|
||||
'Creation date': 'Date d''ouverture'
|
||||
'Not given': 'Non renseigné'
|
||||
'Place of birth': 'Lieu de naissance'
|
||||
placeOfBirth: lieu de naissance
|
||||
'Country of birth': 'Pays de naissance'
|
||||
'Unknown country of birth': 'Pays inconnu'
|
||||
'Marital status': 'État civil'
|
||||
@ -21,6 +31,7 @@ Email: 'Courrier électronique'
|
||||
Address: Adresse
|
||||
Memo: Mémo
|
||||
Phonenumber: 'Numéro de téléphone'
|
||||
phonenumber: numéro de téléphone
|
||||
'{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'
|
||||
@ -128,6 +139,9 @@ Accompanyied people: Personnes accompagnées
|
||||
## exports
|
||||
Count peoples by various parameters.: Compte le nombre de personnes en fonction de différents filtres.
|
||||
Count peoples: Nombre de personnes
|
||||
List peoples: Liste des personnes
|
||||
Create a list of people according to various filters.: Crée une liste des personnes selon différents filtres.
|
||||
Fields to include in export: Champs à inclure dans l'export
|
||||
|
||||
## filters
|
||||
Filter by person gender: Filtrer par genre de la personne
|
||||
|
Loading…
x
Reference in New Issue
Block a user