Generate the display of the marks for this question out of the available marks.
@param question_attempt $qa the question attempt to display.
@param question_display_options $options controls what should and should not be displayed.
@return HTML fragment.
974015
public function standard_mark_out_of_max(question_attempt $qa, question_display_options $options) {
        $a = new stdClass();
        $a->mark = $qa->format_mark($options->markdp);
        $a->max = $qa->format_max_mark($options->markdp);
        return get_string('markoutofmax', 'question', $a);
    }
989429
public function validateAfterSchema($answerData, array $options = [])
    {
        /** @var GridQuestion $question */
        $question = !empty($options[Validation::QUESTION]) ? $options[Validation::QUESTION] : null;
        if (empty($question)) {
            throw new \LogicException('Answer validation : Cannot perform additional validation without question.');
        }

        $cellIds = array_map(function (Cell $cell) {
            return $cell->getUuid();
        }, $question->getCells()->toArray());

        foreach ($answerData as $answer) {
            if (empty($answer['cellId'])) {
                return ['Answer `cellId` cannot be empty'];
            }

            if (!in_array($answer['cellId'], $cellIds)) {
                return ['Answer array identifiers must reference question cells'];
            }
        }

        return [];
    }
457936
public function input($question, $default = '', $options = [])
    {
        if (empty($default)) {
            $this->write($question . ' ');
        } elseif (empty($options)) {
            $this->write($question . ' [' . $default . '] ');
        } else {
            $available_options = [];
            foreach (strtolower($options) as $option) {
                if ($option === strtolower($default)) {
                    $option = strtoupper($option);
                }
                $available_options[] = $option;
            }
            $available_opts = rtrim(implode($available_options, '/'), '/');
            $this->write($question . ' [' . $available_opts . '] ');
        }
        $answer = rtrim(fgets(STDIN), PHP_EOL);
        if (empty($answer)) {
            return $default;
        }
        if (count($options) > 0) {
            if (!in_array(strtolower($answer), array_map('strtolower', $options))) {
                return $this->input($question, $default, $options);
            }
            return $answer;
        }
        return $answer;
    }
588827
public function options($name, $question, array $options, $required = false)
    {
        output()->write(PHP_EOL);

        $choices = [];
        $i = 1;
        foreach ($options as $value => $label) {
            $choices[ $i ] = $value;
            output()->write(
                (new Format())
                    ->setString('(' . $i . ') ' . language()->getLine($label))
                    ->setNewLinesAfter(1)
            );
            $i++;
        }

        //output()->write( PHP_EOL );

        if (is_string($question)) {
            output()->write(
                (new Format())
                    ->setString(language()->getLine($question) . ':')
                    ->setSpace(1)
            );
        } elseif ($question instanceof Format or $question instanceof Text) {
            output()->write($question);
        }

        $requiredText = (new Format())
            ->setColor((new Color())->setBackground(Color::RED))
            ->setString(' ' . language()->getLine('REQUIRED') . ' ')
            ->setIndent(1)
            ->__toString();

        $invalidText = (new Format())
            ->setColor((new Color())->setBackground(Color::RED))
            ->setString(' ' . language()->getLine('INVALID') . ' ')
            ->setIndent(1)
            ->__toString();

        $question = str_replace([$requiredText, $invalidText], '', $question);

        $standardInput = input()->standard();

        if ($required === true and empty($standardInput)) {
            $this->options($name, $question . $requiredText, $options, $required);

            return;
        } elseif ( ! array_key_exists($standardInput, $choices)) {
            $this->options($name, $question . $invalidText, $options, $required);

            return;
        }

        $_POST[ $name ] = $choices[ $standardInput ];
    }
53778
protected function num_parts_correct(question_attempt $qa) {
        $a = new stdClass();
        list($a->num, $a->outof) = $qa->get_question()->get_num_parts_right(
                $qa->get_last_qt_data());
        if (is_null($a->outof)) {
            return '';
        } else {
            return get_string('yougotnright', 'question', $a);
        }
    }
168518
public function review_question_not_allowed(quiz_attempt $attemptobj, $message) {
        $output = '';
        $output .= $this->header();
        $output .= $this->heading(format_string($attemptobj->get_quiz_name(), true,
                                  array("context" => $attemptobj->get_quizobj()->get_context())));
        $output .= $this->notification($message);
        $output .= $this->close_window_button();
        $output .= $this->footer();
        return $output;
    }
1353047
public static function ask(string $question, array $options) : string
    {
        self::out($question);
        fscanf(STDIN, '%s\n', $answer);
        if ($answer === null) {
            $answer = $options[true];
        }
        if (!in_array($answer, $options)) {
            return self::ask($question, $options);
        }
        return $answer;
    }
570999
public function load_questions() {
        if ($this->choose > count($this->availablequestions)) {
            throw new coding_exception('notenoughtshortanswerquestions');
        }

        $questionids = draw_rand_array($this->availablequestions, $this->choose);
        $questions = array();
        foreach ($questionids as $questionid) {
            $questions[] = question_bank::load_question($questionid);
        }
        return $questions;
    }
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);
    }
891986
protected function after_execute_question() {
        global $DB;

        $essayswithoutoptions = $DB->get_records_sql("
                    SELECT q.*
                      FROM {question} q
                      JOIN {backup_ids_temp} bi ON bi.newitemid = q.id
                 LEFT JOIN {qtype_essay_options} qeo ON qeo.questionid = q.id
                     WHERE q.qtype = ?
                       AND qeo.id IS NULL
                       AND bi.backupid = ?
                       AND bi.itemname = ?
                ", array('essay', $this->get_restoreid(), 'question_created'));

        foreach ($essayswithoutoptions as $q) {
            $defaultoptions = new stdClass();
            $defaultoptions->questionid = $q->id;
            $defaultoptions->responseformat = 'editor';
            $defaultoptions->responserequired = 1;
            $defaultoptions->responsefieldlines = 15;
            $defaultoptions->attachments = 0;
            $defaultoptions->attachmentsrequired = 0;
            $defaultoptions->graderinfo = '';
            $defaultoptions->graderinfoformat = FORMAT_HTML;
            $defaultoptions->responsetemplate = '';
            $defaultoptions->responsetemplateformat = FORMAT_HTML;
            $DB->insert_record('qtype_essay_options', $defaultoptions);
        }
    }
39843
public function files_read_only(question_attempt $qa, question_display_options $options) {
        $files = $qa->get_last_qt_files('attachments', $options->context->id);
        $output = array();

        foreach ($files as $file) {
            $output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file),
                    $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),
                    'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())));
        }
        return implode($output);
    }
120979
public function make_question($questiondata) {
        $question = $this->make_question_instance($questiondata);
        $this->initialise_question_instance($question, $questiondata);
        return $question;
    }
744648
protected function initialise_combined_feedback(question_definition $question,
            $questiondata, $withparts = false) {
        $question->correctfeedback = $questiondata->options->correctfeedback;
        $question->correctfeedbackformat = $questiondata->options->correctfeedbackformat;
        $question->partiallycorrectfeedback = $questiondata->options->partiallycorrectfeedback;
        $question->partiallycorrectfeedbackformat =
                $questiondata->options->partiallycorrectfeedbackformat;
        $question->incorrectfeedback = $questiondata->options->incorrectfeedback;
        $question->incorrectfeedbackformat = $questiondata->options->incorrectfeedbackformat;
        if ($withparts) {
            $question->shownumcorrect = $questiondata->options->shownumcorrect;
        }
    }
915022
public function format_answer($answer, $context, $answerformat, $options = []) {

        if (is_object($options)) {
            $options = (array) $options;
        }

        if (empty($options['context'])) {
            $options['context'] = $context;
        }

        if (empty($options['para'])) {
            $options['para'] = true;
        }

        return format_text($answer, $answerformat, $options);
    }
795347
protected function initialise_question_instance(question_definition $question, $questiondata) {
        $question->id = $questiondata->id;
        $question->category = $questiondata->category;
        $question->contextid = $questiondata->contextid;
        $question->parent = $questiondata->parent;
        $question->qtype = $this;
        $question->name = $questiondata->name;
        $question->questiontext = $questiondata->questiontext;
        $question->questiontextformat = $questiondata->questiontextformat;
        $question->generalfeedback = $questiondata->generalfeedback;
        $question->generalfeedbackformat = $questiondata->generalfeedbackformat;
        $question->defaultmark = $questiondata->defaultmark + 0;
        $question->length = $questiondata->length;
        $question->penalty = $questiondata->penalty;
        $question->stamp = $questiondata->stamp;
        $question->version = $questiondata->version;
        $question->hidden = $questiondata->hidden;
        $question->idnumber = $questiondata->idnumber;
        $question->timecreated = $questiondata->timecreated;
        $question->timemodified = $questiondata->timemodified;
        $question->createdby = $questiondata->createdby;
        $question->modifiedby = $questiondata->modifiedby;

        // Fill extra question fields values.
        $extraquestionfields = $this->extra_question_fields();
        if (is_array($extraquestionfields)) {
            // Omit table name.
            array_shift($extraquestionfields);
            foreach ($extraquestionfields as $field) {
                $question->$field = $questiondata->options->$field;
            }
        }

        $this->initialise_question_hints($question, $questiondata);
    }
1116033
def question_mark(self, request, obj):
        """"""
        obj.question = obj.question + '?'
        obj.save()
653588
public function validateAfterSchema($answerData, array $options = [])
    {
        $question = !empty($options[Validation::QUESTION]) ? $options[Validation::QUESTION] : null;

        if (empty($question)) {
            throw new \LogicException('Answer validation : Cannot perform additional validation without question.');
        }

        $image = $question->getImage();
        $errors = [];

        foreach ($answerData as $index => $coords) {
            if ($coords['x'] > $image->getWidth()) {
                $errors[] = [
                    'path' => "/[{$index}].x",
                    'message' => 'Position exceeds image width',
                ];
            }
            if ($coords['y'] > $image->getHeight()) {
                $errors[] = [
                    'path' => "/[{$index}].y",
                    'message' => 'Position exceeds image height',
                ];
            }
        }

        return $errors;
    }