From 21676a20b2de3da576fba00f0e383b904f80cc9f Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 12 Aug 2015 17:59:12 +0200 Subject: [PATCH] Displaying & edit marital status --- Form/PersonType.php | 6 +- Form/Type/CivilType.php | 46 --------------- Form/Type/Select2MaritalStatusType.php | 80 ++++++++++++++++++++++++++ Resources/config/services.yml | 15 +++-- Resources/views/Person/edit.html.twig | 1 + Resources/views/Person/view.html.twig | 6 ++ 6 files changed, 101 insertions(+), 53 deletions(-) delete mode 100644 Form/Type/CivilType.php create mode 100644 Form/Type/Select2MaritalStatusType.php diff --git a/Form/PersonType.php b/Form/PersonType.php index a531f48f0..16f50cf6f 100644 --- a/Form/PersonType.php +++ b/Form/PersonType.php @@ -24,9 +24,7 @@ namespace Chill\PersonBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; -use Chill\PersonBundle\Form\Type\CivilType; use Chill\PersonBundle\Form\Type\GenderType; -use CL\BelgianNationalNumberBundle\Form\BelgianNationalNumberType; class PersonType extends AbstractType { @@ -57,6 +55,9 @@ class PersonType extends AbstractType 'required' => false, 'multiple' => true )) + ->add('maritalStatus', 'select2_chill_marital_status', array( + 'required' => false + )) ; if($options['cFGroup']) { @@ -65,7 +66,6 @@ class PersonType extends AbstractType array('attr' => array('class' => 'cf-fields'), 'group' => $options['cFGroup'])) ; } - } /** diff --git a/Form/Type/CivilType.php b/Form/Type/CivilType.php deleted file mode 100644 index 5186cf7d4..000000000 --- a/Form/Type/CivilType.php +++ /dev/null @@ -1,46 +0,0 @@ - $rootTranslate.Person::CIVIL_COHAB, - Person::CIVIL_DIVORCED => $rootTranslate.Person::CIVIL_DIVORCED, - Person::CIVIL_SEPARATED => $rootTranslate.Person::CIVIL_SEPARATED, - Person::CIVIL_SINGLE => $rootTranslate.Person::CIVIL_SINGLE, - Person::CIVIL_UNKNOW => $rootTranslate.Person::CIVIL_UNKNOW, - Person::CIVIL_WIDOW => $rootTranslate.Person::CIVIL_WIDOW - ); - - $resolver->setDefaults(array( - 'choices' => $a, - 'expanded' => false, - 'multiple' => false, - - )); - } - -} diff --git a/Form/Type/Select2MaritalStatusType.php b/Form/Type/Select2MaritalStatusType.php new file mode 100644 index 000000000..4139a66ef --- /dev/null +++ b/Form/Type/Select2MaritalStatusType.php @@ -0,0 +1,80 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\PersonBundle\Form\Type; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Chill\MainBundle\Form\Type\DataTransformer\ObjectToIdTransformer; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Doctrine\Common\Persistence\ObjectManager; + +/** + * A type to select the marital status + * + * @author Champs-Libres COOP + */ +class Select2MaritalStatusType extends AbstractType +{ + /** @var RequestStack */ + private $requestStack; + + /** @var ObjectManager */ + private $em; + + public function __construct(RequestStack $requestStack,ObjectManager $em) + { + $this->requestStack = $requestStack; + $this->em = $em; + } + + public function getName() { + return 'select2_chill_marital_status'; + } + + public function getParent() { + return 'select2_choice'; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $transformer = new ObjectToIdTransformer($this->em,'Chill\PersonBundle\Entity\MaritalStatus'); + $builder->addModelTransformer($transformer); + } + + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $locale = $this->requestStack->getCurrentRequest()->getLocale(); + $maritalStatuses = $this->em->getRepository('Chill\PersonBundle\Entity\MaritalStatus')->findAll(); + $choices = array(); + + foreach ($maritalStatuses as $ms) { + $choices[$ms->getId()] = $ms->getName()[$locale]; + } + + asort($choices, SORT_STRING | SORT_FLAG_CASE); + + $resolver->setDefaults(array( + 'class' => 'Chill\PersonBundle\Entity\MaritalStatus', + 'choices' => $choices + )); + } +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index b97cfefd4..79f4aa05e 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -9,7 +9,7 @@ services: - "@request" tags: - { name: form.type, alias: closing_motive } - + chill.person.search_person: class: Chill\PersonBundle\Search\PersonSearch arguments: @@ -20,21 +20,28 @@ services: - ['setContainer', ["@service_container"]] tags: - { name: chill.search, alias: 'person_regular' } - + chill.main.form.type.select2maritalstatus: + class: Chill\PersonBundle\Form\Type\Select2MaritalStatusType + arguments: + - "@request_stack" + - "@doctrine.orm.entity_manager" + tags: + - { name: form.type, alias: select2_chill_marital_status } + chill.person.timeline.accompanying_period_opening: class: Chill\PersonBundle\Timeline\TimelineAccompanyingPeriodOpening arguments: - "@doctrine.orm.entity_manager" tags: - { name: chill.timeline, context: 'person' } - + chill.person.timeline.accompanying_period_closing: class: Chill\PersonBundle\Timeline\TimelineAccompanyingPeriodClosing arguments: - "@doctrine.orm.entity_manager" tags: - { name: chill.timeline, context: 'person' } - + chill.person.security.authorization.person: class: Chill\PersonBundle\Security\Authorization\PersonVoter arguments: diff --git a/Resources/views/Person/edit.html.twig b/Resources/views/Person/edit.html.twig index 71eae201b..5b768f37c 100644 --- a/Resources/views/Person/edit.html.twig +++ b/Resources/views/Person/edit.html.twig @@ -44,6 +44,7 @@

{{ 'Administrative information'|trans }}

{{ form_row(form.nationality, { 'label' : 'Nationality'|trans} ) }} {{ form_row(form.spokenLanguages, {'label' : 'Spoken languages'}) }} + {{ form_row(form.maritalStatus, { 'label' : 'Marital status'} ) }}
diff --git a/Resources/views/Person/view.html.twig b/Resources/views/Person/view.html.twig index eec81a864..937415196 100644 --- a/Resources/views/Person/view.html.twig +++ b/Resources/views/Person/view.html.twig @@ -113,6 +113,12 @@ This view should receive those arguments: {% endif %} +
+
{{'Marital status'|trans}}
+
+ {{ person.maritalStatus.name|localize_translatable_string }} +
+
{% if is_granted('CHILL_PERSON_UPDATE', person) %}