Asks a question that must provide an answer from a specfic set of answers

@param  string $question The question to ask.
@param  array  $answers  A set of possible answers.
@return string           The provided answer.
184290
protected function askWithForcedAnswers($question, $answers)
	{
		// Ask the question
		do $answer = $this->ask($question.' ('.implode('|', $answers).')');

		// Continue to ask the question until we get a valid answer
		while (!in_array($answer, $answers));

		// Return the answer
		return $answer;
	}
764296
public function choice($question, $choices = array(), $allowedMultiple = false)
    {
        $this->output->writeln($question);

        $this->output->writeln(join(',', $choices));

        $answer = $this->input->getInput();

        $valid = $this->validateChoices($answer, $choices, $allowedMultiple);

        if ($valid !== false) {
            return $valid;
        }

        $this->output->writeln($this->wrongChoiceErrorMessage);

        return false;
    }
186903
public function correctAnswer(AbstractItem $question, $answer)
    {
        $corrected = new CorrectedAnswer();
        foreach ($question->getKeywords() as $keyword) {
            if ($this->containKeyword($answer, $keyword)) {
                if (0 < $keyword->getScore()) {
                    $corrected->addExpected($keyword);
                } else {
                    $corrected->addUnexpected($keyword);
                }
            } elseif (0 < $keyword->getScore()) {
                $corrected->addMissing($keyword);
            }
        }

        return $corrected;
    }
463268
public function askWithCompletion($question, array $choices, $default = null)
    {
        $question = new Question($question, $default);

        $question->setAutocompleterValues($choices);

        return $this->output->askQuestion($question);
    }
831606
protected function get_array_of_groups($question, $state) {
        $answers = $this->get_array_of_choices($question);
        $arr = array();
        for ($group = 1; $group < count($answers); $group++) {
            $players = $this->get_group_of_players($question, $state, $answers, $group);
            if ($players) {
                $arr[$group] = $players;
            }
        }
        return $arr;
    }
532221
protected function validate_question_data($question) {
        $this->validate_text($question->questiontext); // Yes, really no ['text'].

        if (isset($question->generalfeedback['text'])) {
            $this->validate_text($question->generalfeedback['text']);
        } else if (isset($question->generalfeedback)) {
            $this->validate_text($question->generalfeedback); // Because question import is weird.
        }

        foreach ($question->answer as $key => $answer) {
            $this->validate_answer($answer);
            $this->validate_text($question->feedback[$key]['text']);
        }
    }
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;
            }
        }
    }
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);
	}
91532
public function ask($question, $weight = "y") {
		$question = self::format($question);
		$y = $weight == 'y' ? 'Y' : 'y';
		$n = $weight == 'n' ? 'N' : 'n';
		$answer = $this->prompt("$question [$y/$n]");
		$line = trim(strtolower($answer));
		
		if(empty($line)) {
			$line = $weight;
		}

		return in_array($line, array('y','yes'));
	}
334465
public function addAnswer(Answer $answer)
    {
        if (!$this->answers->contains($answer)) {
            $this->answers->add($answer);
            $answer->setPaper($this);
        }
    }
257900
protected function askYn( $question ) {
		$answer = $this->ask( $question .' [Y/n] ');
		while ( ! in_array( strtolower( $answer ), [ 'y', 'n', 'yes', 'no' ] ) ) {
			$answer = $this->ask('Please choose either yes or no. ');
		}
		return in_array( strtolower( $answer ), [ 'y', 'yes' ] );
	}
1341581
public static function parse($answer)
    {
        if ( ! is_array($answer)) {
            return;
        }

        foreach ($answer as $key => $value) {
            $parsed = is_array($value) ? self::parse($value) : self::process($value);

            if ( ! empty($parsed)) {
                $answer[$key] = $parsed;
            } else {
                unset($answer[$key]);
            }
        }

        return $answer;
    }
220693
private function getCorrectAnswerForColumnSumMode(AbstractItem $question, $answer)
    {
        $corrected = new CorrectedAnswer();

        if (!is_null($answer)) {
            // correct answers per row
            for ($i = 0; $i < $question->getColumns(); ++$i) {
                // get cells where there is at least 1 expected answers for the current column (none possible)
                $colCellsUuids = [];

                foreach ($question->getCells() as $cell) {
                    if ($cell->getCoordsX() === $i && $cell->isInput()) {
                        $colCellsUuids[] = $cell->getUuid();
                    }
                }

                // if any answer is needed in this column
                if (!empty($colCellsUuids)) {
                    // score will be applied only if all expected answers are there and valid
                    $all = true;

                    foreach ($colCellsUuids as $expectedCellUuid) {
                        // if $expectedCellUuid found in answers
                        $givenAnwser = array_filter($answer, function ($given) use ($expectedCellUuid) {
                            return $given['cellId'] === $expectedCellUuid;
                        });
                        if (empty($givenAnwser)) {
                            $all = false;
                            break;
                        } else {
                            $cell = $question->getCell($expectedCellUuid);
                            $currentAnswer = reset($givenAnwser);
                            $choice = $cell->getChoice($currentAnswer['text']);
                            // wrong or empty anwser -> score will not be applied
                            if (empty($choice) || (!empty($choice) && !$choice->isExpected())) {
                                $all = false;
                                break;
                            }
                        }
                    }

                    if ($all) {
                        $scoreToApply = $choice->getScore();
                        $corrected->addExpected(new GenericScore($scoreToApply));
                    } else {
                        $corrected->addPenalty(new GenericPenalty($question->getPenalty()));
                    }
                }
            }
        } else {
            $cells = $question->getCells();

            foreach ($cells as $cell) {
                if ($cell->isInput()) {
                    $corrected->addMissing($this->findCellExpectedAnswer($cell));
                }
            }
        }

        return $corrected;
    }
161331
public function get_question_options($question) {
        global $DB, $OUTPUT;
        // Get additional information from database
        // and attach it to the question object.
        if (!$question->options = $DB->get_record('question_truefalse',
                array('question' => $question->id))) {
            echo $OUTPUT->notification('Error: Missing question options!');
            return false;
        }
        // Load the answers.
        if (!$question->options->answers = $DB->get_records('question_answers',
                array('question' =>  $question->id), 'id ASC')) {
            echo $OUTPUT->notification('Error: Missing question answers for truefalse question ' .
                    $question->id . '!');
            return false;
        }

        return true;
    }
766008
public function evaluateQuestion(array $question, PhpStringParser $parser, GeneratorDataObject $generator)
    {
        $iterator       = $this->iteratorValidator->retrieveValidIteration($question, $generator, $parser);
        $iteratorParser = clone $parser;

        foreach ($iterator as $iteration) {
            $iteratorParser->addVariable('iteration', $iteration);

            $origine            = $iteratorParser->parse($question['iteration']['retrieveBy']);
            $responseCollection = new PredefinedResponseCollection();

            foreach ($question['iteration']['response']['predefined'] as $predefinedResponse) {
                $responseCollection->append(
                    new PredefinedResponse(
                        $predefinedResponse['response'],
                        $iteratorParser->parse($predefinedResponse['text']),
                        $predefinedResponse['response']
                    )
                );
            }

            $questionWithPredefinedResponse = new QuestionWithPredefinedResponse(
                $iteratorParser->parse($question['iteration']['text']),
                'set_predefined_' . ucfirst($question['dtoAttribute']) . $origine,
                $responseCollection
            );

            $questionWithPredefinedResponse->setDefaultResponse(
                (isset($question['iteration']['response']['default']) === true) ?
                    $iteratorParser->parse($question['iteration']['response']['default']) : null
            )->setRequired($question['required'])
             ->setResponseType(new QuestionResponseTypeEnum($question['iteration']['response']['type']));

            $response = $this->context->askCollection($questionWithPredefinedResponse);

            $questionName = $question['setter'];
            if ($response !== null) {
                $generator->getDto()->$questionName($origine, $response);
            }
        }

        return $generator;
    }
561807
protected function make_answer($answer) {
        return new question_answer($answer->id, $answer->answer,
                    $answer->fraction, $answer->feedback, $answer->feedbackformat);
    }
930523
public function ask($question, $default = null)
    {
        $question = new Question("<question>$question</question> ", $default);

        return $this->helper('question')->ask($this->input, $this->output, $question);
    }