plugin/exo/Serializer/Attempt/AnswerSerializer.php
public function serialize(Answer $answer, array $options = [])
    {
        $serialized = [
            'id' => $answer->getUuid(),
            'questionId' => $answer->getQuestionId(),
            'tries' => $answer->getTries(),
            'usedHints' => array_map(function ($hintId) use ($options) {
                return $options['hints'][$hintId];
            }, $answer->getUsedHints()),
        ];

        if (!empty($answer->getData())) {
            $serialized['data'] = json_decode($answer->getData(), true);
        }
        // Adds user score
        if (in_array(Transfer::INCLUDE_USER_SCORE, $options)) {
            $serialized = array_merge($serialized, [
                'score' => $answer->getScore(),
                'feedback' => $answer->getFeedback(),
            ]);
        }

        return $serialized;
    }
public function serialize(Answer $answer, array $options = [])
    {
        $serialized = [
            'id' => $answer->getUuid(),
            'questionId' => $answer->getQuestionId(),
            'tries' => $answer->getTries(),
            'usedHints' => array_map(function ($hintId) use ($options) {
                return $options['hints'][$hintId];
            }, $answer->getUsedHints()),
        ];

        if (!empty($answer->getData())) {
            $serialized['data'] = json_decode($answer->getData(), true);
        }
        // Adds user score
        if (in_array(Transfer::INCLUDE_USER_SCORE, $options)) {
            $serialized = array_merge($serialized, [
                'score' => $answer->getScore(),
                'feedback' => $answer->getFeedback(),
            ]);
        }

        return $serialized;
    }
public function serialize ( Answer $ answer , array $ options = [ ] ) { $ serialized = [ 'id' => $ answer -> getUuid ( ) , 'questionId' => $ answer -> getQuestionId ( ) , 'tries' => $ answer -> getTries ( ) , 'usedHints' => array_map ( function ( $ hintId ) use ( $ options ) { return $ options [ 'hints' ] [ $ hintId ] ; } , $ answer -> getUsedHints ( ) ) , ] ; if ( ! empty ( $ answer -> getData ( ) ) ) { $ serialized [ 'data' ] = json_decode ( $ answer -> getData ( ) , true ) ; } // Adds user score if ( in_array ( Transfer :: INCLUDE_USER_SCORE , $ options ) ) { $ serialized = array_merge ( $ serialized , [ 'score' => $ answer -> getScore ( ) , 'feedback' => $ answer -> getFeedback ( ) , ] ) ; } return $ serialized ; }
Converts an Answer into a JSON-encodable structure.

@param Answer $answer
@param array  $options

@return array
Converts an Answer into a JSON - encodable structure .