mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
make familial situations and professionnal situations configurable
This commit is contained in:
parent
04506781cd
commit
d0dc6b3378
@ -16,24 +16,63 @@ class ConfigRepository
|
||||
*/
|
||||
protected $links;
|
||||
|
||||
public function __construct($links)
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $professionalSituations;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $familialSituations;
|
||||
|
||||
public function __construct($links, $professionnalSituations, $familialSituations)
|
||||
{
|
||||
$this->links = $links;
|
||||
$this->professionalSituations = $professionnalSituations ?? [];
|
||||
$this->familialSituations = $familialSituations ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array where keys are the resource'key and label the ressource label
|
||||
* @return array where keys are the link's keys and label the links label
|
||||
*/
|
||||
public function getLinksLabels()
|
||||
{
|
||||
$links = array();
|
||||
return $this->normalizeConfig($this->links);
|
||||
}
|
||||
|
||||
public function getProfessionalSituationsLabels()
|
||||
{
|
||||
return $this->normalizeConfig($this->professionalSituations);
|
||||
}
|
||||
|
||||
public function hasProfessionalSituation(): bool
|
||||
{
|
||||
return count($this->professionalSituations) > 0;
|
||||
}
|
||||
|
||||
public function getFamilialSituationsLabels()
|
||||
{
|
||||
return $this->normalizeConfig($this->familialSituations);
|
||||
}
|
||||
|
||||
public function hasFamilialSituation(): bool
|
||||
{
|
||||
return count($this->familialSituations) > 0;
|
||||
}
|
||||
|
||||
private function normalizeConfig($config)
|
||||
{
|
||||
$els = array();
|
||||
|
||||
foreach ($this->links as $definition) {
|
||||
$links[$definition['key']] = $this->normalizeLabel($definition['labels']);
|
||||
foreach ($config as $definition) {
|
||||
$els[$definition['key']] = $this->normalizeLabel($definition['labels']);
|
||||
}
|
||||
|
||||
return $links;
|
||||
return $els;
|
||||
}
|
||||
|
||||
private function normalizeLabel($labels)
|
||||
|
@ -24,7 +24,7 @@ class ChillAMLIFamilyMembersExtension extends Extension implements PrependExtens
|
||||
$configuration = new Configuration();
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
$this->storeLinksConfig($container, $config);
|
||||
$this->storeConfig($container, $config);
|
||||
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services/config.yml');
|
||||
@ -35,14 +35,19 @@ class ChillAMLIFamilyMembersExtension extends Extension implements PrependExtens
|
||||
$loader->load('services/templating.yml');
|
||||
}
|
||||
|
||||
private function storeLinksConfig(ContainerBuilder $container, array $config)
|
||||
private function storeConfig(ContainerBuilder $container, array $config)
|
||||
{
|
||||
$container->setParameter('chill_family_members.links', $config['links']);
|
||||
$container->setParameter('chill_family_members.professionnal_situations',
|
||||
$config['professionnal_situations']);
|
||||
$container->setParameter('chill_family_members.familial_situations',
|
||||
$config['familial_situations']);
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container)
|
||||
{
|
||||
$this->prependAuthorization($container);
|
||||
$this->prependRoutes($container);
|
||||
}
|
||||
|
||||
protected function prependAuthorization(ContainerBuilder $container)
|
||||
@ -54,5 +59,20 @@ class ChillAMLIFamilyMembersExtension extends Extension implements PrependExtens
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/* (non-PHPdoc)
|
||||
* @see \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface::prepend()
|
||||
*/
|
||||
public function prependRoutes(ContainerBuilder $container)
|
||||
{
|
||||
//add routes for custom bundle
|
||||
$container->prependExtensionConfig('chill_main', array(
|
||||
'routing' => array(
|
||||
'resources' => array(
|
||||
'@ChillAMLIFamilyMembersBundle/Resources/config/routing.yml'
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,23 +22,67 @@ class Configuration implements ConfigurationInterface
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
// ressources
|
||||
->arrayNode('links')->isRequired()->requiresAtLeastOneElement()
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('key')->isRequired()->cannotBeEmpty()
|
||||
->info('the key stored in database')
|
||||
->scalarNode('key')->isRequired()->cannotBeEmpty()
|
||||
->info('the key stored in database')
|
||||
->example('grandson')
|
||||
->end()
|
||||
->arrayNode('labels')->isRequired()->requiresAtLeastOneElement()
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('lang')->isRequired()->cannotBeEmpty()
|
||||
->example('fr')
|
||||
->end()
|
||||
->scalarNode('label')->isRequired()->cannotBeEmpty()
|
||||
->example('Petit-fils')
|
||||
->end()
|
||||
->example('fr')
|
||||
->end()
|
||||
->scalarNode('label')->isRequired()->cannotBeEmpty()
|
||||
->example('Petit-fils')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('professionnal_situations')->isRequired()
|
||||
->info("the list of professional situations. If empty, the field will not be shown")
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('key')->isRequired()->cannotBeEmpty()
|
||||
->info('the key stored in database')
|
||||
->example('student')
|
||||
->end()
|
||||
->arrayNode('labels')->isRequired()->requiresAtLeastOneElement()
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('lang')->isRequired()->cannotBeEmpty()
|
||||
->example('fr')
|
||||
->end()
|
||||
->scalarNode('label')->isRequired()->cannotBeEmpty()
|
||||
->example('Étudiant')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('familial_situations')->isRequired()
|
||||
->info("the list of familial situations. If empty, the field will not be shown")
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('key')->isRequired()->cannotBeEmpty()
|
||||
->info('the key stored in database')
|
||||
->example('half_time_keeping')
|
||||
->end()
|
||||
->arrayNode('labels')->isRequired()->requiresAtLeastOneElement()
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('lang')->isRequired()->cannotBeEmpty()
|
||||
->example('fr')
|
||||
->end()
|
||||
->scalarNode('label')->isRequired()->cannotBeEmpty()
|
||||
->example('En garde alternée')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
@ -44,9 +44,7 @@ class FamilyMemberType extends AbstractType
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$professionnalSituations = \array_flip(AbstractDiagnosticNIAssignment::PROFESSIONNAL_SITUATIONS);
|
||||
$professionnalSituations["Scolarité"] = 'scolarite';
|
||||
|
||||
|
||||
$builder
|
||||
->add('lastname', TextType::class, [
|
||||
'label' => 'Last name'
|
||||
@ -58,23 +56,35 @@ class FamilyMemberType extends AbstractType
|
||||
->add('birthdate', ChillDateType::class, [
|
||||
'required' => false
|
||||
])
|
||||
->add('professionnalSituation', ChoiceType::class, [
|
||||
'required' => false,
|
||||
'choices' => $professionnalSituations
|
||||
])
|
||||
->add('link', ChoiceType::class, [
|
||||
'choices' => $this->getLinks(),
|
||||
'choices' => $this->buildChoices($this->configRepository->getLinksLabels()),
|
||||
'placeholder' => 'Choose a link',
|
||||
'label' => 'Relationship'
|
||||
])
|
||||
->add('maritalStatus', Select2MaritalStatusType::class, [
|
||||
'required' => false
|
||||
])
|
||||
->add('familialSituation', ChoiceType::class, [
|
||||
'label' => 'Familial situation',
|
||||
'required' => false,
|
||||
'choices' => \array_flip(AbstractFamilyMember::FAMILIAL_SITUATION)
|
||||
]);
|
||||
;
|
||||
|
||||
if ($this->configRepository->hasProfessionalSituation()) {
|
||||
$builder
|
||||
->add('professionnalSituation', ChoiceType::class, [
|
||||
'required' => false,
|
||||
'choices' => $this->buildChoices(
|
||||
$this->configRepository->getProfessionalSituationsLabels()
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->configRepository->hasProfessionalSituation()) {
|
||||
$builder
|
||||
->add('familialSituation', ChoiceType::class, [
|
||||
'required' => false,
|
||||
'choices' => $this->buildChoices(
|
||||
$this->configRepository->getFamilialSituationsLabels()
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
if ($options['show_start_date']) {
|
||||
$builder
|
||||
@ -108,17 +118,18 @@ class FamilyMemberType extends AbstractType
|
||||
;
|
||||
}
|
||||
|
||||
private function getLinks()
|
||||
private function buildChoices($els)
|
||||
{
|
||||
$links = $this->configRepository
|
||||
->getLinksLabels();
|
||||
$choices = [];
|
||||
|
||||
// rewrite labels to filter in language
|
||||
foreach ($links as $key => $labels) {
|
||||
$links[$key] = $this->translatableStringHelper->localize($labels);
|
||||
foreach ($els as $key => $labels) {
|
||||
$choices[$this->translatableStringHelper->localize($labels)] = $key;
|
||||
}
|
||||
|
||||
return \array_flip($links);
|
||||
return $choices;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,3 +2,5 @@ services:
|
||||
Chill\AMLI\FamilyMembersBundle\Config\ConfigRepository:
|
||||
arguments:
|
||||
$links: '%chill_family_members.links%'
|
||||
$professionnalSituations: '%chill_family_members.professionnal_situations%'
|
||||
$familialSituations: '%chill_family_members.familial_situations%'
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Add `familial_situation` to family members
|
||||
*/
|
||||
final class Version20180723133605 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_amli.associated_family_member ADD familial_situation VARCHAR(200) DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE chill_family.family_member ADD familial_situation VARCHAR(200) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_family.family_member DROP familial_situation');
|
||||
$this->addSql('ALTER TABLE chill_amli.associated_family_member DROP familial_situation');
|
||||
}
|
||||
}
|
@ -14,8 +14,12 @@
|
||||
{{ form_row(form.birthdate) }}
|
||||
{{ form_row(form.link) }}
|
||||
{{ form_row(form.gender) }}
|
||||
{% if form.familialSituation is defined %}
|
||||
{{ form_row(form.familialSituation) }}
|
||||
{% endif %}
|
||||
{% if form.professionnalSituation is defined -%}
|
||||
{{ form_row(form.professionnalSituation) }}
|
||||
{% endif -%}
|
||||
{{ form_row(form.maritalStatus) }}
|
||||
{{ form_row(form.startDate) }}
|
||||
{{ form_row(form.endDate) }}
|
||||
|
@ -52,7 +52,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{ f.link|family_member_link_display }}
|
||||
{{ f.link|chill_family_member_link_display }}
|
||||
</td>
|
||||
<td>
|
||||
{% if f.endDate is not null %}
|
||||
|
@ -14,8 +14,12 @@
|
||||
{{ form_row(form.birthdate) }}
|
||||
{{ form_row(form.link) }}
|
||||
{{ form_row(form.gender) }}
|
||||
{% if form.familialSituation is defined %}
|
||||
{{ form_row(form.familialSituation) }}
|
||||
{% endif %}
|
||||
{% if form.professionnalSituation is defined -%}
|
||||
{{ form_row(form.professionnalSituation) }}
|
||||
{% endif -%}
|
||||
{{ form_row(form.maritalStatus) }}
|
||||
{{ form_row(form.startDate) }}
|
||||
{{ form_row(form.endDate) }}
|
||||
|
@ -14,7 +14,7 @@
|
||||
<dd>{{ familyMember.firstName ~ ' ' ~ familyMember.lastName }}</dd>
|
||||
|
||||
<dt>{{ 'family membership link'|trans }}</dt>
|
||||
<dd>{{ familyMember.link|family_member_link_display }}</dd>
|
||||
<dd>{{ familyMember.link|chill_family_member_link_display }}</dd>
|
||||
|
||||
<dt>{{ 'family membership period'|trans }}</dt>
|
||||
<dd>
|
||||
@ -52,14 +52,23 @@
|
||||
{%- endif -%}
|
||||
</dd>
|
||||
|
||||
{% if chill_family_members_has_professionnal_situation() %}
|
||||
<dt>{{ 'Professionnal situation'|trans }}</dt>
|
||||
<dd>
|
||||
{%- if familyMember.professionnalSituation is not empty -%}
|
||||
{{ familyMember.professionnalSituation }}
|
||||
{{ familyMember.professionnalSituation|chill_family_member_professional_situation_display }}
|
||||
{%- else -%}
|
||||
<span class="chill-no-data-statement">{{ 'Not given'|trans }}</span>
|
||||
{%- endif -%}
|
||||
</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if chill_family_members_has_familial_situation() %}
|
||||
<dt>{{ 'Familial situation'|trans }}</dt>
|
||||
<dd>
|
||||
{{ familyMember.familialSituation|chill_family_member_familial_situation_display|chill_print_or_message('Not given') }}
|
||||
</dd>
|
||||
{% endif %}
|
||||
</dl>
|
||||
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
|
@ -7,6 +7,7 @@ namespace Chill\AMLI\FamilyMembersBundle\Templating;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Chill\AMLI\FamilyMembersBundle\Config\ConfigRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -39,15 +40,62 @@ class Twig extends AbstractExtension
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new \Twig_Filter('family_member_link_display', [ $this, 'displayLink' ], [ 'is_safe' => [ 'html' ]])
|
||||
new \Twig_Filter('chill_family_member_link_display', [ $this, 'displayLink' ], [ 'is_safe' => [ 'html' ]]),
|
||||
new \Twig_Filter('chill_family_member_professional_situation_display', [ $this, 'displayProfessionalSituation' ], [ 'is_safe' => [ 'html' ]]),
|
||||
new \Twig_Filter('chill_family_member_familial_situation_display', [ $this, 'displayFamilialSituation' ], [ 'is_safe' => [ 'html' ]]),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('chill_family_members_has_professionnal_situation', [ $this, 'hasProfessionnalSituation' ]),
|
||||
new TwigFunction('chill_family_members_has_familial_situation', [ $this, 'hasFamilialSituation' ]),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function displayLink($link)
|
||||
{
|
||||
if (NULL === $link) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->translatableStringHelper->localize(
|
||||
$this->configRepository->getLinksLabels()[$link]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function displayProfessionalSituation($situation)
|
||||
{
|
||||
if (NULL === $situation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->translatableStringHelper->localize(
|
||||
$this->configRepository->getProfessionalSituationsLabels()[$situation]
|
||||
);
|
||||
}
|
||||
|
||||
public function hasProfessionnalSituation()
|
||||
{
|
||||
return $this->configRepository->hasProfessionalSituation();
|
||||
}
|
||||
|
||||
public function displayFamilialSituation($situation)
|
||||
{
|
||||
if (NULL === $situation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->translatableStringHelper->localize(
|
||||
$this->configRepository->getFamilialSituationsLabels()[$situation]
|
||||
);
|
||||
}
|
||||
|
||||
public function hasFamilialSituation()
|
||||
{
|
||||
return $this->configRepository->hasFamilialSituation();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user