create and review the creation of a person

This commit is contained in:
Julien Fastré 2013-12-03 17:12:56 +01:00
parent 44d8236f21
commit 5750c73574
6 changed files with 258 additions and 7 deletions

View File

@ -5,7 +5,9 @@ namespace CL\Chill\PersonBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use CL\Chill\PersonBundle\Entity\Person; use CL\Chill\PersonBundle\Entity\Person;
use CL\Chill\PersonBundle\Form\PersonType; use CL\Chill\PersonBundle\Form\PersonType;
use CL\Chill\PersonBundle\Form\CreationPersonType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class PersonController extends Controller { class PersonController extends Controller {
@ -140,6 +142,143 @@ class PersonController extends Controller {
)); ));
} }
public function newAction() {
$form = $this->createForm(
new CreationPersonType(CreationPersonType::FORM_NOT_REVIEWED),
null, array('action' => $this->generateUrl('chill_person_review')));
return $this->_renderNewForm($form);
}
private function _renderNewForm($form) {
return $this->render('CLChillPersonBundle:Person:create.html.twig',
array(
'form' => $form->createView()
));
}
/**
*
* @param type $form
* @return \CL\Chill\PersonBundle\Entity\Person
*/
private function _bindCreationForm($form) {
$date = new \DateTime($form['creation_date']->getData());
$person = new Person($date);
$date_of_birth = new \DateTime($form['dateOfBirth']->getData());
$person->setName($form['name']->getData())
->setSurname($form['surname']->getData())
->setGenre($form['genre']->getData())
->setDateOfBirth($date_of_birth)
;
return $person;
}
public function reviewAction() {
$request = $this->getRequest();
if ($request->getMethod() !== 'POST') {
$r = new Response("You must send something to review the creation of a new Person");
$r->setStatusCode(400);
return $r;
}
$form = $this->createForm(
new CreationPersonType(CreationPersonType::FORM_BEING_REVIEWED),
null, array('action' => $this->generateUrl('chill_person_create')));
$form->handleRequest($request);
$person = $this->_bindCreationForm($form);
$errors = $this->get('validator')
->validate($person, array('creation'));
//validate history
$histories = $person->getHistories();
foreach ($histories as $history) {
$errors_history = $this->get('validator')
->validate($history);
//group errors :
foreach($errors_history as $error) {
$errors->add($error);
}
}
if ( count($errors) > 0) {
$flashBag = $this->get('session')->getFlashBag();
$translator = $this->get('translator');
$flashBag->add('danger', $translator->trans('controller.Person.review.problem_with_data'));
foreach($errors as $error) {
$flashBag->add('info', $error->getMessage());
}
$form = $this->createForm(
new CreationPersonType(CreationPersonType::FORM_NOT_REVIEWED),
array('action' => $this->generateUrl('chill_person_create')));
$form->handleRequest($request);
return $this->_renderNewForm($form);
}
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery();
$dql = 'SELECT p from CLChillPersonBundle:Person p WHERE '
. 'LOWER(p.name) LIKE LOWER(:name)'
. ' OR LOWER(p.surname) LIKE LOWER(:surname)';
$query->setParameter('name', $form['name']->getData())
->setParameter('surname', $form['surname']->getData());
if ($this->container
->getParameter('cl_chill_person.search.use_double_metaphone')) {
$dql .= ' OR DOUBLEMETAPHONE(p.name) LIKE DOUBLEMETAPHONE(:name)';
}
$query->setDql($dql);
$alternatePersons = $query->getResult();
if (count($alternatePersons) === 0) {
return $this->forward('CLChillPersonBundle:Person:create');
}
$this->get('session')->getFlashBag()->add('info',
$this->get('translator')->trans(
'controller.Person.review.people_with_similar_name',
array('%nb%' => count($alternatePersons)))
);
return $this->render('CLChillPersonBundle:Person:create_review.html.twig',
array('alternatePersons' => $alternatePersons,
'name' => $form['name']->getData(),
'surname' => $form['surname']->getData(),
'dateOfBirth' => $form['dateOfBirth']->getData(),
'genre' => $form['genre']->getData(),
'creation_date' => $form['creation_date']->getData(),
'form' => $form->createView()));
}
/** /**
* easy getting a person by his id * easy getting a person by his id
* @return \CL\Chill\PersonBundle\Entity\Person * @return \CL\Chill\PersonBundle\Entity\Person

View File

@ -0,0 +1,77 @@
<?php
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 CreationPersonType extends AbstractType
{
private $form_status;
const NAME = 'cl_chill_personbundle_person_creation';
const FORM_NOT_REVIEWED = 'not_reviewed';
const FORM_REVIEWED = 'reviewed' ;
const FORM_BEING_REVIEWED = 'being_reviewed';
public function __construct($form_status = self::FORM_NOT_REVIEWED) {
$this->setStatus($form_status);
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($this->form_status === self::FORM_BEING_REVIEWED) {
$builder->add('name', 'hidden')
->add('surname', 'hidden')
->add('dateOfBirth', 'hidden')
->add('genre', 'hidden')
->add('creation_date', 'hidden')
->add('form_status', 'hidden')
;
} else {
$builder
->add('name')
->add('surname')
->add('dateOfBirth', 'date', array('required' => false, 'widget' => 'single_text'))
->add('genre', new GenderType(), array(
'required' => false
))
->add('creation_date', 'date', array('required' => true,
'widget' => 'single_text', 'data' => new \DateTime()))
->add('form_status', 'hidden', array('data' => $this->form_status))
;
}
}
private function setStatus($status) {
$this->form_status = $status;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
// $resolver->setDefaults(array(
// 'data_class' => 'CL\Chill\PersonBundle\Entity\Person'
// ));
}
/**
* @return string
*/
public function getName()
{
return self::NAME;
}
}

View File

@ -16,6 +16,18 @@ chill_person_general_update:
pattern: /view/{id}/update pattern: /view/{id}/update
defaults: {_controller: CLChillPersonBundle:Person:update } defaults: {_controller: CLChillPersonBundle:Person:update }
chill_person_new:
pattern: /new
defaults: {_controller: CLChillPersonBundle:Person:new }
chill_person_review:
pattern: /review
defaults: {_controller: CLChillPersonBundle:Person:review }
chill_person_create:
pattern: /create
defaults: {_controller: CLChillPersonBundle:Person:create }
chill_person_search: chill_person_search:
pattern: /search pattern: /search

View File

@ -7,17 +7,17 @@ CL\Chill\PersonBundle\Entity\Person:
groups: [general] groups: [general]
name: name:
- NotBlank: - NotBlank:
groups: [general] groups: [general, creation]
- Length: - Length:
min: 2 min: 2
max: 255 max: 255
minMessage: validation.Person.constraint.name_min minMessage: validation.Person.constraint.name_min
maxMessage: validation.Person.constraint.name_max maxMessage: validation.Person.constraint.name_max
groups: [general] groups: [general, creation]
surname: surname:
- NotBlank: - NotBlank:
groups: [general] groups: [general, creation]
- Length: - Length:
min: 2 min: 2
max: 255 max: 255
@ -26,7 +26,8 @@ CL\Chill\PersonBundle\Entity\Person:
groups: [general] groups: [general]
dateOfBirth: dateOfBirth:
- Date: - Date:
groups: [general] message: validation.Person.constraint.dateOfBirth.not_valid
groups: [general, creation]
nbOfChild: nbOfChild:
- Range: - Range:
min: 0 min: 0
@ -48,11 +49,15 @@ CL\Chill\PersonBundle\Entity\Person:
CL\Chill\PersonBundle\Entity\PersonHistoryFile: CL\Chill\PersonBundle\Entity\PersonHistoryFile:
properties: properties:
date_opening: date_opening:
- Date: ~ - Date:
- NotNull: ~ message: validation.history.date_opening.not_valid
date_closing:
- Date: ~
- NotNull: - NotNull:
message: validation.history.date_opening.not_null
date_closing:
- Date:
message: validation.history.date_closing.not_valid
- NotNull:
message: validation.history.date_closing.not_null
groups: [closed] groups: [closed]
constraints: constraints:
- Callback: - Callback:

View File

@ -2,7 +2,9 @@ person:
name: Nom name: Nom
surname: Prénom surname: Prénom
dateOfBirth: Date de naissance dateOfBirth: Date de naissance
without_date_of_birth: Date de naissance inconnue
nationality: Nationalité nationality: Nationalité
without_nationality: Sans nationalité
civil_union: civil_union:
divorced: Divorcé divorced: Divorcé
separated: Séparé separated: Séparé
@ -33,6 +35,9 @@ validation:
error: '{1} Le champs %field% est incorrect. Veuillez le corriger. | ]1, Inf] Plusieurs champs sont incorrects. Veuillez les vérifier.' error: '{1} Le champs %field% est incorrect. Veuillez le corriger. | ]1, Inf] Plusieurs champs sont incorrects. Veuillez les vérifier.'
controller: controller:
Person: Person:
review:
people_with_similar_name: %nb% personnes ont un nom similaire. Vérifiez qu'il ne s'agit pas de l'une d'elles.
problem_with_data: Les données de votre formulaire sont invalides.
history: history:
close: close:
done: Bravo ! Le dossier de <em>%name%</em> a été clotûré. done: Bravo ! Le dossier de <em>%name%</em> a été clotûré.
@ -113,6 +118,17 @@ views:
motive_of_closing: Motif de clôture motive_of_closing: Motif de clôture
texto: Mémo texto: Mémo
action: Modifier action: Modifier
creation:
add: Ajouter
open: Ouverture d'un dossier
review:
altName: Nom
altDateOfBirth: Prénom
altNationality: Nationalité
confirm_creation: Confirmer la création
creation_date: Date d'ouverture
you_will_create_this_person: Vous allez créer le dossier suivant

View File

@ -6,6 +6,8 @@ validation:
nbOfChild_min: Ce nombre est négatif. Il ne peut y avoir moins de 0 enfants. nbOfChild_min: Ce nombre est négatif. Il ne peut y avoir moins de 0 enfants.
nbOfChild_max: Ce nombre est trop élevé. Il ne peut être supérieur à {{ limit }}. nbOfChild_max: Ce nombre est trop élevé. Il ne peut être supérieur à {{ limit }}.
nbOfChild_invalid: La valeur introduite n'est pas un nombre. nbOfChild_invalid: La valeur introduite n'est pas un nombre.
dateOfBirth:
not_valid: La date de naissance n'est pas valide.
history: history:
opening_is_before_closing: L'historique des ouvertures et fermetures de dossier n'est pas cohérent. Des historiques d'ouverture et de fermeture se chevauchent. Vérifiez la liste des ouvertures et fermetures. opening_is_before_closing: L'historique des ouvertures et fermetures de dossier n'est pas cohérent. Des historiques d'ouverture et de fermeture se chevauchent. Vérifiez la liste des ouvertures et fermetures.
open_history_without_closing: Vous tentez d'ouvrir un dossier à une date passée alors qu'il est réouvert plus tard. Veuillez insérer une nouvelle ligne d'ouverture avant de la clotûrer avant la suivante. open_history_without_closing: Vous tentez d'ouvrir un dossier à une date passée alors qu'il est réouvert plus tard. Veuillez insérer une nouvelle ligne d'ouverture avant de la clotûrer avant la suivante.