Пример #1
0
 public function addAction(Request $request)
 {
     var_dump($request->get('_affinite'));
     die;
     $em = $this->getDoctrine()->getEntityManager();
     //get qcm s'il existe.
     $qcm = $em->getRepository('GenericBundle:Qcmdef')->findOneBy(array('nom' => $request->get('_Nom')));
     if (!$qcm) {
         //s'il n'existe pas le créer.
         $newqcm = new Qcmdef();
         $newqcm->setNom($request->get('_Nom'));
         $newqcm->setAffinite(intval($request->get('_affinite')));
         $em->persist($newqcm);
         $em->flush();
         $qcm = $newqcm;
     }
     $em->flush();
     $questions = array();
     $questionorder = 0;
     if ($request->get('questions')) {
         foreach ($request->get('questions') as $value) {
             //get Question s'elle existe.
             $question = $em->getRepository('GenericBundle:Questiondef')->findOneBy(array('question' => $value, 'qcmdef' => $qcm));
             if (!$question) {
                 //S'elle n'existe pas la créer.
                 $newquestion = new Questiondef();
                 $newquestion->setQuestion($value);
                 $newquestion->setQcmdef($qcm);
                 $em->persist($newquestion);
                 $em->flush();
                 $question = $newquestion;
             }
             $question->setOrdre($questionorder++);
             $em->flush();
             array_push($questions, $question);
         }
         $i = 0;
         foreach ($request->get('reponse') as $reponses) {
             $reponseorder = 0;
             foreach ($reponses as $rep) {
                 //get Reponse s'elle existe.
                 $reponse = $em->getRepository('GenericBundle:Reponsedef')->findOneBy(array('reponse' => $rep, 'questiondef' => $questions[$i]));
                 if (!$reponse) {
                     //S'elle n'existe pas la créer.
                     $newreponse = new Reponsedef();
                     $newreponse->setReponse($rep);
                     $newreponse->setQuestiondef($questions[$i]);
                     $em->persist($newreponse);
                     $em->flush();
                     $reponse = $newreponse;
                 }
                 $reponse->setOrdre($reponseorder++);
                 $em->flush();
             }
             $i++;
         }
     }
     return $this->render('AdminBundle:Admin:iFrameContent.html.twig');
 }
Пример #2
0
 static function sort_reponses_by_order(\GenericBundle\Entity\Reponsedef $a, \GenericBundle\Entity\Reponsedef $b)
 {
     if ($a->getOrdre() == $b->getOrdre()) {
         return 0;
     }
     return $a->getOrdre() < $b->getOrdre() ? -1 : 1;
 }