public function serialize(MatchQuestion $setQuestion, array $options = [])
    {
        $serialized = [
            'random' => $setQuestion->getShuffle(),
            'penalty' => $setQuestion->getPenalty(),
        ];

        $items = array_map(function (Proposal $proposal) use ($options) {
            $setData = $this->contentSerializer->serialize($proposal, $options);
            $setData['id'] = $proposal->getUuid();

            return $setData;
        }, $setQuestion->getProposals()->toArray());

        $sets = array_map(function (Label $label) use ($options) {
            $itemData = $this->contentSerializer->serialize($label, $options);
            $itemData['id'] = $label->getUuid();

            return $itemData;
        }, $setQuestion->getLabels()->toArray());

        if ($setQuestion->getShuffle() && in_array(Transfer::SHUFFLE_ANSWERS, $options)) {
            shuffle($sets);
            shuffle($items);
        }

        $serialized['sets'] = $sets;
        $serialized['items'] = $items;

        if (in_array(Transfer::INCLUDE_SOLUTIONS, $options)) {
            $serialized['solutions'] = $this->serializeSolutions($setQuestion);
        }

        return $serialized;
    }
public function serialize(MatchQuestion $setQuestion, array $options = [])
    {
        $serialized = [
            'random' => $setQuestion->getShuffle(),
            'penalty' => $setQuestion->getPenalty(),
        ];

        $items = array_map(function (Proposal $proposal) use ($options) {
            $setData = $this->contentSerializer->serialize($proposal, $options);
            $setData['id'] = $proposal->getUuid();

            return $setData;
        }, $setQuestion->getProposals()->toArray());

        $sets = array_map(function (Label $label) use ($options) {
            $itemData = $this->contentSerializer->serialize($label, $options);
            $itemData['id'] = $label->getUuid();

            return $itemData;
        }, $setQuestion->getLabels()->toArray());

        if ($setQuestion->getShuffle() && in_array(Transfer::SHUFFLE_ANSWERS, $options)) {
            shuffle($sets);
            shuffle($items);
        }

        $serialized['sets'] = $sets;
        $serialized['items'] = $items;

        if (in_array(Transfer::INCLUDE_SOLUTIONS, $options)) {
            $serialized['solutions'] = $this->serializeSolutions($setQuestion);
        }

        return $serialized;
    }
public function serialize ( MatchQuestion $ setQuestion , array $ options = [ ] ) { $ serialized = [ 'random' => $ setQuestion -> getShuffle ( ) , 'penalty' => $ setQuestion -> getPenalty ( ) , ] ; $ items = array_map ( function ( Proposal $ proposal ) use ( $ options ) { $ setData = $ this -> contentSerializer -> serialize ( $ proposal , $ options ) ; $ setData [ 'id' ] = $ proposal -> getUuid ( ) ; return $ setData ; } , $ setQuestion -> getProposals ( ) -> toArray ( ) ) ; $ sets = array_map ( function ( Label $ label ) use ( $ options ) { $ itemData = $ this -> contentSerializer -> serialize ( $ label , $ options ) ; $ itemData [ 'id' ] = $ label -> getUuid ( ) ; return $ itemData ; } , $ setQuestion -> getLabels ( ) -> toArray ( ) ) ; if ( $ setQuestion -> getShuffle ( ) && in_array ( Transfer :: SHUFFLE_ANSWERS , $ options ) ) { shuffle ( $ sets ) ; shuffle ( $ items ) ; } $ serialized [ 'sets' ] = $ sets ; $ serialized [ 'items' ] = $ items ; if ( in_array ( Transfer :: INCLUDE_SOLUTIONS , $ options ) ) { $ serialized [ 'solutions' ] = $ this -> serializeSolutions ( $ setQuestion ) ; } return $ serialized ; }
Converts a Set question into a JSON-encodable structure.

@param MatchQuestion $setQuestion
@param array         $options

@return array
Converts a Set question into a JSON - encodable structure .