Exemplo n.º 1
0
 /**
  * Export submitted answers for one Question of the Paper.
  *
  * @param Question $question
  * @param Paper    $paper
  * @param bool     $withScore Do we need to export the score of the Paper ?
  *
  * @return array
  *
  * @throws \UJM\ExoBundle\Transfer\Json\UnregisteredHandlerException
  */
 public function exportPaperAnswer(Question $question, Paper $paper, $withScore = false)
 {
     $responseRepo = $this->om->getRepository('UJMExoBundle:Response');
     $handler = $this->handlerCollector->getHandlerForInteractionType($question->getType());
     // TODO: these two queries must be moved out of the loop
     $response = $responseRepo->findOneBy(['paper' => $paper, 'question' => $question]);
     $usedHints = $this->hintManager->getUsedHints($paper, $question);
     $hints = array_map(function ($hint) {
         return $this->hintManager->exportHint($hint, true);
         // We always grab hint value for used hints
     }, $usedHints);
     $answer = $response ? $handler->convertAnswerDetails($response) : null;
     $answerScore = $response ? $response->getMark() : 0;
     $nbTries = $response ? $response->getNbTries() : 0;
     $paperQuestion = null;
     if ($response || count($hints) > 0) {
         $paperQuestion = ['id' => $question->getId(), 'answer' => $answer, 'hints' => $hints, 'nbTries' => $nbTries, 'score' => $withScore ? $answerScore : null];
     }
     return $paperQuestion;
 }
Exemplo n.º 2
0
 /**
  * Ensures the format of the answer is correct and returns a list of
  * validation errors, if any.
  *
  * @param Question $question
  * @param mixed    $data
  *
  * @return array
  *
  * @throws \UJM\ExoBundle\Transfer\Json\UnregisteredHandlerException
  */
 public function validateAnswerFormat(Question $question, $data)
 {
     $handler = $this->handlerCollector->getHandlerForInteractionType($question->getType());
     return $handler->validateAnswerFormat($question, $data);
 }
Exemplo n.º 3
0
 /**
  * call method to export a question.
  *
  * @param \UJM\ExoBundle\Entity\Question $question
  */
 public function export($question)
 {
     if ($question->getType() !== InteractionOpen::TYPE) {
         $service = 'ujm.exo_qti_export_' . $question->getType();
         $qtiExport = $this->container->get($service);
     } else {
         $qtiExport = $this->serviceOpenQuestion($question->getId());
     }
     return $qtiExport->export($question, $this);
 }