Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Prohor's avatar

syntax error, unexpected token "public", expecting end of file in your code on line 105

0 likes
5 replies
Prohor's avatar

''' <?php defined('MOODLE_INTERNAL') || die;

require_once($CFG->libdir . '/questionlib.php');

class qtype_random_quadratic extends question_type { public function name() { return 'random_quadratic'; }

public function save_question_options($question) {
    $question->options = json_encode($question->options);
    return true;
}

public function get_question_options(&$question) {
    $question->options = json_decode($question->options, true);
    return true;
}

public function extra_question_fields() {
    return array('a', 'b', 'c');
}

public function response_summary($question, $state, $length = 80) {
    return '';
}

public function is_usable_by_random() {
    return true;
}

public function can_regrade_response($question) {
    return false;
}

public function get_expected_data($question, $nameprefix) {
    return array();
}

public function get_actual_data($question, $nameprefix) {
    return array();
}

public function save_session_and_responses(&$question, &$state) {
    return true;
}

public function restore_session_and_responses(&$question, &$state) {
    return true;
}

public function get_question_edit_options_form_definition($question) {
    $mform = $this->create_question_edit_options_form($question);
    return $mform;
}

public function save_question_edit_options($question) {
    return $this->save_question_options($question);
}

public function get_question_options_form_definition($form, $question) {
    $this->add_per_question_fields($form->addElement('text', 'a', get_string('a', 'qtype_random_quadratic')));
    $this->add_per_question_fields($form->addElement('text', 'b', get_string('b', 'qtype_random_quadratic')));
    $this->add_per_question_fields($form->addElement('text', 'c', get_string('c', 'qtype_random_quadratic')));

    $form->addRule('a', null, 'required', null, 'client');
    $form->addRule('b', null, 'required', null, 'client');
    $form->addRule('c', null, 'required', null, 'client');
}

public function get_default_qt_options() {
    return array();
}

public function is_compatible($question) {
    return true;
}

public function get_question_preview($question, $state, $cmoptions, $options) {
    return '';
}

public function get_question_options_for_export($question) {
    return $question->options;
}

public function get_question_options_from_import($data) {
    return $data;
}

public function get_used_question_ids($questionids, $quiz) {
    return array();
}

public function has_additional_javascript() {
    return false;
}

public function start_attempt($question, $context, $state, $cmoptions) {
    return new qtype_random_quadratic_attempt($question, $state, $context);
}

}

public function print_question_formulation_and_controls($question, $state, $cmoptions, $options) {
global $OUTPUT;

$a = $question->options['a'];
$b = $question->options['b'];
$c = $question->options['c'];


$questiontext = "$a x^2 + $b x + $c = 0";


echo $OUTPUT->box_start('boxquestion');
echo $OUTPUT->heading(format_text($questiontext), 5, 'questiontext');
echo $OUTPUT->box_end();


echo $OUTPUT->hidden('answer', 0);
echo $OUTPUT->hidden('questionid', $question->id);

} public function grade_responses($question, $state, $cmoptions) { $raw_grade = $state->responses['answer']; $result = new StdClass; $result->fraction = ($raw_grade == 1) ? 1 : 0; $result->feedback = ''; return $result; }

public function get_correct_responses($question, $state) { return array('' => 1); }

public function response_summary_format() { return QUESTION_RESPONSE_SUMMARY_IGNORE; }

public function get_question_options($question) { $options = array(); $options['a'] = $question->a; $options['b'] = $question->b; $options['c'] = $question->c; return $options; } ?> ''''

Snapey's avatar

you close the class then have further public functions in the file

Also, avoid using closing php tags at the end of the file - ?> -they can lead to unwanted output in the response stream

Prohor's avatar

@Snapey This means that I do not have to close the class and continue the declaration in it public functions?

kokoshneta's avatar

It’s very hard to read when only half the code is in code blocks. Please edit the post and put all the code in a code block. You do this by adding three backticks (```) on a separate line both before and after the code.

Please or to participate in this conversation.