Ejemplo n.º 1
0
 public function ajoutAction(Request $request)
 {
     // Si on est du role Admin, on est redirigé
     if ($this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
         return $this->redirect($this->generateUrl("mq_quizi_admin_quizs"));
     }
     // Creation formulaire
     $data = array();
     $form = $this->createFormBuilder($data)->add('nomQuiz', 'text')->add('affichageFinal', 'choice', array('choices' => array('1' => 'Score', '2' => 'Score + Résultat par question', '3' => 'Score + Résultat par question + Bonne réponse'), 'multiple' => false, 'expanded' => true))->add('nomQuestion', 'text')->add('rep1', 'text')->add('rep2', 'text')->add('rep3', 'text', array('required' => false))->add('rep4', 'text', array('required' => false))->add('reponseCorrect', 'choice', array('choices' => array('1' => 'Réponse 1', '2' => 'Réponse 2', '3' => 'Réponse 3', '4' => 'Réponse 4'), 'multiple' => false, 'expanded' => true))->add('btnCreer', 'submit', array('label' => 'Créer le Quiz', 'attr' => array('class' => 'btn waves-effect waves-light')))->getForm();
     // Résultat Formulaire
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $data = $form->getData();
             // Si les champs obligatoire ne sont pas vide
             if ($data['nomQuiz'] != null && $data['nomQuestion'] != null && $data['rep1'] != null && $data['rep2'] != null && $data['reponseCorrect'] != null && $data['affichageFinal'] != null) {
                 // Si une case de réponse correct est cochée et cette réponse est vide
                 if ($data['rep4'] == null && $data['reponseCorrect'] == 4 || $data['rep3'] == null && $data['reponseCorrect'] == 3) {
                     $session = $request->getSession();
                     $session->getFlashBag()->add('infoError', 'Vous avez coché une réponse correcte qui est vide');
                     return $this->render('MQQuiziBundle:AdminQuizs:adminAddQuizs.html.twig', array('form' => $form->createView()));
                 } else {
                     if ($this->regexScript($data['rep1']) && $this->regexScript($data['rep2']) && $this->regexScript($data['rep3']) && $this->regexScript($data['rep4'])) {
                         // On ajoute la question et on redemande le formulaire
                         if ($form->get('btnCreer')->isClicked()) {
                             $em = $this->getDoctrine()->getManager();
                             $quiz = new Quiz();
                             $quiz->setTitreQuiz($data['nomQuiz']);
                             $quiz->setAffichageFinalQuiz($data['affichageFinal']);
                             date_default_timezone_set('UTC');
                             $date = date('d-m-Y');
                             $quiz->setDateCreationQuiz(new \DateTime($date));
                             $quiz->setUser($this->get('security.context')->getToken()->getUser());
                             // Ajout du quiz dans la BDD
                             $em->persist($quiz);
                             $em->flush();
                             $this->addOrUpdateQuestion($quiz, $data);
                             $session = $request->getSession();
                             $session->getFlashBag()->add('info', 'Quiz ajouté avec succès');
                             return $this->redirectToRoute('mq_quizi_modif_quizs', array('idQuiz' => $quiz->getId()));
                         }
                     } else {
                         $session = $request->getSession();
                         $session->getFlashBag()->add('infoError', 'Vous n\'êtes pas autorisé à entrer ce genre de données ...');
                         return $this->render('MQQuiziBundle:AdminQuizs:adminAddQuizs.html.twig', array('form' => $form->createView()));
                     }
                 }
             } else {
                 $session = $request->getSession();
                 $session->getFlashBag()->add('infoError', 'Certains champs sont vides');
                 return $this->render('MQQuiziBundle:AdminQuizs:adminAddQuizs.html.twig', array('form' => $form->createView()));
             }
         } else {
             return $this->render('MQQuiziBundle:AdminQuizs:adminAddQuizs.html.twig', array('form' => $form->createView(), 'error' => 'Formulaire non valide'));
         }
     }
     return $this->render('MQQuiziBundle:AdminQuizs:adminAddQuizs.html.twig', array('form' => $form->createView()));
 }
Ejemplo n.º 2
0
 public function load(ObjectManager $manager)
 {
     /*
      *
      * QUIZ 1 --> QUI VEUT GAGNER DE L'ARGENT EN MASSE ?
      *
      */
     // Ajout du quiz dans la BDD
     $quiz = new Quiz();
     $quiz->setTitreQuiz("Qui veut gagner d'l'argent en masse ?");
     $quiz->setAffichageFinalQuiz("3");
     date_default_timezone_set('UTC');
     $date = date('d-m-Y');
     $quiz->setDateCreationQuiz(new \DateTime($date));
     $quiz->setUser($this->getReference('user'));
     // Ajout du quiz dans la BDD
     $manager->persist($quiz);
     $manager->flush();
     // --------------------------------------------------------------
     // QUESTION 1
     $question = new Question();
     $question->setTitreQuestion("Lorsqu'un pancake tombe dans la neige avant le 31 décembre, on dit qu'il est :");
     $question->setQuiz($quiz);
     // Les réponses
     $reponse1 = new Reponse();
     $reponse2 = new Reponse();
     $reponse3 = new Reponse();
     $reponse4 = new Reponse();
     $reponse1->setTitreReponse("tombé dans la neige avant le 31 décembre");
     $reponse1->setBonneReponse(0);
     $reponse2->setTitreReponse("un frizby comestible");
     $reponse2->setBonneReponse(0);
     $reponse3->setTitreReponse("une kipa surgelée");
     $reponse3->setBonneReponse(1);
     $reponse4->setTitreReponse("la réponse D");
     $reponse4->setBonneReponse(0);
     $question->addReponse($reponse1);
     $question->addReponse($reponse2);
     $question->addReponse($reponse3);
     $question->addReponse($reponse4);
     $manager->persist($reponse1);
     $manager->persist($reponse2);
     $manager->persist($reponse3);
     $manager->persist($reponse4);
     $manager->persist($question);
     $manager->flush();
     // --------------------------------------------------------------
     // QUESTION 2
     $question = new Question();
     $question->setTitreQuestion("Lorsqu'un pancake prend l'avion à destination de Toronto et qu'il fait une escale technique à St Claude, on dit :");
     $question->setQuiz($quiz);
     // Les réponses
     $reponse1 = new Reponse();
     $reponse2 = new Reponse();
     $reponse3 = new Reponse();
     $reponse4 = new Reponse();
     $reponse1->setTitreReponse("qu'il n'est pas arrivé à Toronto");
     $reponse1->setBonneReponse(0);
     $reponse2->setTitreReponse("qu'il était supposé arriver à Toronto");
     $reponse2->setBonneReponse(0);
     $reponse3->setTitreReponse("qu'est ce qu'il fout ce maudit pancake tabernacle ?");
     $reponse3->setBonneReponse(1);
     $reponse4->setTitreReponse("la réponse D");
     $reponse4->setBonneReponse(0);
     $question->addReponse($reponse1);
     $question->addReponse($reponse2);
     $question->addReponse($reponse3);
     $question->addReponse($reponse4);
     $manager->persist($reponse1);
     $manager->persist($reponse2);
     $manager->persist($reponse3);
     $manager->persist($reponse4);
     $manager->persist($question);
     $manager->flush();
     // --------------------------------------------------------------
     // QUESTION 3
     $question = new Question();
     $question->setTitreQuestion("Lorsqu'on invite un pancake à une Barmitzva, les convivent doivent :");
     $question->setQuiz($quiz);
     // Les réponses
     $reponse1 = new Reponse();
     $reponse2 = new Reponse();
     $reponse3 = new Reponse();
     $reponse4 = new Reponse();
     $reponse1->setTitreReponse("l'inciter à boire à l'Open Barmitzva");
     $reponse1->setBonneReponse(1);
     $reponse2->setTitreReponse("lui présenter Raymond Barmitzva");
     $reponse2->setBonneReponse(0);
     $reponse3->setTitreReponse("lui offrir des Malabarmitzva");
     $reponse3->setBonneReponse(0);
     $reponse4->setTitreReponse("la réponse D");
     $reponse4->setBonneReponse(0);
     $question->addReponse($reponse1);
     $question->addReponse($reponse2);
     $question->addReponse($reponse3);
     $question->addReponse($reponse4);
     $manager->persist($reponse1);
     $manager->persist($reponse2);
     $manager->persist($reponse3);
     $manager->persist($reponse4);
     $manager->persist($question);
     $manager->flush();
     // --------------------------------------------------------------
     // QUESTION 4
     $question = new Question();
     $question->setTitreQuestion("Au cours de quel évènement historique fut créé le pancake ?");
     $question->setQuiz($quiz);
     // Les réponses
     $reponse1 = new Reponse();
     $reponse2 = new Reponse();
     $reponse3 = new Reponse();
     $reponse4 = new Reponse();
     $reponse1->setTitreReponse("En 1618, pendant la guerre des croissants au beurre");
     $reponse1->setBonneReponse(0);
     $reponse2->setTitreReponse("En 1702, pendant le massacre de la Saint Panini");
     $reponse2->setBonneReponse(0);
     $reponse3->setTitreReponse("En 112 avant Céline, pendant la prise de la brioche");
     $reponse3->setBonneReponse(1);
     $reponse4->setTitreReponse("la réponse D");
     $reponse4->setBonneReponse(0);
     $question->addReponse($reponse1);
     $question->addReponse($reponse2);
     $question->addReponse($reponse3);
     $question->addReponse($reponse4);
     $manager->persist($reponse1);
     $manager->persist($reponse2);
     $manager->persist($reponse3);
     $manager->persist($reponse4);
     $manager->persist($question);
     $manager->flush();
     /*
      *
      * QUIZ 2 --> LES MATHS POUR LES NULS !
      *
      */
     // Ajout du quiz dans la BDD
     $quiz = new Quiz();
     $quiz->setTitreQuiz("Les Maths pour les nuls !");
     $quiz->setAffichageFinalQuiz("1");
     date_default_timezone_set('UTC');
     $date = date('d-m-Y');
     $quiz->setDateCreationQuiz(new \DateTime($date));
     $quiz->setUser($this->getReference('user'));
     // Ajout du quiz dans la BDD
     $manager->persist($quiz);
     $manager->flush();
     // --------------------------------------------------------------
     // QUESTION 1
     $question = new Question();
     $titreQuestion = "<svg width=\"400\" height=\"110\"><rect width=\"300\" height=\"100\" style=\"fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)\">Sorry, your browser does not support inline SVG.</svg>";
     $question->setTitreQuestion("Que represente cette forme : <br>" . $titreQuestion);
     $question->setQuiz($quiz);
     // Les réponses
     $reponse1 = new Reponse();
     $reponse2 = new Reponse();
     $reponse3 = new Reponse();
     $reponse4 = new Reponse();
     $reponse1->setTitreReponse("Un carré");
     $reponse1->setBonneReponse(0);
     $reponse2->setTitreReponse("Un cercle");
     $reponse2->setBonneReponse(0);
     $reponse3->setTitreReponse("Un triangle");
     $reponse3->setBonneReponse(0);
     $reponse4->setTitreReponse("Un rectangle");
     $reponse4->setBonneReponse(1);
     $question->addReponse($reponse1);
     $question->addReponse($reponse2);
     $question->addReponse($reponse3);
     $question->addReponse($reponse4);
     $manager->persist($reponse1);
     $manager->persist($reponse2);
     $manager->persist($reponse3);
     $manager->persist($reponse4);
     $manager->persist($question);
     $manager->flush();
     // --------------------------------------------------------------
     // QUESTION 2
     $question = new Question();
     $question->setTitreQuestion("Qu'est ce qu'un triangle ?");
     $question->setQuiz($quiz);
     // Les réponses
     $reponse1 = new Reponse();
     $reponse2 = new Reponse();
     $reponse3 = new Reponse();
     $reponse4 = new Reponse();
     $reponse1->setTitreReponse("<svg width=\"400\" height=\"110\"><rect width=\"300\" height=\"100\" style=\"fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)\">Sorry, your browser does not support inline SVG.</svg>");
     $reponse1->setBonneReponse(0);
     $reponse2->setTitreReponse("<svg height=\"100\" width=\"100\"><circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"3\" fill=\"red\" />Sorry, your browser does not support inline SVG.</svg>");
     $reponse2->setBonneReponse(0);
     $reponse3->setTitreReponse("<svg height=\"210\" width=\"400\"><path d=\"M150 0 L75 200 L225 200 Z\" />Sorry, your browser does not support inline SVG.</svg>");
     $reponse3->setBonneReponse(1);
     $reponse4->setTitreReponse("<svg height=\"210\" width=\"500\"><polygon points=\"100,10 40,198 190,78 10,78 160,198\" style=\"fill:lime;stroke:purple;stroke-width:5;fill-rule:nonzero;\"/>Sorry, your browser does not support inline SVG.</svg>");
     $reponse4->setBonneReponse(0);
     $question->addReponse($reponse1);
     $question->addReponse($reponse2);
     $question->addReponse($reponse3);
     $question->addReponse($reponse4);
     $manager->persist($reponse1);
     $manager->persist($reponse2);
     $manager->persist($reponse3);
     $manager->persist($reponse4);
     $manager->persist($question);
     $manager->flush();
     // --------------------------------------------------------------
     // QUESTION 3
     $question = new Question();
     $titreQuestion = "<math display=\"block\"><mrow><mfrac><mrow><mi>4</mi><mo>+</mo><msup><mi>4</mi><mn>2</mn></msup></mrow><mrow><mi>2</mi><mo>+</mo><mn>3</mn></mrow></mfrac></mrow></math>";
     $question->setTitreQuestion("Quel est le résultat de " . $titreQuestion);
     $question->setQuiz($quiz);
     // Les réponses
     $reponse1 = new Reponse();
     $reponse2 = new Reponse();
     $reponse3 = new Reponse();
     $reponse4 = new Reponse();
     $reponse1->setTitreReponse("2");
     $reponse1->setBonneReponse(0);
     $reponse2->setTitreReponse("4");
     $reponse2->setBonneReponse(1);
     $reponse3->setTitreReponse("5");
     $reponse3->setBonneReponse(0);
     $reponse4->setTitreReponse("10");
     $reponse4->setBonneReponse(0);
     $question->addReponse($reponse1);
     $question->addReponse($reponse2);
     $question->addReponse($reponse3);
     $question->addReponse($reponse4);
     $manager->persist($reponse1);
     $manager->persist($reponse2);
     $manager->persist($reponse3);
     $manager->persist($reponse4);
     $manager->persist($question);
     $manager->flush();
     // --------------------------------------------------------------
     // QUESTION 4
     $question = new Question();
     $question->setTitreQuestion("A quoi est égal 5 ?");
     $question->setQuiz($quiz);
     // Les réponses
     $reponse1 = new Reponse();
     $reponse2 = new Reponse();
     $reponse3 = new Reponse();
     $reponse4 = new Reponse();
     $reponse1->setTitreReponse("<math display=\"block\"><mrow><mfrac><mrow><mi>6</mi><mo>+</mo><msup><mi>4</mi><mn>2</mn></msup></mrow><mrow><mi>2</mi><mo>+</mo><mn>3</mn></mrow></mfrac></mrow></math>");
     $reponse1->setBonneReponse(0);
     $reponse2->setTitreReponse("<math display=\"block\"><mrow><mfrac><mrow><mi>4</mi><mo>+</mo><msup><mi>4</mi><mn>2</mn></msup></mrow><mrow><mi>2</mi><mo>+</mo><mn>3</mn></mrow></mfrac></mrow></math>");
     $reponse2->setBonneReponse(0);
     $reponse3->setTitreReponse("<math display=\"block\"><mrow><mfrac><mrow><mi>4</mi><mo>+</mo><msup><mi>4</mi><mn>2</mn></msup></mrow><mrow><mi>2</mi><mo>+</mo><mn>2</mn></mrow></mfrac></mrow></math>");
     $reponse3->setBonneReponse(1);
     $reponse4->setTitreReponse("<math display=\"block\"><mrow><mfrac><mrow><mi>4</mi><mo>+</mo><msup><mi>4</mi><mn>2</mn></msup></mrow><mrow><mi>-1</mi><mo>+</mo><mn>3</mn></mrow></mfrac></mrow></math>");
     $reponse4->setBonneReponse(0);
     $question->addReponse($reponse1);
     $question->addReponse($reponse2);
     $question->addReponse($reponse3);
     $question->addReponse($reponse4);
     $manager->persist($reponse1);
     $manager->persist($reponse2);
     $manager->persist($reponse3);
     $manager->persist($reponse4);
     $manager->persist($question);
     $manager->flush();
 }
 /**
  * {@inheritDoc}
  */
 public function setTitreQuiz($titreQuiz)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setTitreQuiz', array($titreQuiz));
     return parent::setTitreQuiz($titreQuiz);
 }