plugin/exo/Serializer/Item/Type/SelectionQuestionSerializer.php
private function deserializeSelections(SelectionQuestion $selectionQuestion, array $selections, array $solutions, array $options = [])
    {
        $selectionEntities = $selectionQuestion->getSelections()->toArray();

        foreach ($selections as $selectionData) {
            $selection = null;

            foreach ($selectionEntities as $entityIndex => $selectionEntity) {
                /** @var Selection $selectionEntity */
                if ($selectionEntity->getUuid() === $selectionData['id']) {
                    $selection = $selectionEntity;
                    unset($selectionEntities[$entityIndex]);
                    break;
                }
            }

            $selection = $selection ?: new Selection();
            $selection->setUuid($selectionData['id']);

            $solutionsD = array_values(array_filter($solutions, function ($solution) use ($selectionData) {
                return $solution['selectionId'] === $selectionData['id'];
            }));

            if (isset($solutionsD[0]) && isset($solutionsD[0]['feedback'])) {
                $selection->setFeedback($solutionsD[0]['feedback']);
            }

            $selection->setBegin($selectionData['begin']);
            $selection->setEnd($selectionData['end']);

            foreach ($solutions as $solutionData) {
                if ($solutionData['selectionId'] === $selectionData['id']) {
                    switch ($options['selection_mode']) {
                      case SelectionQuestion::MODE_SELECT:
                        $selection->setScore($solutionData['score']);
                        break;
                      case SelectionQuestion::MODE_HIGHLIGHT:
                        $selection->setScore(0);
                        $this->deserializeColorSelection($selection, $solutionData['answers'], $selectionQuestion->getColors()->toArray());
                        break;
                      }
                }
            }

            $selectionQuestion->addSelection($selection);
        }

        // Remaining color are no longer in the Question
        foreach ($selectionEntities as $selectionToRemove) {
            $selectionQuestion->removeSelection($selectionToRemove);
        }
    }
private function deserializeSelections(SelectionQuestion $selectionQuestion, array $selections, array $solutions, array $options = [])
    {
        $selectionEntities = $selectionQuestion->getSelections()->toArray();

        foreach ($selections as $selectionData) {
            $selection = null;

            foreach ($selectionEntities as $entityIndex => $selectionEntity) {
                /** @var Selection $selectionEntity */
                if ($selectionEntity->getUuid() === $selectionData['id']) {
                    $selection = $selectionEntity;
                    unset($selectionEntities[$entityIndex]);
                    break;
                }
            }

            $selection = $selection ?: new Selection();
            $selection->setUuid($selectionData['id']);

            $solutionsD = array_values(array_filter($solutions, function ($solution) use ($selectionData) {
                return $solution['selectionId'] === $selectionData['id'];
            }));

            if (isset($solutionsD[0]) && isset($solutionsD[0]['feedback'])) {
                $selection->setFeedback($solutionsD[0]['feedback']);
            }

            $selection->setBegin($selectionData['begin']);
            $selection->setEnd($selectionData['end']);

            foreach ($solutions as $solutionData) {
                if ($solutionData['selectionId'] === $selectionData['id']) {
                    switch ($options['selection_mode']) {
                      case SelectionQuestion::MODE_SELECT:
                        $selection->setScore($solutionData['score']);
                        break;
                      case SelectionQuestion::MODE_HIGHLIGHT:
                        $selection->setScore(0);
                        $this->deserializeColorSelection($selection, $solutionData['answers'], $selectionQuestion->getColors()->toArray());
                        break;
                      }
                }
            }

            $selectionQuestion->addSelection($selection);
        }

        // Remaining color are no longer in the Question
        foreach ($selectionEntities as $selectionToRemove) {
            $selectionQuestion->removeSelection($selectionToRemove);
        }
    }
private function deserializeSelections ( SelectionQuestion $ selectionQuestion , array $ selections , array $ solutions , array $ options = [ ] ) { $ selectionEntities = $ selectionQuestion -> getSelections ( ) -> toArray ( ) ; foreach ( $ selections as $ selectionData ) { $ selection = null ; foreach ( $ selectionEntities as $ entityIndex => $ selectionEntity ) { /** @var Selection $selectionEntity */ if ( $ selectionEntity -> getUuid ( ) === $ selectionData [ 'id' ] ) { $ selection = $ selectionEntity ; unset ( $ selectionEntities [ $ entityIndex ] ) ; break ; } } $ selection = $ selection ? : new Selection ( ) ; $ selection -> setUuid ( $ selectionData [ 'id' ] ) ; $ solutionsD = array_values ( array_filter ( $ solutions , function ( $ solution ) use ( $ selectionData ) { return $ solution [ 'selectionId' ] === $ selectionData [ 'id' ] ; } ) ) ; if ( isset ( $ solutionsD [ 0 ] ) && isset ( $ solutionsD [ 0 ] [ 'feedback' ] ) ) { $ selection -> setFeedback ( $ solutionsD [ 0 ] [ 'feedback' ] ) ; } $ selection -> setBegin ( $ selectionData [ 'begin' ] ) ; $ selection -> setEnd ( $ selectionData [ 'end' ] ) ; foreach ( $ solutions as $ solutionData ) { if ( $ solutionData [ 'selectionId' ] === $ selectionData [ 'id' ] ) { switch ( $ options [ 'selection_mode' ] ) { case SelectionQuestion :: MODE_SELECT : $ selection -> setScore ( $ solutionData [ 'score' ] ) ; break ; case SelectionQuestion :: MODE_HIGHLIGHT : $ selection -> setScore ( 0 ) ; $ this -> deserializeColorSelection ( $ selection , $ solutionData [ 'answers' ] , $ selectionQuestion -> getColors ( ) -> toArray ( ) ) ; break ; } } } $ selectionQuestion -> addSelection ( $ selection ) ; } // Remaining color are no longer in the Question foreach ( $ selectionEntities as $ selectionToRemove ) { $ selectionQuestion -> removeSelection ( $ selectionToRemove ) ; } }
Deserializes Question selection.

@param SelectionQuestion $selectionQuestion
@param array             $selections
@param array             $solutions
@param array             $options
Deserializes Question selection .