MDL-27413 qtype_multianswer more coding style cleanup.

This commit is contained in:
Tim Hunt 2011-05-26 11:25:26 +01:00
parent df4be1222e
commit 12c6e0087e
4 changed files with 153 additions and 149 deletions

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -69,14 +68,12 @@ class qtype_multianswer_question extends question_graded_automatically {
public function start_attempt(question_attempt_step $step) { public function start_attempt(question_attempt_step $step) {
foreach ($this->subquestions as $i => $subq) { foreach ($this->subquestions as $i => $subq) {
$subq->start_attempt($this->get_substep($step, $i)); $subq->start_attempt($this->get_substep($step, $i));
} }
} }
public function apply_attempt_state(question_attempt_step $step) { public function apply_attempt_state(question_attempt_step $step) {
foreach ($this->subquestions as $i => $subq) { foreach ($this->subquestions as $i => $subq) {
$subq->apply_attempt_state($this->get_substep($step, $i)); $subq->apply_attempt_state($this->get_substep($step, $i));
} }
} }

View file

@ -92,7 +92,8 @@ class qtype_multianswer extends question_type {
array('question' => $question->id))) { array('question' => $question->id))) {
$oldwrappedquestions = array(); $oldwrappedquestions = array();
} else { } else {
$oldwrappedquestions = $DB->get_records_list('question', 'id', explode(',', $oldwrappedids), 'id ASC'); $oldwrappedquestions = $DB->get_records_list('question', 'id',
explode(',', $oldwrappedids), 'id ASC');
} }
$sequence = array(); $sequence = array();
@ -100,7 +101,8 @@ class qtype_multianswer extends question_type {
if (!empty($wrapped)) { if (!empty($wrapped)) {
// if we still have some old wrapped question ids, reuse the next of them // if we still have some old wrapped question ids, reuse the next of them
if (is_array($oldwrappedquestions) && $oldwrappedquestion = array_shift($oldwrappedquestions)) { if (is_array($oldwrappedquestions) &&
$oldwrappedquestion = array_shift($oldwrappedquestions)) {
$wrapped->id = $oldwrappedquestion->id; $wrapped->id = $oldwrappedquestion->id;
if ($oldwrappedquestion->qtype != $wrapped->qtype) { if ($oldwrappedquestion->qtype != $wrapped->qtype) {
switch ($oldwrappedquestion->qtype) { switch ($oldwrappedquestion->qtype) {
@ -152,7 +154,8 @@ class qtype_multianswer extends question_type {
$multianswer = new stdClass(); $multianswer = new stdClass();
$multianswer->question = $question->id; $multianswer->question = $question->id;
$multianswer->sequence = implode(',', $sequence); $multianswer->sequence = implode(',', $sequence);
if ($oldid = $DB->get_field('question_multianswer', 'id', array('question' => $question->id))) { if ($oldid = $DB->get_field('question_multianswer', 'id',
array('question' => $question->id))) {
$multianswer->id = $oldid; $multianswer->id = $oldid;
$DB->update_record('question_multianswer', $multianswer); $DB->update_record('question_multianswer', $multianswer);
} else { } else {
@ -248,7 +251,8 @@ define('NUMERICAL_ABS_ERROR_MARGIN', 6);
// Remaining ANSWER regexes // Remaining ANSWER regexes
define('ANSWER_TYPE_DEF_REGEX', define('ANSWER_TYPE_DEF_REGEX',
'(NUMERICAL|NM)|(MULTICHOICE|MC)|(MULTICHOICE_V|MCV)|(MULTICHOICE_H|MCH)|(SHORTANSWER|SA|MW)|(SHORTANSWER_C|SAC|MWC)'); '(NUMERICAL|NM)|(MULTICHOICE|MC)|(MULTICHOICE_V|MCV)|(MULTICHOICE_H|MCH)|' .
'(SHORTANSWER|SA|MW)|(SHORTANSWER_C|SAC|MWC)');
define('ANSWER_START_REGEX', define('ANSWER_START_REGEX',
'\{([0-9]*):(' . ANSWER_TYPE_DEF_REGEX . '):'); '\{([0-9]*):(' . ANSWER_TYPE_DEF_REGEX . '):');

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -33,13 +32,13 @@ require_once($CFG->dirroot . '/question/type/shortanswer/renderer.php');
* Base class for generating the bits of output common to multianswer * Base class for generating the bits of output common to multianswer
* (Cloze) questions. * (Cloze) questions.
* This render the main question text and transfer to the subquestions * This render the main question text and transfer to the subquestions
* the task of display their input elements and status * the task of display their input elements and status
* feedback, grade, correct answer(s) * feedback, grade, correct answer(s)
* *
* @copyright 2010 Pierre Pichet * @copyright 2010 Pierre Pichet
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class qtype_multianswer_renderer extends qtype_renderer { class qtype_multianswer_renderer extends qtype_renderer {
public function formulation_and_controls(question_attempt $qa, public function formulation_and_controls(question_attempt $qa,
question_display_options $options) { question_display_options $options) {
@ -156,13 +155,15 @@ class qtype_multianswer_textfield_renderer extends qtype_renderer {
if ($options->rightanswer) { if ($options->rightanswer) {
$correct = $subq->get_matching_answer($subq->get_correct_response()); $correct = $subq->get_matching_answer($subq->get_correct_response());
$feedback[] = get_string('correctansweris', 'qtype_shortanswer', s($correct->answer)); $feedback[] = get_string('correctansweris', 'qtype_shortanswer',
s($correct->answer));
} }
$subfraction = ''; $subfraction = '';
if ($options->marks >= question_display_options::MARK_AND_MAX && $subq->maxmark > 0) { if ($options->marks >= question_display_options::MARK_AND_MAX && $subq->maxmark > 0) {
$a = new stdClass(); $a = new stdClass();
$a->mark = format_float($matchinganswer->fraction * $subq->maxmark, $options->markdp); $a->mark = format_float($matchinganswer->fraction * $subq->maxmark,
$options->markdp);
$a->max = format_float($subq->maxmark, $options->markdp); $a->max = format_float($subq->maxmark, $options->markdp);
$feedback[] = get_string('markoutofmax', 'question', $a); $feedback[] = get_string('markoutofmax', 'question', $a);
} }
@ -182,12 +183,15 @@ class qtype_multianswer_textfield_renderer extends qtype_renderer {
} }
} }
/** /**
* As multianswer have specific display requirements for multichoice display * As multianswer have specific display requirements for multichoice display
* a new class was defined although largely following the multichoice one * a new class was defined although largely following the multichoice one
*
* @copyright 2010 Pierre Pichet
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
abstract class qtype_multianswer_multichoice_renderer_base extends qtype_renderer {
abstract class qtype_multianswer_multichoice_renderer_base extends qtype_renderer {
abstract protected function get_input_type(); abstract protected function get_input_type();
abstract protected function get_input_name(question_attempt $qa, $value); abstract protected function get_input_name(question_attempt $qa, $value);
@ -201,23 +205,21 @@ abstract class qtype_multianswer_multichoice_renderer_base extends qtype_render
abstract protected function is_right(question_answer $ans); abstract protected function is_right(question_answer $ans);
abstract protected function get_response(question_attempt $qa); abstract protected function get_response(question_attempt $qa);
public function specific_feedback(question_attempt $qa) { public function specific_feedback(question_attempt $qa) {
return ''; return '';
} }
public function formulation_and_controls(question_attempt $qa, public function formulation_and_controls(question_attempt $qa,
question_display_options $options) { question_display_options $options) {
$questiontot = $qa->get_question(); $questiontot = $qa->get_question();
$subquestion = $questiontot->subquestions[$qa->subquestionindex]; $subquestion = $questiontot->subquestions[$qa->subquestionindex];
$order = $subquestion->get_order($qa); //array_keys($question->answers); // $order = $subquestion->get_order($qa);
$response = $this->get_response($qa); $response = $this->get_response($qa);
$inputattributes = array( $inputattributes = array(
'type' => $this->get_input_type(), 'type' => $this->get_input_type(),
); );
if ($options->readonly) { if ($options->readonly) {
$inputattributes['disabled'] = 'disabled'; $inputattributes['disabled'] = 'disabled';
@ -226,23 +228,22 @@ abstract class qtype_multianswer_multichoice_renderer_base extends qtype_render
$feedbackimg = array(); $feedbackimg = array();
$feedback = array(); $feedback = array();
$classes = array(); $classes = array();
$totfraction = 0 ; $totfraction = 0;
$nullresponse = true ; $nullresponse = true;
foreach ($order as $value => $ansid) { foreach ($order as $value => $ansid) {
$ans = $subquestion->answers[$ansid]; $ans = $subquestion->answers[$ansid];
$inputattributes['name'] = $this->get_input_name($qa, $value); $inputattributes['name'] = $this->get_input_name($qa, $value);
// echo "<p>name $value name".$inputattributes['name']." </p>";
$inputattributes['value'] = $this->get_input_value($value); $inputattributes['value'] = $this->get_input_value($value);
$inputattributes['id'] = $this->get_input_id($qa, $value); $inputattributes['id'] = $this->get_input_id($qa, $value);
if ($subquestion->single) { if ($subquestion->single) {
$isselected = $this->is_choice_selected($response, $value); $isselected = $this->is_choice_selected($response, $value);
} else { } else {
$isselected = $this->is_choice_selected($response,$value) ; //$subquestion->field( $value)); $isselected = $this->is_choice_selected($response, $value);
} }
if ($isselected) { if ($isselected) {
$inputattributes['checked'] = 'checked'; $inputattributes['checked'] = 'checked';
$totfraction += $ans->fraction ; $totfraction += $ans->fraction;
$nullresponse = false ; $nullresponse = false;
} else { } else {
unset($inputattributes['checked']); unset($inputattributes['checked']);
} }
@ -266,55 +267,54 @@ abstract class qtype_multianswer_multichoice_renderer_base extends qtype_render
$classes[] = $class; $classes[] = $class;
} }
$result = '' ; $result = '';
$answername = 'answer' ; $answername = 'answer';
if ($subquestion->layout == 1 ){ if ($subquestion->layout == 1) {
$result .= html_writer::start_tag('div', array('class' => 'ablock')); $result .= html_writer::start_tag('div', array('class' => 'ablock'));
$result .= html_writer::start_tag('table', array('class' => $answername)); $result .= html_writer::start_tag('table', array('class' => $answername));
foreach ($radiobuttons as $key => $radio) { foreach ($radiobuttons as $key => $radio) {
$result .= html_writer::start_tag('tr', array('class' => $answername)); $result .= html_writer::start_tag('tr', array('class' => $answername));
$result .= html_writer::start_tag('td', array('class' => $answername)); $result .= html_writer::start_tag('td', array('class' => $answername));
$result .= html_writer::tag('span',$radio . $feedbackimg[$key] . $feedback[$key], array('class' => $classes[$key])) . "\n"; $result .= html_writer::tag('span', $radio . $feedbackimg[$key] . $feedback[$key], array('class' => $classes[$key])) . "\n";
$result .= html_writer::end_tag('td'); $result .= html_writer::end_tag('td');
$result .= html_writer::end_tag('tr'); $result .= html_writer::end_tag('tr');
} }
$result .= html_writer::end_tag('table'); // answer $result .= html_writer::end_tag('table'); // answer
$result .= html_writer::end_tag('div'); // ablock $result .= html_writer::end_tag('div'); // ablock
} }
if ($subquestion->layout == 2 ){ if ($subquestion->layout == 2) {
$result .= html_writer::start_tag('div', array('class' => 'ablock')); $result .= html_writer::start_tag('div', array('class' => 'ablock'));
$result .= html_writer::start_tag('table', array('class' => $answername)); $result .= html_writer::start_tag('table', array('class' => $answername));
$result .= html_writer::start_tag('tr', array('class' => $answername)); $result .= html_writer::start_tag('tr', array('class' => $answername));
foreach ($radiobuttons as $key => $radio) { foreach ($radiobuttons as $key => $radio) {
$result .= html_writer::start_tag('td', array('class' => $answername)); $result .= html_writer::start_tag('td', array('class' => $answername));
$result .= html_writer::tag('span',$radio . $feedbackimg[$key] . $feedback[$key] $result .= html_writer::tag('span', $radio . $feedbackimg[$key] . $feedback[$key]
, array('class' => $classes[$key])) . "\n"; , array('class' => $classes[$key])) . "\n";
$result .= html_writer::end_tag('td'); $result .= html_writer::end_tag('td');
} }
$result .= html_writer::end_tag('tr'); $result .= html_writer::end_tag('tr');
$result .= html_writer::end_tag('table'); // answer $result .= html_writer::end_tag('table'); // answer
$result .= html_writer::end_tag('div'); // ablock $result .= html_writer::end_tag('div'); // ablock
}
}
if ($options->feedback ) { if ($options->feedback) {
$result .= html_writer::start_tag('div', array('class' => 'outcome')); $result .= html_writer::start_tag('div', array('class' => 'outcome'));
if ($options->correctness ) { if ($options->correctness) {
if ( $nullresponse ){ if ( $nullresponse) {
$state = $qa->get_state(); $state = $qa->get_state();
$state = question_state::$invalid; $state = question_state::$invalid;
$result1 = $state->default_string(); $result1 = $state->default_string();
$result .= html_writer::nonempty_tag('div',$result1,
array('class' => 'validationerror'));
$result1 = ($subquestion->single) ? get_string('singleanswer', 'quiz') : get_string('multipleanswers', 'quiz');
$result .= html_writer::nonempty_tag('div', $result1, $result .= html_writer::nonempty_tag('div', $result1,
array('class' => 'validationerror')) array('class' => 'validationerror'));
; $result1 = ($subquestion->single) ? get_string('singleanswer', 'quiz') : get_string('multipleanswers', 'quiz');
}else { $result .= html_writer::nonempty_tag('div', $result1,
array('class' => 'validationerror'));
} else {
$state = $qa->get_state(); $state = $qa->get_state();
$state = question_state::graded_state_for_fraction($totfraction); $state = question_state::graded_state_for_fraction($totfraction);
$result1 = $state->default_string(); $result1 = $state->default_string();
@ -322,25 +322,23 @@ abstract class qtype_multianswer_multichoice_renderer_base extends qtype_render
array('class' => 'outcome')); array('class' => 'outcome'));
} }
} }
if ($options->correctresponse ) {
$result1 = $this->correct_response($qa);
$result .= html_writer::nonempty_tag('div',$result1, array('class' => 'outcome'))
;
}
if ($options->marks ) {
$subgrade= $totfraction * $subquestion->defaultmark ;
$result .= $questiontot->mark_summary($options, $subquestion->defaultmark , $subgrade );
}
if ($qa->get_state() == question_state::$invalid) { if ($options->correctresponse) {
$result .= html_writer::nonempty_tag('div', array('class' => 'validationerror'), $result1 = $this->correct_response($qa);
$subquestion->get_validation_error($qa->get_last_qt_data())); $result .= html_writer::nonempty_tag('div', $result1, array('class' => 'outcome'));
} }
$result .= html_writer::end_tag('div'); if ($options->marks) {
$subgrade= $totfraction * $subquestion->defaultmark;
$result .= $questiontot->mark_summary($options, $subquestion->defaultmark , $subgrade);
}
} if ($qa->get_state() == question_state::$invalid) {
$result .= html_writer::nonempty_tag('div', array('class' => 'validationerror'),
$subquestion->get_validation_error($qa->get_last_qt_data()));
}
$result .= html_writer::end_tag('div');
}
return $result; return $result;
} }
@ -349,27 +347,30 @@ abstract class qtype_multianswer_multichoice_renderer_base extends qtype_render
class qtype_multianswer_multichoice_single_renderer extends qtype_multianswer_multichoice_renderer_base { class qtype_multianswer_multichoice_single_renderer extends qtype_multianswer_multichoice_renderer_base {
protected function get_input_type() { protected function get_input_type() {
return 'radio'; return 'radio';
} }
protected function is_choice_selected($response, $value) { protected function is_choice_selected($response, $value) {
return $response == $value ; return $response == $value;
} }
protected function is_right(question_answer $ans) {
return $ans->fraction > 0.9999999;
}
protected function get_input_name(question_attempt $qa, $value) {
$questiontot = $qa->get_question();
$subquestion = $questiontot->subquestions[$qa->subquestionindex];
$answername = $subquestion->fieldid.'answer';
return $qa->get_qt_field_name($answername);
}
protected function get_input_value($value) {
return $value;
}
protected function get_input_id(question_attempt $qa, $value) { protected function is_right(question_answer $ans) {
return $ans->fraction > 0.9999999;
}
protected function get_input_name(question_attempt $qa, $value) {
$questiontot = $qa->get_question();
$subquestion = $questiontot->subquestions[$qa->subquestionindex];
$answername = $subquestion->fieldid.'answer';
return $qa->get_qt_field_name($answername);
}
protected function get_input_value($value) {
return $value;
}
protected function get_input_id(question_attempt $qa, $value) {
$questiontot = $qa->get_question(); $questiontot = $qa->get_question();
$subquestion = $questiontot->subquestions[$qa->subquestionindex]; $subquestion = $questiontot->subquestions[$qa->subquestionindex];
$answername = $subquestion->fieldid.'answer'; $answername = $subquestion->fieldid.'answer';
@ -380,12 +381,13 @@ class qtype_multianswer_multichoice_single_renderer extends qtype_multianswer_mu
$questiontot = $qa->get_question(); $questiontot = $qa->get_question();
$subquestion = $questiontot->subquestions[$qa->subquestionindex]; $subquestion = $questiontot->subquestions[$qa->subquestionindex];
return $qa->get_last_qt_var($subquestion->fieldid.'answer', -1); return $qa->get_last_qt_var($subquestion->fieldid.'answer', -1);
} }
public function correct_response(question_attempt $qa) { public function correct_response(question_attempt $qa) {
$questiontot = $qa->get_question(); $questiontot = $qa->get_question();
$subquestion = $questiontot->subquestions[$qa->subquestionindex]; $subquestion = $questiontot->subquestions[$qa->subquestionindex];
foreach ($subquestion->answers as $ans) { foreach ($subquestion->answers as $ans) {
if ($ans->fraction > 0.9999999) { if ($ans->fraction > 0.9999999) {
return get_string('correctansweris', 'qtype_multichoice', return get_string('correctansweris', 'qtype_multichoice',
@ -393,27 +395,28 @@ class qtype_multianswer_multichoice_single_renderer extends qtype_multianswer_mu
} }
} }
return ''; return '';
} }
} }
class qtype_multianswer_multichoice_single_inline_renderer extends qtype_multianswer_multichoice_single_renderer { class qtype_multianswer_multichoice_single_inline_renderer extends qtype_multianswer_multichoice_single_renderer {
protected function get_input_type() { protected function get_input_type() {
return 'select'; return 'select';
} }
public function formulation_and_controls(question_attempt $qa, public function formulation_and_controls(question_attempt $qa,
question_display_options $options) { question_display_options $options) {
$questiontot = $qa->get_question(); $questiontot = $qa->get_question();
$subquestion = $questiontot->subquestions[$qa->subquestionindex]; $subquestion = $questiontot->subquestions[$qa->subquestionindex];
$answers = $subquestion->answers; $answers = $subquestion->answers;
$correctanswers = $subquestion->get_correct_response(); $correctanswers = $subquestion->get_correct_response();
foreach($correctanswers as $key=> $value){ foreach ($correctanswers as $key => $value) {
$correct = $value ; $correct = $value;
} }
$order = $subquestion->get_order($qa); $order = $subquestion->get_order($qa);
$response = $this->get_response($qa); $response = $this->get_response($qa);
$currentanswer = $response ; $currentanswer = $response;
$answername = $subquestion->fieldid.'answer'; $answername = $subquestion->fieldid.'answer';
$inputname = $qa->get_qt_field_name($answername); $inputname = $qa->get_qt_field_name($answername);
$inputattributes = array( $inputattributes = array(
@ -427,25 +430,25 @@ class qtype_multianswer_multichoice_single_inline_renderer extends qtype_multian
} }
$choices = array(); $choices = array();
$popup = ''; $popup = '';
$feedback = '' ; $feedback = '';
$answer = '' ; $answer = '';
$classes = 'control'; $classes = 'control';
$feedbackimage = ''; $feedbackimage = '';
$fraction = 0 ; $fraction = 0;
$chosen = 0 ; $chosen = 0;
foreach ($order as $value => $ansid) { foreach ($order as $value => $ansid) {
$mcanswer = $subquestion->answers[$ansid]; $mcanswer = $subquestion->answers[$ansid];
$choices[$value] = strip_tags($mcanswer->answer); $choices[$value] = strip_tags($mcanswer->answer);
$selected = ''; $selected = '';
$isselected = false ; $isselected = false;
if( $response != ''){ if ( $response != '') {
$isselected = $this->is_choice_selected($response, $value); $isselected = $this->is_choice_selected($response, $value);
} }
if ($isselected) { if ($isselected) {
$chosen = $value ; $chosen = $value;
$answer = $mcanswer ; $answer = $mcanswer;
$fraction = $mcanswer->fraction ; $fraction = $mcanswer->fraction;
$selected = ' selected="selected"'; $selected = ' selected="selected"';
} }
} }
@ -466,63 +469,60 @@ class qtype_multianswer_multichoice_single_inline_renderer extends qtype_multian
// subquestion status correctness or Finished validator if correctness // subquestion status correctness or Finished validator if correctness
// Correct response // Correct response
// marks // marks
$strfeedbackwrapped = 'Response Status'; $strfeedbackwrapped = 'Response Status';
if ($options->feedback ) { if ($options->feedback) {
$feedback = get_string('feedback', 'quiz').":".$feedback."<br />"; $feedback = get_string('feedback', 'quiz').":".$feedback."<br />";
if ($options->correctness ) { if ($options->correctness) {
if ( ! $answer ){ if (!$answer) {
$state = $qa->get_state(); $state = $qa->get_state();
$state = question_state::$invalid; $state = question_state::$invalid;
$strfeedbackwrapped .= ":<font color=red >".$state->default_string()."</font>" ; $strfeedbackwrapped .= ":<font color=red >".$state->default_string()."</font>";
$feedback = "<font color=red >".get_string('singleanswer', 'quiz') ."</font><br />"; $feedback = "<font color=red >".get_string('singleanswer', 'quiz') ."</font><br />";
}else { } else {
$state = $qa->get_state(); $state = $qa->get_state();
$state = question_state::graded_state_for_fraction($fraction); $state = question_state::graded_state_for_fraction($fraction);
$strfeedbackwrapped .= ":".$state->default_string(); $strfeedbackwrapped .= ":".$state->default_string();
} }
} }
if ($options->correctresponse) {
if ($options->correctresponse ) {
$feedback .= $this->correct_response($qa)."<br />"; $feedback .= $this->correct_response($qa)."<br />";
} }
if ($options->marks ) { if ($options->marks) {
$subgrade= $fraction * $subquestion->defaultmark ; $subgrade= $fraction * $subquestion->defaultmark;
$feedback .= $questiontot->mark_summary($options, $subquestion->defaultmark , $subgrade ); $feedback .= $questiontot->mark_summary($options, $subquestion->defaultmark , $subgrade);
} }
$feedback .= '</div>'; $feedback .= '</div>';
} }
if ($options->feedback ) { if ($options->feedback) {
// need to replace ' and " as they could break the popup string // need to replace ' and " as they could break the popup string
// as the text comes from database, slashes have been removed // as the text comes from database, slashes have been removed
// addslashes will not work as it keeps the " // addslashes will not work as it keeps the "
// HTML &#039; for ' does not work // HTML &#039; for ' does not work
$feedback = str_replace("'","\'",$feedback); $feedback = str_replace("'", "\'", $feedback);
$feedback = str_replace('"',"\'",$feedback); $feedback = str_replace('"', "\'", $feedback);
$strfeedbackwrapped = str_replace("'","\'",$strfeedbackwrapped); $strfeedbackwrapped = str_replace("'", "\'", $strfeedbackwrapped);
$strfeedbackwrapped = str_replace('"',"\'",$strfeedbackwrapped); $strfeedbackwrapped = str_replace('"', "\'", $strfeedbackwrapped);
$popup = " onmouseover=\"return overlib('$feedback', STICKY, MOUSEOFF, CAPTION, '$strfeedbackwrapped', FGCOLOR, '#FFFFFF');\" ". $popup = " onmouseover=\"return overlib('$feedback', STICKY, MOUSEOFF, CAPTION, '$strfeedbackwrapped', FGCOLOR, '#FFFFFF');\" ".
" onmouseout=\"return nd();\" "; " onmouseout=\"return nd();\" ";
} }
$result = ''; $result = '';
$result .= "<span $popup >"; $result .= "<span $popup >";
$result .= html_writer::start_tag('span', array('class' => $classes), ''); $result .= html_writer::start_tag('span', array('class' => $classes), '');
$result .=
choose_from_menu($choices, $inputname, $chosen,
' ', '', '', true, $options->readonly) . $feedbackimage ;
$result .= html_writer::end_tag('span');
$result .= html_writer::end_tag('span');
$result .= choose_from_menu($choices, $inputname, $chosen,
' ', '', '', true, $options->readonly) . $feedbackimage;
$result .= html_writer::end_tag('span');
$result .= html_writer::end_tag('span');
return $result; return $result;
} }
protected function format_choices($question) { protected function format_choices($question) {
$choices = array(); $choices = array();
foreach ($question->get_choice_order() as $key => $choiceid) { foreach ($question->get_choice_order() as $key => $choiceid) {
@ -556,14 +556,14 @@ class qtype_multianswer_multichoice_multi_renderer extends qtype_multianswer_mul
$responses = $qa->get_last_qt_data(); $responses = $qa->get_last_qt_data();
$questiontot = $qa->get_question(); $questiontot = $qa->get_question();
$subresponses =$questiontot->decode_subquestion_responses($responses); $subresponses =$questiontot->decode_subquestion_responses($responses);
if( isset($subresponses[$qa->subquestionindex])) { if ( isset($subresponses[$qa->subquestionindex])) {
return $subresponses[$qa->subquestionindex] ; return $subresponses[$qa->subquestionindex];
}else{ } else {
return ''; return '';
} }
} }
protected function is_choice_selected($response, $value) { protected function is_choice_selected($response, $value) {
return isset($response['choice'.$value]); return isset($response['choice'.$value]);
} }
@ -585,11 +585,11 @@ class qtype_multianswer_multichoice_multi_renderer extends qtype_multianswer_mul
if (!empty($right)) { if (!empty($right)) {
return get_string('correctansweris', 'qtype_multichoice', return get_string('correctansweris', 'qtype_multichoice',
implode(', ', $right)); implode(', ', $right));
} }
return ''; return '';
} }
} }

View file

@ -90,9 +90,12 @@ class qtype_multianswer_test_helper extends question_test_helper {
$mc->layout = 1; $mc->layout = 1;
$mc->answers = array( $mc->answers = array(
13 => new question_answer(13, 'Bow-wow', 0, 'You seem to have a dog obsessions!', FORMAT_HTML), 13 => new question_answer(13, 'Bow-wow', 0,
14 => new question_answer(14, 'Wiggly worm', 0, 'Now you are just being rediculous!', FORMAT_HTML), 'You seem to have a dog obsessions!', FORMAT_HTML),
15 => new question_answer(15, 'Pussy-cat', 1, 'Well done!', FORMAT_HTML), 14 => new question_answer(14, 'Wiggly worm', 0,
'Now you are just being rediculous!', FORMAT_HTML),
15 => new question_answer(15, 'Pussy-cat', 1,
'Well done!', FORMAT_HTML),
); );
$mc->qtype = question_bank::get_qtype('multichoice'); $mc->qtype = question_bank::get_qtype('multichoice');
$mc->maxmark = 1; $mc->maxmark = 1;