Commit 26984f0b authored by Patrick Etcheverry's avatar Patrick Etcheverry

Formulaire personnalisé de Question totalement implémenté

parent c1a95292
......@@ -50,22 +50,22 @@ class QuestionController extends Controller
*/
public function newAction(Request $request)
{
/* On construit un tableau dans lequel les données du formulaire
seront recueillies */
$data = array();
/* On construit un tableau dans lequel les données du formulaire
seront recueillies */
$donneesFormulaireQuestion = array();
$editForm = $this->createQuestionForm($data);
$editForm = $this->createQuestionForm($donneesFormulaireQuestion);
$editForm->handleRequest($request);
if ($editForm->isSubmitted())
{
$dataReceived = $editForm->getData();
$donneesFormulaireQuestionRecuperees = $editForm->getData();
if ($this->questionFormIsValid($dataReceived))
if ($this->questionFormIsValid($donneesFormulaireQuestionRecuperees))
{
$question = $this->createQuestionFromForm($dataReceived);
$question = $this->createQuestionEntityFromFormData($donneesFormulaireQuestionRecuperees);
$em = $this->getDoctrine()->getManager();
$em->persist($question);
......@@ -101,15 +101,37 @@ class QuestionController extends Controller
public function editAction(Request $request, Question $question)
{
$deleteForm = $this->createDeleteForm($question);
$editForm = $this->createForm('ScenarisationProcessBundle\Form\QuestionType', $question);
$editForm->handleRequest($request);
/* On construit un tableau dans lequel les données du formulaire
seront recueillies */
$donneesFormulaireQuestion = array();
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
/* On récupère les données déjà présentes */
$donneesFormulaireQuestion['enWording'] = $question->getEnWording();
$donneesFormulaireQuestion['frWording'] = $question->getFrWording();
$donneesFormulaireQuestion['esWording'] = $question->getEsWording();
$donneesFormulaireQuestion['type'] = $question->getType();
return $this->redirectToRoute('question_edit', array('id' => $question->getId()));
}
$editForm = $this->createQuestionForm($donneesFormulaireQuestion);
$editForm->handleRequest($request);
if ($editForm->isSubmitted())
{
$donneesFormulaireQuestionRecuperees = $editForm->getData();
if ($this->questionFormIsValid($donneesFormulaireQuestionRecuperees))
{
$question = $this->createQuestionEntityFromFormData($donneesFormulaireQuestionRecuperees);
$em = $this->getDoctrine()->getManager();
$em->persist($question);
$em->flush();
return $this->redirectToRoute('question_edit', array('id' => $question->getId()));
}
}
return $this->render('ScenarisationProcessBundle:question:edit.html.twig', array(
'question' => $question,
......@@ -186,9 +208,9 @@ class QuestionController extends Controller
{
$form = $this->createFormBuilder($data);
$form
->add('enWording',TextareaType::class, array("label" => "enWording"))
->add('frWording',TextareaType::class, array("label" => "frWording"))
->add('esWording',TextareaType::class, array("label" => "esWording"))
->add('enWording',TextareaType::class, array("label" => "enWording", "data" => (isset($data['enWording'])?$data['enWording']:'')))
->add('frWording',TextareaType::class, array("label" => "frWording", "data" => (isset($data['frWording'])?$data['frWording']:'')))
->add('esWording',TextareaType::class, array("label" => "esWording", "data" => (isset($data['esWording'])?$data['esWording']:'')))
->add('type', ChoiceType::class, array(
'choices' => array(
'generalQuestion' => 'generalQuestion',
......@@ -196,14 +218,15 @@ class QuestionController extends Controller
'sessionQuestion' => 'sessionQuestion'
),
'expanded' => true,
'multiple' => false
'multiple' => false,
'data' => (isset($data['type'])?$data['type']:'')
));
return $form->getForm();
}
private function createQuestionFromForm($data)
private function createQuestionEntityFromFormData($data)
{
switch ($data['type'])
{
......
......@@ -51,4 +51,9 @@ class GeneralQuestion extends Question
{
return $this->generalAnswers;
}
public function getType()
{
return 'generalQuestion';
}
}
......@@ -52,4 +52,8 @@ class SequenceQuestion extends Question
return $this->sequenceAnswers;
}
public function getType()
{
return 'sequenceQuestion';
}
}
......@@ -52,5 +52,8 @@ class SessionQuestion extends Question
return $this->sessionAnswers;
}
public function getType()
{
return 'sessionQuestion';
}
}
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