Hi All,
I want to extend the abstract class "qtype_multichoice_renderer_base" located at "
/question/type/multichoice/renderer.php". I am using enlightlite theme and moodle version 3.6. I added a new file in the theme/classes folder and tried extending the class but I am getting 'HTTP ERROR 500' error.
Please suggest how can I resolve this error and can extend the class successfully.
Please find below the snippet of the code for your reference.
<?php
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/type/multichoice/renderer.php');
abstract class theme_enlightlite_qtype_multichoice_renderer extends qtype_multichoice_renderer_base {
protected abstract function get_input_type();
protected abstract function get_input_name(question_attempt $qa, $value);
protected abstract function get_input_value($value);
protected abstract function get_input_id(question_attempt $qa, $value);
protected abstract function is_right(question_answer $ans);
protected abstract function prompt();
public function formulation_and_controls(question_attempt $qa, question_display_options $options) {
$question = $qa->get_question();
$response = $question->get_response($qa);
$inputname = $qa->get_qt_field_name('answer');
$inputattributes = array(
'type' => $this->get_input_type(),
'name' => $inputname,
);
if ($options->readonly) {
$inputattributes['disabled'] = 'disabled';
}
$radiobuttons = array();
$feedbackimg = array();
$feedback = array();
$classes = array();
foreach ($question->get_order($qa) as $value => $ansid) {
$ans = $question->answers[$ansid];
$inputattributes['name'] = $this->get_input_name($qa, $value);
$inputattributes['value'] = $this->get_input_value($value);
$inputattributes['id'] = $this->get_input_id($qa, $value);
$isselected = $question->is_choice_selected($response, $value);
if ($isselected) {
$inputattributes['checked'] = 'checked';
} else {
unset($inputattributes['checked']);
}
$hidden = '';
if (!$options->readonly && $this->get_input_type() == 'checkbox') {
$hidden = html_writer::empty_tag('input', array(
'type' => 'hidden',
'name' => $inputattributes['name'],
'value' => 0,
));
}
$radiobuttons[] = $hidden . html_writer::empty_tag('input', $inputattributes) .
html_writer::tag('label',
html_writer::span($this->number_in_style($value, $question->answernumbering), 'answernumber') .
$question->make_html_inline($question->format_text(
$ans->answer, $ans->answerformat,
$qa, 'question', 'answer', $ansid)),
array('for' => $inputattributes['id'], 'class' => 'm-l-1'));
// Param $options->suppresschoicefeedback is a hack specific to the
// oumultiresponse question type. It would be good to refactor to
// avoid refering to it here.
if ($options->feedback && empty($options->suppresschoicefeedback) &&
$isselected && trim($ans->feedback)) {
$feedback[] = html_writer::tag('div',
$question->make_html_inline($question->format_text(
$ans->feedback, $ans->feedbackformat,
$qa, 'question', 'answerfeedback', $ansid)),
array('class' => 'specificfeedback'));
} else {
$feedback[] = '';
}
$class = 'r' . ($value % 2);
if ($options->correctness && $isselected) {
$feedbackimg[] = $this->feedback_image($this->is_right($ans));
$class .= ' ' . $this->feedback_class($this->is_right($ans));
} else {
$feedbackimg[] = '';
}
$classes[] = $class;
}
$result = '';
$result .= html_writer::tag('div', $question->format_questiontext($qa),
array('class' => 'qtext hello'));
$result .= html_writer::start_tag('div', array('class' => 'ablock'));
$result .= html_writer::tag('div', $this->prompt(), array('class' => 'prompt'));
$result .= html_writer::start_tag('div', array('class' => 'answer'));
foreach ($radiobuttons as $key => $radio) {
$result .= html_writer::tag('div', $radio . ' ' . $feedbackimg[$key] . $feedback[$key],
array('class' => $classes[$key])) . "\n";
}
$result .= html_writer::end_tag('div'); // Answer.
$result .= html_writer::end_tag('div'); // Ablock.
if ($qa->get_state() == question_state::$invalid) {
$result .= html_writer::nonempty_tag('div',
$question->get_validation_error($qa->get_last_qt_data()),
array('class' => 'validationerror'));
}
return $result;
}
}