/**
  * Export exercise with steps with questions.
  *
  * @param Exercise $exercise
  * @param bool     $withSolutions
  *
  * @return array
  */
 public function exportSteps(Exercise $exercise, $withSolutions = true)
 {
     $steps = $exercise->getSteps();
     $data = [];
     foreach ($steps as $step) {
         $data[] = $this->stepManager->exportStep($step, $withSolutions);
     }
     return $data;
 }
 /**
  * Reorder the Questions of a Step.
  *
  * @EXT\Route(
  *     "/steps/{id}/questions/reorder",
  *     name="exercise_question_reorder",
  *     requirements={"id"="\d+"},
  *     options={"expose"=true}
  * )
  * @EXT\Method("PUT")
  * @EXT\ParamConverter("exercise", class="UJMExoBundle:Exercise", options={"mapping": {"exerciseId": "id"}})
  * @param Exercise $exercise
  * @param Step     $step
  * @param Request  $request
  *
  * @return JsonResponse
  */
 public function reorderQuestionsAction(Exercise $exercise, Step $step, Request $request)
 {
     $this->assertHasPermission('ADMINISTRATE', $exercise);
     $dataRaw = $request->getContent();
     if (empty($dataRaw)) {
         return new JsonResponse(['message' => 'No data sent.'], 422);
     }
     $order = json_decode($dataRaw);
     if (!is_array($order)) {
         return new JsonResponse(['message' => 'Invalid data sent. Expected an array of Question IDs.'], 422);
     }
     $errors = $this->stepManager->reorderQuestions($step, $order);
     if (count($errors) !== 0) {
         return new JsonResponse($errors, 422);
     }
     return new JsonResponse(null, 204);
 }