mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
edit template & update action
This commit is contained in:
parent
d366a76567
commit
574d1d4dcf
@ -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
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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;
|
||||
|
@ -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'
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
|
46
Form/Type/CivilType.php
Normal file
46
Form/Type/CivilType.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace CL\Chill\PersonBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
use CL\Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
* A type to select the civil union state
|
||||
*
|
||||
* @author julien
|
||||
*/
|
||||
class CivilType extends AbstractType {
|
||||
|
||||
|
||||
public function getName() {
|
||||
return 'civil';
|
||||
}
|
||||
|
||||
public function getParent() {
|
||||
return 'choice';
|
||||
}
|
||||
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver) {
|
||||
|
||||
$rootTranslate = 'person.civil_union.';
|
||||
|
||||
$a = array(
|
||||
Person::CIVIL_COHAB => $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,
|
||||
|
||||
));
|
||||
}
|
||||
|
||||
}
|
42
Form/Type/GenderType.php
Normal file
42
Form/Type/GenderType.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace CL\Chill\PersonBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
use CL\Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
* A type to select the civil union state
|
||||
*
|
||||
* @author julien
|
||||
*/
|
||||
class GenderType extends AbstractType {
|
||||
|
||||
|
||||
public function getName() {
|
||||
return 'gender';
|
||||
}
|
||||
|
||||
public function getParent() {
|
||||
return 'choice';
|
||||
}
|
||||
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver) {
|
||||
|
||||
$rootTranslate = 'person.gender.';
|
||||
|
||||
$a = array(
|
||||
Person::GENRE_MAN => $rootTranslate.Person::GENRE_MAN,
|
||||
Person::GENRE_WOMAN => $rootTranslate.Person::GENRE_WOMAN
|
||||
);
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => $a,
|
||||
'expanded' => true,
|
||||
'multiple' => false,
|
||||
'empty_value' => $rootTranslate.'undefined'
|
||||
));
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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 <span class="research">%q%</span> 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
|
||||
|
||||
|
@ -8,7 +8,49 @@
|
||||
|
||||
{% form_theme form 'CLChillMainBundle:Form:fields.html.twig' %}
|
||||
|
||||
{{ form(form) }}
|
||||
{{ form_start(form) }}
|
||||
|
||||
<button type="submit">{{ 'views.Person.edit.submit'|trans }}</button>
|
||||
|
||||
<fieldset>
|
||||
<legend><h2>{{ 'views.Person.view.general'|trans }}</h2></legend>
|
||||
{{ form_row(form.surname, {'label' : 'views.Person.view.surname'}) }}
|
||||
{{ form_row(form.name, {'label' : 'views.Person.view.name'}) }}
|
||||
{{ form_row(form.genre, {'label' : 'views.Person.view.gender'}) }}
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><h2>{{ 'views.Person.view.birth'|trans }}</h2></legend>
|
||||
{{ form_row(form.dateOfBirth, {'label': 'views.Person.view.dateOfBirth'} ) }}
|
||||
{{ form_row(form.placeOfBirth, { 'label' : 'views.Person.view.placeOfBirth'} ) }}
|
||||
{{ form_row(form.countryOfBirth, { 'label' : 'views.Person.view.contry_of_birth' } ) }}
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><h2>{{ 'views.Person.view.family'|trans }}</h2></legend>
|
||||
{{ form_row(form.civil_union, {'label' : 'views.Person.view.civil_union'}) }}
|
||||
{{ form_row(form.nbOfChild, {'label' : 'views.Person.view.nb_of_childs'}) }}
|
||||
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><h2>{{ 'views.Person.view.administrative'|trans }}</h2></legend>
|
||||
{{ form_row(form.nationality, { 'label' : 'views.Person.view.nationality'|trans} ) }}
|
||||
{{ form_row(form.belgian_national_number, { 'label' : 'views.Person.view.national_number'}) }}
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><h2>{{ 'views.Person.view.contact'|trans }}</h2></legend>
|
||||
{{ form_row(form.address, {'label' : 'views.Person.view.address'}) }}
|
||||
{{ form_row(form.email, {'label': 'views.Person.view.email'}) }}
|
||||
|
||||
</fieldset>
|
||||
|
||||
{{ form_row(form.memo, {'label' : 'views.Person.view.memo'} ) }}
|
||||
|
||||
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
|
||||
|
||||
{% endblock personcontent %}
|
Loading…
x
Reference in New Issue
Block a user