Deserializes Question solutions.

@param SelectionQuestion $selectionQuestion
@param array             $solutions
@param array             $options
506295
private function deserializeSolutions(SelectionQuestion $selectionQuestion, array $solutions, array $options = [])
    {
        $selectionEntities = $selectionQuestion->getSelections()->toArray();

        foreach ($solutions as $solutionData) {
            $selection = null;

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

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

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

            $selection->setBegin($solutionData['begin']);
            $selection->setEnd($solutionData['end']);
            $selection->setScore($solutionData['score']);
            $selectionQuestion->addSelection($selection);
        }

        // Remaining color are no longer in the Question
        foreach ($selectionEntities as $selectionToRemove) {
            $selectionQuestion->removeSelection($selectionToRemove);
        }
    }
133748
private function deserializeObjects(Item $question, array $objects = [], array $options = [])
    {
        $objectEntities = $question->getObjects()->toArray();
        $question->emptyObjects();

        foreach ($objects as $index => $objectData) {
            $existingObject = null;

            // Searches for an existing object entity.
            foreach ($objectEntities as $entityIndex => $entityObject) {
                /** @var ItemObject $entityObject */
                if ($entityObject->getUuid() === $objectData['id']) {
                    $existingObject = $entityObject;
                    unset($objectEntities[$entityIndex]);
                    break;
                }
            }
            $itemObject = $this->itemObjectSerializer->deserialize($objectData, $existingObject, $options);
            $itemObject->setOrder($index);
            $question->addObject($itemObject);
        }

        // Remaining objects are no longer in the Item
        if (0 < count($objectEntities)) {
            foreach ($objectEntities as $objectToRemove) {
                $this->om->remove($objectToRemove);
            }
        }
    }
875406
public function validateChoices($answer, $choices, $allowedMultiple = false)
    {
        if ($allowedMultiple) {
            return $this->validateMultipleChoice($answer, $choices);
        } else {
            return $this->validateSingleChoice($answer, $choices);
        }
    }
948767
public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null)
    {
        return parent::choice($this->setTextPrompt($question), $choices, $default, $attempts, $multiple);
    }
815884
public function deserialize($data, GridQuestion $gridQuestion = null, array $options = [])
    {
        if (empty($gridQuestion)) {
            $gridQuestion = new GridQuestion();
        }
        if (!empty($data['penalty']) || 0 === $data['penalty']) {
            $gridQuestion->setPenalty($data['penalty']);
        }
        $this->sipe('data', 'setData', $data, $gridQuestion);
        $this->sipe('rows', 'setRows', $data, $gridQuestion);
        $this->sipe('cols', 'setColumns', $data, $gridQuestion);
        $this->sipe('sumMode', 'setSumMode', $data, $gridQuestion);
        $this->sipe('border.width', 'setBorderWidth', $data, $gridQuestion);
        $this->sipe('border.color', 'setBorderColor', $data, $gridQuestion);

        // Deserialize cells and solutions
        $this->deserializeCells($gridQuestion, $data['cells'], $data['solutions'], $options);

        return $gridQuestion;
    }
1091595
public function serialize(FieldFacetChoice $choice, array $options = [])
    {
        $serialized = [
          'id' => $choice->getUuid(),
          'name' => $choice->getName(),
          'label' => $choice->getName(),
          'value' => $choice->getValue(),
          'position' => $choice->getPosition(),
        ];

        if (!empty($choice->getChildren())) {
            $serialized['children'] = [];

            foreach ($choice->getChildren() as $child) {
                $serialized['children'][] = $this->serialize($child);
            }
        }

        return $serialized;
    }
884535
public function serialize(OrderingQuestion $question, array $options = [])
    {
        $serialized = [
            'mode' => $question->getMode(),
            'direction' => $question->getDirection(),
            'penalty' => $question->getPenalty(),
        ];

        // Serializes items
        $items = $this->serializeItems($question, $options);

        // shuffle items only in player
        if (in_array(Transfer::SHUFFLE_ANSWERS, $options)) {
            shuffle($items);
        }
        $serialized['items'] = $items;

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

        return $serialized;
    }
471089
public function choice($question, array $choices, $default = null)
    {
        $helper = $this->getHelper('question');

        $question = new ChoiceQuestion($question, $choices, $default);

        $question->setMultiselect(true);

        return $helper->ask($this->input, $this->getOutputInterface(), $question);
    }
26254
public function choice($question, array $choices, $default = null)
    {
        if ($default) {
            $values = array_flip($choices);
            $default = $values[$default];
        }

        $question = new ChoiceQuestion($question, $choices, $default);
        $question->setMultiselect(true);

        return $this->askQuestion($question);
    }
558420
private function serializeSolutions(ChoiceQuestion $choiceQuestion)
    {
        return array_map(function (Choice $choice) {
            $solutionData = [
                'id' => $choice->getUuid(),
                'score' => $choice->getScore(),
            ];

            if ($choice->getFeedback()) {
                $solutionData['feedback'] = $choice->getFeedback();
            }

            return $solutionData;
        }, $choiceQuestion->getChoices()->toArray());
    }
1077879
public function serialize(ChoiceQuestion $choiceQuestion, array $options = [])
    {
        $serialized = [
            'random' => $choiceQuestion->getShuffle(),
            'multiple' => $choiceQuestion->isMultiple(),
            'numbering' => $choiceQuestion->getNumbering(),
            'direction' => $choiceQuestion->getDirection(),
        ];

        // Serializes choices
        $choices = $this->serializeChoices($choiceQuestion, $options);

        if ($choiceQuestion->getShuffle() && in_array(Transfer::SHUFFLE_ANSWERS, $options)) {
            shuffle($choices);
        }

        $serialized['choices'] = $choices;

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

        return $serialized;
    }
188202
public function deserialize($data, PairQuestion $pairQuestion = null, array $options = [])
    {
        if (empty($pairQuestion)) {
            $pairQuestion = new PairQuestion();
        }

        if (!empty($data['penalty']) || 0 === $data['penalty']) {
            $pairQuestion->setPenalty($data['penalty']);
        }
        $this->sipe('random', 'setShuffle', $data, $pairQuestion);

        $this->deserializeItems($pairQuestion, $data['items'], $options);
        $this->deserializeSolutions($pairQuestion, $data['solutions']);

        return $pairQuestion;
    }
441820
public function ask(string $question, array $options): int
	{
		$options = array_values($options);

		$this->output->writeLn(trim($question));

		$this->output->write($this->buildOptionsList($options));

		$key = (int) $this->input->read() - 1;

		if(isset($options[$key]))
		{
			return $key;
		}

		return $this->ask($question, $options);
	}
702009
private function deserializeProposals(MatchQuestion $setQuestion, array $items)
    {
        $proposalsEntities = $setQuestion->getProposals()->toArray();

        foreach ($items as $index => $itemData) {
            $proposal = null;

            // Search for an existing Proposal entity.
            foreach ($proposalsEntities as $entityIndex => $entityProposal) {
                /* @var Proposal $entityProposal */
                if ($entityProposal->getUuid() === $itemData['id']) {
                    $proposal = $entityProposal;

                    unset($proposalsEntities[$entityIndex]);
                    break;
                }
            }

            $proposal = $proposal ?: new Proposal();
            $proposal->setUuid($itemData['id']);
            $proposal->setOrder($index);

            // Deserialize proposal content
            $proposal = $this->contentSerializer->deserialize($itemData, $proposal);
            $setQuestion->addProposal($proposal);
        }

        // Remaining proposals are no longer in the Question
        foreach ($proposalsEntities as $proposalToRemove) {
            $setQuestion->removeProposal($proposalToRemove);
        }
    }
676193
private function deserializeQuestionType(Item $question, array $data, array $options = [])
    {
        $type = $this->itemDefinitions->getConvertedType($question->getMimeType());
        $definition = $this->itemDefinitions->get($type);

        // Deserialize item type data
        $type = $definition->deserializeQuestion($data, $question->getInteraction(), $options);
        $type->setQuestion($question);
        if (in_array(Transfer::REFRESH_UUID, $options)) {
            $definition->refreshIdentifiers($question->getInteraction());
        }
    }
856897
private function deserializeTags(Item $question, array $tags = [], array $options = [])
    {
        if (in_array(Transfer::PERSIST_TAG, $options)) {
            $user = null;

            if ($this->tokenStorage->getToken() && $this->tokenStorage->getToken()->getUser() instanceof User) {
                $user = $this->tokenStorage->getToken()->getUser();
            }

            $event = new GenericDataEvent([
                'user' => $user,
                'tags' => $tags,
                'data' => [
                    [
                        'class' => Item::class,
                        'id' => $question->getUuid(),
                        'name' => $question->getTitle(),
                    ],
                ],
                'replace' => true,
            ]);

            $this->eventDispatcher->dispatch('claroline_tag_multiple_data', $event);
        }
    }
89600
private function serializeAnswers(Paper $paper, array $options = [])
    {
        // We need to inject the hints available in the structure
        $options['hints'] = [];
        $decoded = json_decode($paper->getStructure(), true);

        foreach ($decoded['steps'] as $step) {
            foreach ($step['items'] as $item) {
                if (1 === preg_match('#^application\/x\.[^/]+\+json$#', $item['type'])) {
                    foreach ($item['hints'] as $hint) {
                        $options['hints'][$hint['id']] = $hint;
                    }
                }
            }
        }

        return array_map(function (Answer $answer) use ($options) {
            return $this->answerSerializer->serialize($answer, $options);
        }, $paper->getAnswers()->toArray());
    }