Commit b45b529d authored by Julien Fastré's avatar Julien Fastré

person creation: fix bug + improve multi_center

The center is hidden in page "check if the person exists in the db"
parent 07ed6a97
Pipeline #270 failed with stage
......@@ -174,10 +174,12 @@ class PersonController extends Controller
->setCenter($defaultCenter);
$form = $this->createForm(
new CreationPersonType(CreationPersonType::FORM_NOT_REVIEWED),
CreationPersonType::NAME,
$person,
array('action' => $this->generateUrl('chill_person_review'))
);
array(
'action' => $this->generateUrl('chill_person_review'),
'form_status' => CreationPersonType::FORM_NOT_REVIEWED
));
return $this->_renderNewForm($form);
}
......@@ -254,9 +256,12 @@ class PersonController extends Controller
}
$form = $this->createForm(
new CreationPersonType(CreationPersonType::FORM_BEING_REVIEWED),
CreationPersonType::NAME,
new Person(),
array('action' => $this->generateUrl('chill_person_create')));
array(
'action' => $this->generateUrl('chill_person_create'),
'form_status' => CreationPersonType::FORM_BEING_REVIEWED
));
$form->handleRequest($request);
......@@ -277,9 +282,12 @@ class PersonController extends Controller
}
$form = $this->createForm(
new CreationPersonType(CreationPersonType::FORM_NOT_REVIEWED),
CreationPersonType::NAME,
new Person(),
array('action' => $this->generateUrl('chill_person_review')));
array(
'action' => $this->generateUrl('chill_person_review'),
'form_status' => CreationPersonType::FORM_NOT_REVIEWED
));
$form->handleRequest($request);
......@@ -338,10 +346,12 @@ class PersonController extends Controller
return $r;
}
$form = $this->createForm(new CreationPersonType());
$form = $this->createForm(CreationPersonType::NAME, null, array(
'form_status' => CreationPersonType::FORM_REVIEWED
));
$form->handleRequest($request);
var_dump($form->getData());
$person = $this->_bindCreationForm($form);
$errors = $this->_validatePersonAndAccompanyingPeriod($person);
......
......@@ -23,23 +23,28 @@ namespace Chill\PersonBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Chill\PersonBundle\Form\Type\GenderType;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer;
class CreationPersonType extends AbstractType
{
private $form_status;
const NAME = '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);
/**
*
* @var CenterTransformer
*/
private $centerTransformer;
public function __construct(CenterTransformer $centerTransformer) {
$this->centerTransformer = $centerTransformer;
}
/**
......@@ -48,7 +53,7 @@ class CreationPersonType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($this->form_status === self::FORM_BEING_REVIEWED) {
if ($options['form_status'] === self::FORM_BEING_REVIEWED) {
$dateToStringTransformer = new DateTimeToStringTransformer(
null, null, 'd-m-Y', false);
......@@ -63,14 +68,17 @@ class CreationPersonType extends AbstractType
'mapped' => false
))
->add('form_status', 'hidden', array(
'mapped' => false
'mapped' => false,
'data' => $options['form_status']
))
->add('center', 'center')
->add('center', 'hidden')
;
$builder->get('birthdate')
->addModelTransformer($dateToStringTransformer);
$builder->get('creation_date', 'hidden')
$builder->get('creation_date')
->addModelTransformer($dateToStringTransformer);
$builder->get('center')
->addModelTransformer($this->centerTransformer);
} else {
$builder
->add('firstName')
......@@ -87,26 +95,29 @@ class CreationPersonType extends AbstractType
'mapped' => false,
'data' => new \DateTime()))
->add('form_status', 'hidden', array(
'data' => $this->form_status,
'data' => $options['form_status'],
'mapped' => false
))
->add('center', 'center')
;
}
}
private function setStatus($status) {
$this->form_status = $status;
}
/**
* @param OptionsResolverInterface $resolver
* @param OptionsResolver $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chill\PersonBundle\Entity\Person'
));
$resolver->setRequired('form_status')
->setAllowedValues('form_status', array(
self::FORM_BEING_REVIEWED,
self::FORM_NOT_REVIEWED,
self::FORM_REVIEWED
));
}
/**
......
......@@ -56,3 +56,10 @@ services:
tags:
- { name: validator.constraint_validator, alias: birthdate_not_before }
chill.main.form.person_creation:
class: Chill\PersonBundle\Form\CreationPersonType
arguments:
- "@chill.main.form.data_transformer.center_transformer"
tags:
- { name: form.type, alias: chill_personbundle_person_creation }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment