Example #1
0
 /**
  * Records or updates an answer for a given question and paper.
  *
  * @param Paper    $paper
  * @param Question $question
  * @param mixed    $data
  * @param string   $ip
  */
 public function recordAnswer(Paper $paper, Question $question, $data, $ip)
 {
     $handler = $this->handlerCollector->getHandlerForInteractionType($question->getType());
     $response = $this->om->getRepository('UJMExoBundle:Response')->findOneBy(['paper' => $paper, 'question' => $question]);
     if (!$response) {
         $response = new Response();
         $response->setPaper($paper);
         $response->setQuestion($question);
         $response->setIp($ip);
     } else {
         $response->setNbTries($response->getNbTries() + 1);
     }
     $handler->storeAnswerAndMark($question, $response, $data);
     if (-1 !== $response->getMark()) {
         // Only apply penalties if the answer has been marked
         $this->applyPenalties($paper, $question, $response);
     }
     $this->om->persist($response);
     $this->om->flush();
 }