Commit c1a95292 authored by Patrick Etcheverry's avatar Patrick Etcheverry

Intégration bouton radio pour la création de question

parent a4d9ff20
sequenceQuestion: "Sequence Question"
sessionQuestion: "Session Question"
generalQuestion: "General Question"
scenarisationStage: "Scenarisation stage"
scenarisationProcess: "Scenarisation process"
question : "Question"
......
sequenceQuestion: ""
sessionQuestion: ""
generalQuestion: ""
scenarisationStage: ""
scenarisationProcess: ""
question: "Pregunta"
......
sequenceQuestion: "Question Séquence"
sessionQuestion: "Question Séance"
generalQuestion: "Question Générale"
scenarisationStage: "Etape de scénarisation"
scenarisationProcess: "Démarche de scénarisation"
question: "Question"
......
......@@ -6,6 +6,14 @@ use ScenarisationProcessBundle\Entity\Question;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
// Pour les formulaires
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use ScenarisationProcessBundle\Entity\SessionQuestion;
use ScenarisationProcessBundle\Entity\SequenceQuestion;
use ScenarisationProcessBundle\Entity\GeneralQuestion;
/**
* Question controller.
*
......@@ -42,21 +50,33 @@ class QuestionController extends Controller
*/
public function newAction(Request $request)
{
$question = new Question();
$form = $this->createForm('ScenarisationProcessBundle\Form\QuestionType', $question);
$form->handleRequest($request);
/* On construit un tableau dans lequel les données du formulaire
seront recueillies */
$data = array();
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($question);
$em->flush();
$editForm = $this->createQuestionForm($data);
$editForm->handleRequest($request);
return $this->redirectToRoute('question_show', array('id' => $question->getId()));
if ($editForm->isSubmitted())
{
$dataReceived = $editForm->getData();
if ($this->questionFormIsValid($dataReceived))
{
$question = $this->createQuestionFromForm($dataReceived);
$em = $this->getDoctrine()->getManager();
$em->persist($question);
$em->flush();
return $this->redirectToRoute('question_show', array('id' => $question->getId()));
}
}
return $this->render('ScenarisationProcessBundle:question:new.html.twig', array(
'question' => $question,
'form' => $form->createView(),
'form' => $editForm->createView()//$form->createView(),
));
}
......@@ -81,7 +101,8 @@ class QuestionController extends Controller
public function editAction(Request $request, Question $question)
{
$deleteForm = $this->createDeleteForm($question);
$editForm = $this->createForm('ScenarisationProcessBundle\Form\QuestionType', $question);
$editForm = $this->createForm('ScenarisationProcessBundle\Form\QuestionType', $question);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
......@@ -130,4 +151,77 @@ class QuestionController extends Controller
->getForm()
;
}
private function questionFormIsValid($questionForm)
{
if ( isset($questionForm['enWording']) &&
isset($questionForm['frWording']) &&
isset($questionForm['esWording']) &&
isset($questionForm['type']) )
{
if ( !empty($questionForm['enWording']) &&
!empty($questionForm['frWording']) &&
!empty($questionForm['esWording']) &&
!empty($questionForm['type']))
{
if ($questionForm['type'] == "sessionQuestion" ||
$questionForm['type'] == "sequenceQuestion" ||
$questionForm['type'] == "generalQuestion")
{
return true;
}
}
}
else
{
return false;
}
}
private function createQuestionForm($data)
{
$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('type', ChoiceType::class, array(
'choices' => array(
'generalQuestion' => 'generalQuestion',
'sequenceQuestion' => 'sequenceQuestion',
'sessionQuestion' => 'sessionQuestion'
),
'expanded' => true,
'multiple' => false
));
return $form->getForm();
}
private function createQuestionFromForm($data)
{
switch ($data['type'])
{
case 'generalQuestion':
$question = new GeneralQuestion();
break;
case 'sequenceQuestion':
$question = new SequenceQuestion();
break;
case 'sessionQuestion' :
$question = new SessionQuestion();
break;
}
$question->setEnWording($data['enWording']);
$question->setFrWording($data['frWording']);
$question->setEsWording($data['esWording']);
return $question;
}
}
......@@ -7,6 +7,8 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class QuestionType extends AbstractType
{
/**
......@@ -14,9 +16,19 @@ class QuestionType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('enWording',TextareaType::class, array("label" => "enWording"));
$builder->add('frWording',TextareaType::class, array("label" => "frWording"));
$builder->add('esWording',TextareaType::class, array("label" => "esWording"));
$builder->add('enWording',TextareaType::class, array("label" => "enWording"));
$builder->add('frWording',TextareaType::class, array("label" => "frWording"));
$builder->add('esWording',TextareaType::class, array("label" => "esWording"));
$builder->add('type', ChoiceType::class, array(
'choices' => array(
'generalQuestion' => 'generalQuestion',
'sequenceQuestion' => 'sequenceQuestion',
'sessionQuestion' => 'sessionQuestion'
),
'expanded' => true,
'multiple' => false
));
}
/**
......
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