plugin/exo/Controller/Api/AttemptController.php
public function submitAnswersAction(Paper $paper, User $user = null, Request $request)
    {
        $this->assertHasPermission('OPEN', $paper->getExercise());
        $this->assertHasPaperAccess($paper, $user);

        $errors = [];

        $data = $this->decodeRequestData($request);

        if (empty($data) || !is_array($data)) {
            $errors[] = [
                'path' => '',
                'message' => 'Invalid JSON data',
            ];
        } else {
            try {
                $this->attemptManager->submit($paper, $data, $request->getClientIp());
            } catch (InvalidDataException $e) {
                $errors = $e->getErrors();
            }
        }

        if (!empty($errors)) {
            return new JsonResponse($errors, 422);
        } else {
            return new JsonResponse(null, 204);
        }
    }
public function submitAnswersAction(Paper $paper, User $user = null, Request $request)
    {
        $this->assertHasPermission('OPEN', $paper->getExercise());
        $this->assertHasPaperAccess($paper, $user);

        $errors = [];

        $data = $this->decodeRequestData($request);

        if (empty($data) || !is_array($data)) {
            $errors[] = [
                'path' => '',
                'message' => 'Invalid JSON data',
            ];
        } else {
            try {
                $this->attemptManager->submit($paper, $data, $request->getClientIp());
            } catch (InvalidDataException $e) {
                $errors = $e->getErrors();
            }
        }

        if (!empty($errors)) {
            return new JsonResponse($errors, 422);
        } else {
            return new JsonResponse(null, 204);
        }
    }
public function submitAnswersAction ( Paper $ paper , User $ user = null , Request $ request ) { $ this -> assertHasPermission ( 'OPEN' , $ paper -> getExercise ( ) ) ; $ this -> assertHasPaperAccess ( $ paper , $ user ) ; $ errors = [ ] ; $ data = $ this -> decodeRequestData ( $ request ) ; if ( empty ( $ data ) || ! is_array ( $ data ) ) { $ errors [ ] = [ 'path' => '' , 'message' => 'Invalid JSON data' , ] ; } else { try { $ this -> attemptManager -> submit ( $ paper , $ data , $ request -> getClientIp ( ) ) ; } catch ( InvalidDataException $ e ) { $ errors = $ e -> getErrors ( ) ; } } if ( ! empty ( $ errors ) ) { return new JsonResponse ( $ errors , 422 ) ; } else { return new JsonResponse ( null , 204 ) ; } }
Submits answers to an Exercise.

@EXT\Route("/{id}", name="exercise_attempt_submit")
@EXT\Method("PUT")
@EXT\ParamConverter("paper", class="UJMExoBundle:Attempt\Paper", options={"mapping": {"id": "uuid"}})
@EXT\ParamConverter("user", converter="current_user", options={"allowAnonymous"=true})

@param User    $user
@param Paper   $paper
@param Request $request

@return JsonResponse
Submits answers to an Exercise .