예제 #1
0
 /**
  * Get penalty for an interaction and a paper.
  *
  * @param \UJM\ExoBundle\Entity\Question $question
  * @param int                            $paperID
  *
  * @return float
  */
 private function getPenaltyPaper($question, $paperID)
 {
     $em = $this->doctrine->getManager();
     $penalty = 0;
     $hints = $question->getHints();
     foreach ($hints as $hint) {
         $lhp = $em->getRepository('UJMExoBundle:LinkHintPaper')->getLHP($hint->getId(), $paperID);
         if (count($lhp) > 0) {
             $signe = substr($hint->getPenalty(), 0, 1);
             if ($signe === '-') {
                 $penalty += substr($hint->getPenalty(), 1);
             } else {
                 $penalty += $hint->getPenalty();
             }
         }
     }
     return $penalty;
 }
예제 #2
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;
 }