示例#1
0
 /**
  * Exports a step in a JSON-encodable format.
  *
  * @param Step $step
  * @param bool $withSolutions
  *
  * @return array
  */
 public function exportStep(Step $step, $withSolutions = true)
 {
     $stepQuestions = $step->getStepQuestions();
     $items = [];
     /** @var StepQuestion $stepQuestion */
     foreach ($stepQuestions as $stepQuestion) {
         $question = $stepQuestion->getQuestion();
         $items[] = $this->questionManager->exportQuestion($question, $withSolutions);
     }
     return ['id' => $step->getId(), 'meta' => ['description' => $step->getText(), 'maxAttempts' => $step->getMaxAttempts(), 'title' => $step->getTitle()], 'items' => $items];
 }
示例#2
0
 /**
  * Export the Questions linked to the Paper.
  *
  * @param Paper $paper
  * @param bool  $withSolution
  * @param bool  $forPaperList
  *
  * @return array
  */
 public function exportPaperQuestions(Paper $paper, $withSolution = false, $forPaperList = false)
 {
     $solutionAvailable = $withSolution || $this->isSolutionAvailable($paper->getExercise(), $paper);
     $export = [];
     $questions = $this->getPaperQuestions($paper);
     foreach ($questions as $question) {
         $exportedQuestion = $this->questionManager->exportQuestion($question, $solutionAvailable, $forPaperList);
         $exportedQuestion->stats = null;
         if ($paper->getExercise()->hasStatistics()) {
             $exportedQuestion->stats = $this->questionManager->generateQuestionStats($question, $paper->getExercise());
         }
         $export[] = $exportedQuestion;
     }
     return $export;
 }