plugin/exo/Serializer/ExerciseSerializer.php
private function deserializeSteps(Exercise $exercise, array $steps = [], array $options = [])
    {
        $stepEntities = $exercise->getSteps()->toArray();

        foreach ($steps as $index => $stepData) {
            $existingStep = null;

            // Searches for an existing step entity.
            foreach ($stepEntities as $entityIndex => $entityStep) {
                /** @var Step $entityStep */
                if ($entityStep->getUuid() === $stepData['id']) {
                    $existingStep = $entityStep;
                    unset($stepEntities[$entityIndex]);
                    break;
                }
            }

            $step = $this->stepSerializer->deserialize($stepData, $existingStep, $options);
            // Set order in Exercise
            $step->setOrder($index);

            if (empty($existingStep)) {
                // Creation of a new step (we need to link it to the Exercise)
                $exercise->addStep($step);
            }
        }

        // Remaining steps are no longer in the Exercise
        if (0 < count($stepEntities)) {
            /** @var Step $stepToRemove */
            foreach ($stepEntities as $stepToRemove) {
                $exercise->removeStep($stepToRemove);
                $stepQuestions = $stepToRemove->getStepQuestions()->toArray();

                foreach ($stepQuestions as $stepQuestionToRemove) {
                    $stepToRemove->removeStepQuestion($stepQuestionToRemove);
                }
            }
        }
    }
private function deserializeSteps(Exercise $exercise, array $steps = [], array $options = [])
    {
        $stepEntities = $exercise->getSteps()->toArray();

        foreach ($steps as $index => $stepData) {
            $existingStep = null;

            // Searches for an existing step entity.
            foreach ($stepEntities as $entityIndex => $entityStep) {
                /** @var Step $entityStep */
                if ($entityStep->getUuid() === $stepData['id']) {
                    $existingStep = $entityStep;
                    unset($stepEntities[$entityIndex]);
                    break;
                }
            }

            $step = $this->stepSerializer->deserialize($stepData, $existingStep, $options);
            // Set order in Exercise
            $step->setOrder($index);

            if (empty($existingStep)) {
                // Creation of a new step (we need to link it to the Exercise)
                $exercise->addStep($step);
            }
        }

        // Remaining steps are no longer in the Exercise
        if (0 < count($stepEntities)) {
            /** @var Step $stepToRemove */
            foreach ($stepEntities as $stepToRemove) {
                $exercise->removeStep($stepToRemove);
                $stepQuestions = $stepToRemove->getStepQuestions()->toArray();

                foreach ($stepQuestions as $stepQuestionToRemove) {
                    $stepToRemove->removeStepQuestion($stepQuestionToRemove);
                }
            }
        }
    }
private function deserializeSteps ( Exercise $ exercise , array $ steps = [ ] , array $ options = [ ] ) { $ stepEntities = $ exercise -> getSteps ( ) -> toArray ( ) ; foreach ( $ steps as $ index => $ stepData ) { $ existingStep = null ; // Searches for an existing step entity. foreach ( $ stepEntities as $ entityIndex => $ entityStep ) { /** @var Step $entityStep */ if ( $ entityStep -> getUuid ( ) === $ stepData [ 'id' ] ) { $ existingStep = $ entityStep ; unset ( $ stepEntities [ $ entityIndex ] ) ; break ; } } $ step = $ this -> stepSerializer -> deserialize ( $ stepData , $ existingStep , $ options ) ; // Set order in Exercise $ step -> setOrder ( $ index ) ; if ( empty ( $ existingStep ) ) { // Creation of a new step (we need to link it to the Exercise) $ exercise -> addStep ( $ step ) ; } } // Remaining steps are no longer in the Exercise if ( 0 < count ( $ stepEntities ) ) { /** @var Step $stepToRemove */ foreach ( $ stepEntities as $ stepToRemove ) { $ exercise -> removeStep ( $ stepToRemove ) ; $ stepQuestions = $ stepToRemove -> getStepQuestions ( ) -> toArray ( ) ; foreach ( $ stepQuestions as $ stepQuestionToRemove ) { $ stepToRemove -> removeStepQuestion ( $ stepQuestionToRemove ) ; } } } }
Deserializes Exercise steps.
Forwards the step deserialization to StepSerializer.

@param Exercise $exercise
@param array    $steps
@param array    $options
Deserializes Exercise steps . Forwards the step deserialization to StepSerializer .