Serializes Item hints.
Forwards the hint serialization to HintSerializer.

@param Item  $question
@param array $options

@return array
517695
private function serializeHints(Item $question, array $options = [])
    {
        return array_map(function (Hint $hint) use ($options) {
            return $this->hintSerializer->serialize($hint, $options);
        }, $question->getHints()->toArray());
    }
77868
public function serialize(BooleanQuestion $question, array $options = [])
    {
        // Serializes choices
        $choices = $this->serializeChoices($question, $options);

        if (in_array(Transfer::SHUFFLE_ANSWERS, $options)) {
            shuffle($choices);
        }

        $serialized = ['choices' => $choices];

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

        return $serialized;
    }
517822
public function getQuestionConfirm(
        $question,
        $default = 'y',
        array $options = array('y', 'n'),
        $required = true
    ) {
        return $this->getQuestion($question, $default, $options, $required);
    }
786038
final protected function askList($question, $items)
    {
        $indent = ($this->indent > 0) ? $this->indent : 0;
        $question = sprintf('%s%s: ', str_repeat(' ', 4 * $indent), $question);

        $question = new ChoiceQuestion($question, $items);
        return $this->getHelper('question')->ask($this->input, $this->output, $question);
    }
1070341
public function serialize(ContentItem $contentItem, array $options = [])
    {
        $serialized = [];

        if (1 === preg_match('#^text\/[^/]+$#', $contentItem->getQuestion()->getMimeType())) {
            $serialized['data'] = $contentItem->getData();
        } else {
            $serialized['url'] = $contentItem->getData();
        }

        return $serialized;
    }
724041
public function serialize(Paper $paper, array $options = [])
    {
        // Adds user score if available and the method options do not already request it
        if (!in_array(Transfer::INCLUDE_USER_SCORE, $options)
            && $this->isScoreAvailable($paper->getExercise(), $paper)) {
            $options[] = Transfer::INCLUDE_USER_SCORE;
        }

        return $this->serializer->serialize($paper, $options);
    }
519891
protected function select(string $question, array $options): int
	{
		return (new Select($this->input, $this->output))->ask($question, $options);
	}
916736
protected function askChoice($question, $options, $default = NULL) {
    return $this->doAsk(new ChoiceQuestion($this->formatQuestion($question),
      $options, $default));
  }
684267
public function useHint(Paper $paper, $questionId, $hintId, $clientIp)
    {
        $question = $paper->getQuestion($questionId);

        if (empty($question)) {
            throw new \LogicException("Question {$questionId} and paper {$paper->getId()} are not related");
        }

        $hint = null;

        foreach ($question['hints'] as $questionHint) {
            if ($hintId === $questionHint['id']) {
                $hint = $questionHint;
                break;
            }
        }

        if (empty($hint)) {
            // Hint is not related to a question of the current attempt
            throw new \LogicException("Hint {$hintId} and paper {$paper->getId()} are not related");
        }

        // Retrieve or create the answer for the question
        $answer = $paper->getAnswer($question['id']);

        if (empty($answer)) {
            $answer = new Answer();
            $answer->setTries(0); // Using an hint is not a try. This will be updated when user will submit his answer
            $answer->setQuestionId($question['id']);
            $answer->setIp($clientIp);

            // Link the new answer to the paper
            $paper->addAnswer($answer);
        }

        $answer->addUsedHint($hintId);

        // Calculate new answer score
        $decodedQuestion = $this->itemSerializer->deserialize($question, new Item());
        $score = $this->itemManager->calculateScore($decodedQuestion, $answer);
        $answer->setScore($score);

        $this->om->persist($answer);
        $this->om->flush();

        return $hint;
    }
701192
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;
    }
453918
public function choose($question, array $options, $default, $error_message)
	{
		/** @var QuestionHelper $helper */
		$helper = $this->_helperSet->get('question');
		$choice_question = new ChoiceQuestion('<question>' . $question . '</question> ', $options, $default);
		$choice_question->setErrorMessage($error_message);

		return $helper->ask($this->_input, $this->_output, $choice_question);
	}
625481
public function correctAnswer(AbstractItem $question, $answer)
    {
        $scoreRule = json_decode($question->getQuestion()->getScoreRule(), true);

        if ('fixed' === $scoreRule['type']) {
            return $this->getCorrectAnswerForFixMode($question, $answer);
        } else {
            // 3 sum submode
            switch ($question->getSumMode()) {
              case GridQuestion::SUM_CELL:
                return $this->getCorrectAnswerForSumCellsMode($question, $answer);
              break;
              case GridQuestion::SUM_COLUMN:
                return $this->getCorrectAnswerForColumnSumMode($question, $answer);
              break;
              case GridQuestion::SUM_ROW:
                return $this->getCorrectAnswerForRowSumMode($question, $answer);
              break;
            }
        }
    }
307810
public function serialize(Paper $paper, array $options = [])
    {
        $serialized = [
            'id' => $paper->getUuid(),
            'number' => $paper->getNumber(),
            'finished' => !$paper->isInterrupted(),
            'user' => $paper->getUser() && !$paper->isAnonymized() ? $this->userSerializer->serialize($paper->getUser(), $options) : null,
            'startDate' => $paper->getStart() ? DateNormalizer::normalize($paper->getStart()) : null,
            'endDate' => $paper->getEnd() ? DateNormalizer::normalize($paper->getEnd()) : null,
            'structure' => json_decode($paper->getStructure(), true),
        ];

        // Adds detail information
        if (!in_array(Transfer::MINIMAL, $options)) {
            $serialized['answers'] = $this->serializeAnswers($paper, $options);
        }

        // Adds user score
        if (!in_array(Transfer::INCLUDE_USER_SCORE, $options)) {
            $serialized['score'] = $paper->getScore();
        }

        return $serialized;
    }
567588
protected function getFormattedSimpleQuestion($question, $default, array $options)
    {
        $question .= '%s';
        $question = sprintf(
            $question,
            ($options ? ' ('.implode('/', $options).')' : '')
        );

        return $question;
    }
403667
private function deserializeResources(Item $question, array $resources = [], array $options = [])
    {
        $resourceEntities = $question->getResources()->toArray();

        foreach ($resources as $resourceData) {
            $existingResource = null;

            // Searches for an existing resource entity.
            foreach ($resourceEntities as $entityIndex => $entityResource) {
                /** @var ItemResource $entityResource */
                if ((string) $entityResource->getId() === $resourceData['id']) {
                    $existingResource = $entityResource;
                    unset($resourceEntities[$entityIndex]);
                    break;
                }
            }

            // Link resource to item
            if (empty($existingResource)) {
                $obj = $this->resourceContentSerializer->deserialize($resourceData, $existingResource, $options);
                if ($obj) {
                    if ($obj instanceof ResourceNode) {
                        $itemResource = new ItemResource();
                        $itemResource->setResourceNode($obj);
                        $itemResource->setQuestion($question);
                        $obj = $itemResource;
                    }
                    $question->addResource($obj);
                }
            }
        }

        // Remaining resources are no longer in the Item
        if (0 < count($resourceEntities)) {
            foreach ($resourceEntities as $resourceToRemove) {
                $question->removeResource($resourceToRemove);
            }
        }
    }
1298344
public function deserializeQuestion(array $itemData, AbstractItem $item = null, array $options = [])
    {
        return $this->getItemSerializer()->deserialize($itemData, $item, $options);
    }
1073625
public function validateAfterSchema($answerData, array $options = [])
    {
        $errors = [];

        /** @var OrderingQuestion $question */
        $question = !empty($options[Validation::QUESTION]) ? $options[Validation::QUESTION] : null;
        if (empty($question)) {
            throw new \LogicException('Answer validation : Cannot perform additional validation without question.');
        }

        $itemIds = array_map(function (OrderingItem $item) {
            return $item->getUuid();
        }, $question->getItems()->toArray());

        foreach ($answerData as $index => $answer) {
            if (!in_array($answer['itemId'], $itemIds)) {
                $errors[] = [
                    'path' => "/[{$index}]",
                    'message' => 'Answer array identifiers must reference question items',
                ];
            }
        }

        return $errors;
    }