plugin/exo/Serializer/Item/ItemSerializer.php
public function serialize(Item $question, array $options = [])
    {
        // Serialize specific data for the item type
        $serialized = $this->serializeQuestionType($question, $options);

        if (1 === preg_match('#^application\/x\.[^/]+\+json$#', $question->getMimeType())) {
            $canEdit = $this->tokenStorage->getToken() && $this->tokenStorage->getToken()->getUser() instanceof User ?
                $this->container->get('ujm_exo.manager.item')->canEdit($question, $this->tokenStorage->getToken()->getUser()) :
                false;
            // Adds minimal information
            $serialized = array_merge($serialized, [
                'id' => $question->getUuid(),
                'autoId' => $question->getId(),
                'type' => $question->getMimeType(),
                'content' => $question->getContent(),
                'title' => $question->getTitle(),
                'meta' => $this->serializeMetadata($question, $options),
                'score' => json_decode($question->getScoreRule(), true),
                'rights' => ['edit' => $canEdit],
            ]);

            // Adds full definition of the item
            if (!in_array(Transfer::MINIMAL, $options)) {
                $serialized = array_merge($serialized, [
                    'description' => $question->getDescription(),
                    'hints' => $this->serializeHints($question, $options),
                    'objects' => $this->serializeObjects($question),
                    'resources' => $this->serializeResources($question),
                    'tags' => $this->serializeTags($question),
                ]);

                // Adds item feedback
                if (in_array(Transfer::INCLUDE_SOLUTIONS, $options)) {
                    $serialized['feedback'] = $question->getFeedback();
                }
            }
        } else {
            $serialized = array_merge($serialized, [
                'id' => $question->getUuid(),
                'type' => $question->getMimeType(),
                'title' => $question->getTitle(),
                'meta' => $this->serializeMetadata($question, $options),
            ]);

            // Adds full definition of the item
            if (!in_array(Transfer::MINIMAL, $options)) {
                $serialized = array_merge($serialized, [
                    'description' => $question->getDescription(),
                    'tags' => $this->serializeTags($question),
                ]);
            }
        }

        return $serialized;
    }
public function serialize(Item $question, array $options = [])
    {
        // Serialize specific data for the item type
        $serialized = $this->serializeQuestionType($question, $options);

        if (1 === preg_match('#^application\/x\.[^/]+\+json$#', $question->getMimeType())) {
            $canEdit = $this->tokenStorage->getToken() && $this->tokenStorage->getToken()->getUser() instanceof User ?
                $this->container->get('ujm_exo.manager.item')->canEdit($question, $this->tokenStorage->getToken()->getUser()) :
                false;
            // Adds minimal information
            $serialized = array_merge($serialized, [
                'id' => $question->getUuid(),
                'autoId' => $question->getId(),
                'type' => $question->getMimeType(),
                'content' => $question->getContent(),
                'title' => $question->getTitle(),
                'meta' => $this->serializeMetadata($question, $options),
                'score' => json_decode($question->getScoreRule(), true),
                'rights' => ['edit' => $canEdit],
            ]);

            // Adds full definition of the item
            if (!in_array(Transfer::MINIMAL, $options)) {
                $serialized = array_merge($serialized, [
                    'description' => $question->getDescription(),
                    'hints' => $this->serializeHints($question, $options),
                    'objects' => $this->serializeObjects($question),
                    'resources' => $this->serializeResources($question),
                    'tags' => $this->serializeTags($question),
                ]);

                // Adds item feedback
                if (in_array(Transfer::INCLUDE_SOLUTIONS, $options)) {
                    $serialized['feedback'] = $question->getFeedback();
                }
            }
        } else {
            $serialized = array_merge($serialized, [
                'id' => $question->getUuid(),
                'type' => $question->getMimeType(),
                'title' => $question->getTitle(),
                'meta' => $this->serializeMetadata($question, $options),
            ]);

            // Adds full definition of the item
            if (!in_array(Transfer::MINIMAL, $options)) {
                $serialized = array_merge($serialized, [
                    'description' => $question->getDescription(),
                    'tags' => $this->serializeTags($question),
                ]);
            }
        }

        return $serialized;
    }
public function serialize ( Item $ question , array $ options = [ ] ) { // Serialize specific data for the item type $ serialized = $ this -> serializeQuestionType ( $ question , $ options ) ; if ( 1 === preg_match ( '#^application\/x\.[^/]+\+json$#' , $ question -> getMimeType ( ) ) ) { $ canEdit = $ this -> tokenStorage -> getToken ( ) && $ this -> tokenStorage -> getToken ( ) -> getUser ( ) instanceof User ? $ this -> container -> get ( 'ujm_exo.manager.item' ) -> canEdit ( $ question , $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ) : false ; // Adds minimal information $ serialized = array_merge ( $ serialized , [ 'id' => $ question -> getUuid ( ) , 'autoId' => $ question -> getId ( ) , 'type' => $ question -> getMimeType ( ) , 'content' => $ question -> getContent ( ) , 'title' => $ question -> getTitle ( ) , 'meta' => $ this -> serializeMetadata ( $ question , $ options ) , 'score' => json_decode ( $ question -> getScoreRule ( ) , true ) , 'rights' => [ 'edit' => $ canEdit ] , ] ) ; // Adds full definition of the item if ( ! in_array ( Transfer :: MINIMAL , $ options ) ) { $ serialized = array_merge ( $ serialized , [ 'description' => $ question -> getDescription ( ) , 'hints' => $ this -> serializeHints ( $ question , $ options ) , 'objects' => $ this -> serializeObjects ( $ question ) , 'resources' => $ this -> serializeResources ( $ question ) , 'tags' => $ this -> serializeTags ( $ question ) , ] ) ; // Adds item feedback if ( in_array ( Transfer :: INCLUDE_SOLUTIONS , $ options ) ) { $ serialized [ 'feedback' ] = $ question -> getFeedback ( ) ; } } } else { $ serialized = array_merge ( $ serialized , [ 'id' => $ question -> getUuid ( ) , 'type' => $ question -> getMimeType ( ) , 'title' => $ question -> getTitle ( ) , 'meta' => $ this -> serializeMetadata ( $ question , $ options ) , ] ) ; // Adds full definition of the item if ( ! in_array ( Transfer :: MINIMAL , $ options ) ) { $ serialized = array_merge ( $ serialized , [ 'description' => $ question -> getDescription ( ) , 'tags' => $ this -> serializeTags ( $ question ) , ] ) ; } } return $ serialized ; }
Converts a Item into a JSON-encodable structure.

@param Item  $question
@param array $options

@return array
Converts a Item into a JSON - encodable structure .