Skip to content
Snippets Groups Projects
Commit 24c24ee1 authored by Tim Hunt's avatar Tim Hunt
Browse files

Copy quesion tests when doing 'Make copy' (Issue #41).

If you edit a question and then click the Make copy button
at the bottom of the form, we now detect this, and copy any question
tests from the original question to the new questions.

Of course, if you have added or removed a PRT or input, you will need to
fix the tests, but that is try if you edit a question normally too.
parent 1794c185
No related branches found
No related tags found
No related merge requests found
...@@ -129,6 +129,7 @@ class qtype_stack extends question_type { ...@@ -129,6 +129,7 @@ class qtype_stack extends question_type {
$input = new stdClass(); $input = new stdClass();
$input->questionid = $fromform->id; $input->questionid = $fromform->id;
$input->name = $inputname; $input->name = $inputname;
$input->options = '';
$input->id = $DB->insert_record('qtype_stack_inputs', $input); $input->id = $DB->insert_record('qtype_stack_inputs', $input);
} }
...@@ -266,16 +267,26 @@ class qtype_stack extends question_type { ...@@ -266,16 +267,26 @@ class qtype_stack extends question_type {
} }
} }
// This is a bit of a hack. If doing 'Make a copy' when saving the
// editing form, then detect that here, and try to copy the question
// tests from the original question.
if (!isset($fromform->testcases) && $fromform->makecopy) {
$oldquestionid = optional_param('id', 0, PARAM_INT);
if ($oldquestionid) {
$fromform->testcases = $this->load_question_tests($oldquestionid);
}
}
if (isset($fromform->testcases)) { if (isset($fromform->testcases)) {
// If the data includes the defintion of the question tests that there // If the data includes the defintion of the question tests that there
// should be (i.e. when doing import) then replace the existing set // should be (i.e. when doing import) then replace the existing set
// of tests with the new one. // of tests with the new one.
$this->save_question_tests($fromform->id, $fromform->testcases); $this->save_question_tests($fromform->id, $fromform->testcases);
}
} else { // Irrespective of what else has happened, ensure there is no garbage
// Otherwise, make sure there is no garbage left in the database, // in the database, for example if we delete a PRT, remove the expected
// for example if we delete a PRT, remove the expected values for // values for that PRT while leaving the rest of the testcases alone.
// that PRT while leaving the rest of the testcases alone.
list($nametest, $params) = $DB->get_in_or_equal($inputnames, SQL_PARAMS_NAMED, 'input', false, null); list($nametest, $params) = $DB->get_in_or_equal($inputnames, SQL_PARAMS_NAMED, 'input', false, null);
$params['questionid'] = $fromform->id; $params['questionid'] = $fromform->id;
$DB->delete_records_select('qtype_stack_qtest_inputs', $DB->delete_records_select('qtype_stack_qtest_inputs',
...@@ -286,7 +297,6 @@ class qtype_stack extends question_type { ...@@ -286,7 +297,6 @@ class qtype_stack extends question_type {
$DB->delete_records_select('qtype_stack_qtest_expected', $DB->delete_records_select('qtype_stack_qtest_expected',
'questionid = :questionid AND prtname ' . $nametest, $params); 'questionid = :questionid AND prtname ' . $nametest, $params);
} }
}
public function get_question_options($question) { public function get_question_options($question) {
global $DB; global $DB;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment