diff --git a/Config/ConfigRepository.php b/Config/ConfigRepository.php index faea2d5d7..82e99cce4 100644 --- a/Config/ConfigRepository.php +++ b/Config/ConfigRepository.php @@ -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) diff --git a/DependencyInjection/ChillAMLIFamilyMembersExtension.php b/DependencyInjection/ChillAMLIFamilyMembersExtension.php index efff8eea9..58d994d66 100644 --- a/DependencyInjection/ChillAMLIFamilyMembersExtension.php +++ b/DependencyInjection/ChillAMLIFamilyMembersExtension.php @@ -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' + ) + ) + )); + } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 5eac73241..875e0046e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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() diff --git a/Form/FamilyMemberType.php b/Form/FamilyMemberType.php index f655ee462..b47818127 100644 --- a/Form/FamilyMemberType.php +++ b/Form/FamilyMemberType.php @@ -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; } /** diff --git a/Resources/config/services/config.yml b/Resources/config/services/config.yml index 965a01637..ae7981f58 100644 --- a/Resources/config/services/config.yml +++ b/Resources/config/services/config.yml @@ -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%' diff --git a/Resources/migrations/Version20180723133605.php b/Resources/migrations/Version20180723133605.php deleted file mode 100644 index 0a66d40d0..000000000 --- a/Resources/migrations/Version20180723133605.php +++ /dev/null @@ -1,28 +0,0 @@ -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'); - } -} diff --git a/Resources/views/FamilyMember/edit.html.twig b/Resources/views/FamilyMember/edit.html.twig index 3fded755f..894f65479 100644 --- a/Resources/views/FamilyMember/edit.html.twig +++ b/Resources/views/FamilyMember/edit.html.twig @@ -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) }} diff --git a/Resources/views/FamilyMember/index.html.twig b/Resources/views/FamilyMember/index.html.twig index a1275cb9a..f41d114f2 100644 --- a/Resources/views/FamilyMember/index.html.twig +++ b/Resources/views/FamilyMember/index.html.twig @@ -52,7 +52,7 @@ {% endif %}