示例#1
0
 /**
  * Set questionnaire
  *
  * @param \AppBundle\Entity\Questionnaire $questionnaire
  *
  * @return Reponses
  */
 public function setQuestionnaire(\AppBundle\Entity\Questionnaire $questionnaire = null)
 {
     $this->questionnaire = $questionnaire;
     $this->listreponses->clear();
     foreach ($questionnaire->getQuestions() as $key => $question) {
         $reponse = new Reponse();
         $reponse->setQuestion($question->getQuestion());
         $reponse->setReponses($this);
         $this->addListreponse($reponse);
     }
     return $this;
 }
 private function saveResponses($formQuestion, $question, $modif)
 {
     for ($cptReponse = 1; $cptReponse < 5; $cptReponse++) {
         if ($formQuestion['response' . $cptReponse]->getData() != null) {
             if ($modif) {
                 $response = $this->getDoctrine()->getManager()->getRepository('AppBundle:Reponse')->findOneBy(array('question' => $question->getId()), array(), 1, $cptReponse - 1);
             } else {
                 $response = new Reponse();
                 $response->setQuestion($question);
             }
             $response->setDescription($formQuestion['response' . $cptReponse]->getData());
             $response->setValid($formQuestion['correct' . $cptReponse]->getData());
             $this->getDoctrine()->getManager()->persist($response);
         }
     }
     $this->getDoctrine()->getManager()->flush();
 }