MDL-20636 Fix codechecker issues in qtype_truefalse.
This commit is contained in:
@@ -60,7 +60,8 @@ class backup_qtype_truefalse_plugin extends backup_qtype_plugin {
|
||||
$pluginwrapper->add_child($truefalse);
|
||||
|
||||
// set source to populate the data
|
||||
$truefalse->set_source_table('question_truefalse', array('question' => backup::VAR_PARENTID));
|
||||
$truefalse->set_source_table('question_truefalse',
|
||||
array('question' => backup::VAR_PARENTID));
|
||||
|
||||
// don't need to annotate ids nor files
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ class restore_qtype_truefalse_plugin extends restore_qtype_plugin {
|
||||
$elepath = $this->get_pathfor('/truefalse'); // we used get_recommended_name() so this works
|
||||
$paths[] = new restore_path_element($elename, $elepath);
|
||||
|
||||
|
||||
return $paths; // And we return the interesting paths
|
||||
}
|
||||
|
||||
@@ -78,8 +77,6 @@ class restore_qtype_truefalse_plugin extends restore_qtype_plugin {
|
||||
$newitemid = $DB->insert_record('question_truefalse', $data);
|
||||
// Create mapping
|
||||
$this->set_mapping('question_truefalse', $oldid, $newitemid);
|
||||
} else {
|
||||
// Nothing to remap if the question already existed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,20 +44,26 @@ class qtype_truefalse_edit_form extends question_edit_form {
|
||||
* @param object $mform the form being built.
|
||||
*/
|
||||
protected function definition_inner($mform) {
|
||||
$mform->addElement('select', 'correctanswer', get_string('correctanswer', 'qtype_truefalse'),
|
||||
array(0 => get_string('false', 'qtype_truefalse'), 1 => get_string('true', 'qtype_truefalse')));
|
||||
$mform->addElement('select', 'correctanswer',
|
||||
get_string('correctanswer', 'qtype_truefalse'), array(
|
||||
0 => get_string('false', 'qtype_truefalse'),
|
||||
1 => get_string('true', 'qtype_truefalse')));
|
||||
|
||||
$mform->addElement('editor', 'feedbacktrue', get_string('feedbacktrue', 'qtype_truefalse'), null, $this->editoroptions);;
|
||||
$mform->addElement('editor', 'feedbacktrue',
|
||||
get_string('feedbacktrue', 'qtype_truefalse'), null, $this->editoroptions);
|
||||
$mform->setType('feedbacktrue', PARAM_RAW);
|
||||
|
||||
$mform->addElement('editor', 'feedbackfalse', get_string('feedbackfalse', 'qtype_truefalse'), null, $this->editoroptions);
|
||||
$mform->addElement('editor', 'feedbackfalse',
|
||||
get_string('feedbackfalse', 'qtype_truefalse'), null, $this->editoroptions);
|
||||
$mform->setType('feedbackfalse', PARAM_RAW);
|
||||
|
||||
$mform->addElement('header', 'multitriesheader', get_string('settingsformultipletries', 'question'));
|
||||
$mform->addElement('header', 'multitriesheader',
|
||||
get_string('settingsformultipletries', 'question'));
|
||||
|
||||
$mform->addElement('hidden', 'penalty', 1);
|
||||
|
||||
$mform->addElement('static', 'penaltymessage', get_string('penaltyforeachincorrecttry', 'question'), 1);
|
||||
$mform->addElement('static', 'penaltymessage',
|
||||
get_string('penaltyforeachincorrecttry', 'question'), 1);
|
||||
$mform->addHelpButton('penaltymessage', 'penaltyforeachincorrecttry', 'question');
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,8 @@ class qtype_truefalse_question extends question_graded_automatically {
|
||||
($answerid == $this->falseanswerid && $response !== ''));
|
||||
|
||||
} else {
|
||||
return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload);
|
||||
return parent::check_file_access($qa, $options, $component, $filearea,
|
||||
$args, $forcedownload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class qtype_truefalse extends question_type {
|
||||
|
||||
// Delete any left over old answer records.
|
||||
$fs = get_file_storage();
|
||||
foreach($oldanswers as $oldanswer) {
|
||||
foreach ($oldanswers as $oldanswer) {
|
||||
$fs->delete_area_files($context->id, 'question', 'answerfeedback', $oldanswer->id);
|
||||
$DB->delete_records('question_answers', array('id' => $oldanswer->id));
|
||||
}
|
||||
@@ -114,14 +114,17 @@ class qtype_truefalse extends question_type {
|
||||
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))) {
|
||||
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;
|
||||
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;
|
||||
@@ -135,11 +138,13 @@ class qtype_truefalse extends question_type {
|
||||
} else {
|
||||
$question->rightanswer = false;
|
||||
}
|
||||
$question->truefeedback = $answers[$questiondata->options->trueanswer]->feedback;
|
||||
$question->truefeedback = $answers[$questiondata->options->trueanswer]->feedback;
|
||||
$question->falsefeedback = $answers[$questiondata->options->falseanswer]->feedback;
|
||||
$question->truefeedbackformat = $answers[$questiondata->options->trueanswer]->feedbackformat;
|
||||
$question->falsefeedbackformat = $answers[$questiondata->options->falseanswer]->feedbackformat;
|
||||
$question->trueanswerid = $questiondata->options->trueanswer;
|
||||
$question->truefeedbackformat =
|
||||
$answers[$questiondata->options->trueanswer]->feedbackformat;
|
||||
$question->falsefeedbackformat =
|
||||
$answers[$questiondata->options->falseanswer]->feedbackformat;
|
||||
$question->trueanswerid = $questiondata->options->trueanswer;
|
||||
$question->falseanswerid = $questiondata->options->falseanswer;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class qtype_truefalse_question_test extends UnitTestCase {
|
||||
$this->assertFalse($question->is_gradable_response(array()));
|
||||
$this->assertTrue($question->is_gradable_response(array('answer' => 0)));
|
||||
$this->assertTrue($question->is_gradable_response(array('answer' => 1)));
|
||||
}
|
||||
}
|
||||
|
||||
public function test_grading() {
|
||||
$question = test_question_maker::make_a_truefalse_question();
|
||||
@@ -96,10 +96,12 @@ class qtype_truefalse_question_test extends UnitTestCase {
|
||||
$tf->start_attempt(new question_attempt_step());
|
||||
|
||||
$this->assertEqual(array(
|
||||
$tf->id => new question_classified_response(0, get_string('false', 'qtype_truefalse'), 0.0)),
|
||||
$tf->id => new question_classified_response(
|
||||
0, get_string('false', 'qtype_truefalse'), 0.0)),
|
||||
$tf->classify_response(array('answer' => '0')));
|
||||
$this->assertEqual(array(
|
||||
$tf->id => new question_classified_response(1, get_string('true', 'qtype_truefalse'), 1.0)),
|
||||
$tf->id => new question_classified_response(
|
||||
1, get_string('true', 'qtype_truefalse'), 1.0)),
|
||||
$tf->classify_response(array('answer' => '1')));
|
||||
$this->assertEqual(array(
|
||||
$tf->id => question_classified_response::no_response()),
|
||||
|
||||
Reference in New Issue
Block a user