diff --git a/Controller/PersonController.php b/Controller/PersonController.php index 7fa60a50c..148fbfa77 100644 --- a/Controller/PersonController.php +++ b/Controller/PersonController.php @@ -4,6 +4,8 @@ namespace CL\Chill\PersonBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use CL\Chill\PersonBundle\Entity\Person; +use CL\Chill\PersonBundle\Form\PersonType; +use Symfony\Component\HttpFoundation\Request; class PersonController extends Controller { @@ -12,7 +14,7 @@ class PersonController extends Controller { $person = $this->_getPerson($id); if ($person === null) { - $this->createNotFoundException("Person with id $id not found on this server"); + return $this->createNotFoundException("Person with id $id not found on this server"); } return $this->render('CLChillPersonBundle:Person:view.html.twig', @@ -25,16 +27,63 @@ class PersonController extends Controller { $person = $this->_getPerson($id); if ($person === null) { - $this->createNotFoundException(); + return $this->createNotFoundException(); } - $form = $this->createForm(new \CL\Chill\PersonBundle\Form\PersonType(), $person); + $form = $this->createForm(new PersonType(), $person, array( + 'action' => $this->generateUrl('chill_person_general_update', array( + 'id' => $id + )) + )); + + return $this->render('CLChillPersonBundle:Person:edit.html.twig', array('person' => $person, 'form' => $form->createView())); } + public function updateAction($id, Request $request) { + $person = $this->_getPerson($id); + + if ($person === null) { + return $this->createNotFoundException(); + } + + $form = $this->createForm(new PersonType(), $person); + + if ($request->getMethod() === 'POST') { + $form->handleRequest($request); + + if ( ! $form->isValid() ) { + + $errors = $form->getErrorsAsString(); + + $this->get('session') + ->getFlashBag()->add('danger', 'error' . $errors); + + return $this->render('CLChillPersonBundle:Person:edit.html.twig', + array('person' => $person, + 'form' => $form->createView())); + } + + $this->get('session')->getFlashBag() + ->add('success', + $this->get('translator') + ->trans('validation.Person.form.person.success') + ); + + $em = $this->getDoctrine()->getManager(); + $em->flush(); + + $url = $this->generateUrl('chill_person_view', array( + 'id' => $person->getId() + )); + + return $this->redirect($url); + } + } + public function searchAction() { $q = $this->getRequest()->query->getAlnum('q', ''); $q = trim($q); @@ -76,8 +125,7 @@ class PersonController extends Controller { return $this->render('CLChillPersonBundle:Person:list.html.twig', array( 'persons' => $persons, - 'pattern' => $q, - 'menu_composer' => $this->get('menu_composer') + 'pattern' => $q )); } diff --git a/DataFixtures/ORM/LoadPeople.php b/DataFixtures/ORM/LoadPeople.php index adea9e99e..198239351 100644 --- a/DataFixtures/ORM/LoadPeople.php +++ b/DataFixtures/ORM/LoadPeople.php @@ -88,7 +88,7 @@ class LoadPeople extends AbstractFixture { 'Genre' => $sex, 'CivilUnion' => $this->CivilUnions[array_rand($this->CivilUnions)], 'NbOfChild' => $this->NbOfChild[array_rand($this->NbOfChild)], - 'BelgianNationalNumber' => '12-10-16-269-24', + 'BelgianNationalNumber' => '811016-269-24', 'Email' => "Email d'un ami: roger@tt.com", 'CountryOfBirth' => 'France', 'Nationality' => 'Russie' diff --git a/Entity/Person.php b/Entity/Person.php index 777d1bc25..f3e6d54f5 100644 --- a/Entity/Person.php +++ b/Entity/Person.php @@ -311,6 +311,10 @@ ou une valeur vide lorsque la donnée nest pas connue*/ */ public function setMemo($memo) { + if ($memo === null) { + $memo = ''; + } + $this->memo = $memo; return $this; @@ -334,6 +338,10 @@ ou une valeur vide lorsque la donnée nest pas connue*/ */ public function setAddress($address) { + if ($address === null) { + $address = ''; + } + $this->address = $address; return $this; diff --git a/Form/PersonType.php b/Form/PersonType.php index 49c68cc16..9b655022c 100644 --- a/Form/PersonType.php +++ b/Form/PersonType.php @@ -5,6 +5,9 @@ namespace CL\Chill\PersonBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use CL\Chill\PersonBundle\Form\Type\CivilType; +use CL\Chill\PersonBundle\Form\Type\GenderType; +use CL\BelgianNationalNumberBundle\Form\BelgianNationalNumberType; class PersonType extends AbstractType { @@ -17,17 +20,28 @@ class PersonType extends AbstractType $builder ->add('name') ->add('surname') - ->add('dateOfBirth') - ->add('placeOfBirth') - ->add('genre') - ->add('civil_union') - ->add('nbOfChild') - ->add('belgian_national_number') - ->add('memo') - ->add('address') - ->add('email') - ->add('countryOfBirth') - ->add('nationality') + ->add('dateOfBirth', 'date', array('required' => false)) + ->add('placeOfBirth', 'text', array('required' => false)) + ->add('genre', new GenderType(), array( + 'required' => false + )) + ->add('civil_union', new CivilType(), array( + 'required' => false + )) + ->add('nbOfChild', 'integer', array('required' => false)) + ->add('belgian_national_number', new BelgianNationalNumberType(), + array('required' => false)) + ->add('memo', 'text', array('required' => false)) + ->add('address', 'text', array('required' => false)) + ->add('email', 'text', array('required' => false)) + ->add('countryOfBirth', 'entity', array( + 'required' => false, + 'class' => 'CL\Chill\MainBundle\Entity\Country' + )) + ->add('nationality', 'entity', array( + 'required' => false, + 'class' => 'CL\Chill\MainBundle\Entity\Country' + )) ; } diff --git a/Form/Type/CivilType.php b/Form/Type/CivilType.php new file mode 100644 index 000000000..ffcd5937f --- /dev/null +++ b/Form/Type/CivilType.php @@ -0,0 +1,46 @@ + $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/GenderType.php b/Form/Type/GenderType.php new file mode 100644 index 000000000..45c081816 --- /dev/null +++ b/Form/Type/GenderType.php @@ -0,0 +1,42 @@ + $rootTranslate.Person::GENRE_MAN, + Person::GENRE_WOMAN => $rootTranslate.Person::GENRE_WOMAN + ); + + $resolver->setDefaults(array( + 'choices' => $a, + 'expanded' => true, + 'multiple' => false, + 'empty_value' => $rootTranslate.'undefined' + )); + } + +} diff --git a/Resources/config/doctrine/Person.orm.yml b/Resources/config/doctrine/Person.orm.yml index daf1f28bb..7adb628bc 100644 --- a/Resources/config/doctrine/Person.orm.yml +++ b/Resources/config/doctrine/Person.orm.yml @@ -43,8 +43,7 @@ CL\Chill\PersonBundle\Entity\Person: address: type: text email: - type: string - length: 255 + type: text manyToOne: countryOfBirth: targetEntity: CL\Chill\MainBundle\Entity\Country diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index a8ac83e21..3b74594d9 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -12,6 +12,9 @@ chill_person_general_edit: pattern: /view/{id}/edit defaults: {_controller: CLChillPersonBundle:Person:edit } +chill_person_general_update: + pattern: /view/{id}/update + defaults: {_controller: CLChillPersonBundle:Person:update } chill_person_search: diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 7d0873d3a..9b04e6cbc 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -10,12 +10,22 @@ person: unknow: Inconnu cohab: Cohabitation légale single: Célibataire + gender: + MAN: Homme + WOM: Femme + undefined: Non renseigné search: q_is_empty: Votre requête est vide. Veuillez introduire un terme de recherche no_results: La requête %q% ne renvoie aucun résultat. - + +validation: + Person: + form: + person: + success: Bravo ! Les données ont été mises à jour. + error: '{1} Le champs %field% est incorrect. Veuillez le mettre à jour | ]1, Inf] Plusieurs champs sont incorrects. Veuillez les vérifier.' views: layout: @@ -23,9 +33,11 @@ views: without_nationality: Nationalité inconnue Person: view: + general: Généralités birth: Naissance dateOfBirth: Date de naissance - placeOfBirth: Lieu de Naissance + placeOfBirth: Lieu de naissance + contry_of_birth: Pays de naissance country_of_birth_unknow: Pays inconnu without_nationality: Nationalité inconnue family: Famille @@ -38,6 +50,10 @@ views: email: Courrer électronique address: Adresse administrative: Administratif + surname: Prénom + name: Nom + gender: Genre + memo: Mémo list: without_nationality: Nationalité inconnue diff --git a/Resources/views/Person/edit.html.twig b/Resources/views/Person/edit.html.twig index 1d0054815..edcd17794 100644 --- a/Resources/views/Person/edit.html.twig +++ b/Resources/views/Person/edit.html.twig @@ -8,7 +8,49 @@ {% form_theme form 'CLChillMainBundle:Form:fields.html.twig' %} -{{ form(form) }} +{{ form_start(form) }} + + + +
+ + + + + + + + + +{{ form_row(form.memo, {'label' : 'views.Person.view.memo'} ) }} + + +{{ form_rest(form) }} +{{ form_end(form) }} {% endblock personcontent %} \ No newline at end of file