Esempio n. 1
0
 /**
  * Returns the value of a question hint, and records the fact that it has
  * been consulted within the context of a given paper.
  *
  * @EXT\Route(
  *     "",
  *     name="exercise_hint_show"
  * )
  * @EXT\ParamConverter("user", converter="current_user", options={"allowAnonymous"=true})
  *
  * @param Paper $paper
  * @param Hint  $hint
  * @param User  $user
  *
  * @return JsonResponse
  */
 public function showHintAction(Paper $paper, Hint $hint, User $user = null)
 {
     $this->assertHasPaperAccess($paper, $user);
     if (!$this->hintManager->hasHint($paper, $hint)) {
         return new JsonResponse('Hint and paper are not related', 422);
     }
     return new JsonResponse($this->hintManager->viewHint($paper, $hint));
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 /**
  * Exports a question in a JSON-encodable format.
  *
  * @param Question $question
  * @param bool     $withSolution
  * @param bool     $forPaperList
  *
  * @return \stdClass
  *
  * @throws \Exception if the question type export is not implemented
  */
 public function exportQuestion(Question $question, $withSolution = true, $forPaperList = false)
 {
     $handler = $this->handlerCollector->getHandlerForInteractionType($question->getType());
     $rm = $this->rm;
     $data = new \stdClass();
     $data->id = $question->getId();
     $data->type = $handler->getQuestionMimeType();
     $data->title = $question->getTitle();
     $data->description = $question->getDescription();
     $data->invite = $question->getInvite();
     $data->supplementary = $question->getSupplementary();
     $data->specification = $question->getSpecification();
     $data->objects = array_map(function ($object) use($rm) {
         $resourceObjectData = new \stdClass();
         $resourceObjectData->id = (string) $object->getResourceNode()->getId();
         $resourceObjectData->type = $object->getResourceNode()->getResourceType()->getName();
         switch ($object->getResourceNode()->getResourceType()->getName()) {
             case 'text':
                 if ($rm->getResourceFromNode($object->getResourceNode())->getRevisions()[0]) {
                     $resourceObjectData->data = $rm->getResourceFromNode($object->getResourceNode())->getRevisions()[0]->getContent();
                 }
             default:
                 $resourceObjectData->url = $this->router->generate('claro_resource_open', ['resourceType' => $object->getResourceNode()->getResourceType()->getName(), 'node' => $object->getResourceNode()->getId()]);
         }
         return $resourceObjectData;
     }, $question->getObjects()->toArray());
     if (count($question->getHints()) > 0) {
         $data->hints = array_map(function ($hint) use($withSolution) {
             return $this->hintManager->exportHint($hint, $withSolution);
         }, $question->getHints()->toArray());
     }
     if ($withSolution && $question->getFeedback()) {
         $data->feedback = $question->getFeedback();
     }
     $handler->convertInteractionDetails($question, $data, $withSolution, $forPaperList);
     return $data;
 }