Skip to content
Snippets Groups Projects
Commit b99ff43e authored by Chris Sangwin's avatar Chris Sangwin
Browse files

WIP fix to issue #724.

parent 9534e652
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,60 @@ if (!is_null($undeploy) && $question->deployedseeds) {
redirect($nexturl);
}
// Process undeployall if applicable.
$deployfromlist = optional_param('deployfromlist', null, PARAM_INT);
if (!is_null($deployfromlist)) {
// Check data integrity.
$dataproblem = false;
$deploytxt = optional_param('deployfromlist', null, PARAM_TEXT);
$newseeds = explode("\n", $deploytxt);
foreach ($newseeds as $var => $seed) {
// Clean up whitespace.
$newseeds[$var] = trim($seed);
// Force the entry to be a positive integer.
$newseeds[$var] = (int) ($newseeds[$var]);
if ($newseeds[$var] <= 0) {
$dataproblem = true;
}
$newseeds[$var] = (string) ($newseeds[$var]);
}
// No action to take?
if ($newseeds === $question->deployedseeds) {
redirect($nexturl);
}
if (count($newseeds) > 100) {
$nexturl->param('deployfeedbackerr', stack_string('deploymanyerror', array('err' => count($newseeds))));
redirect($nexturl);
}
// Check the entries are all different.
if (count($newseeds) !== count(array_flip($newseeds))) {
// TODO: specific feedback for each error.
$dataproblem = true;
}
if ($dataproblem) {
$nexturl->param('deployfeedbackerr', stack_string('deployfromlisterror'));
redirect($nexturl);
}
// Undeploy all existing variants.
if ($question->deployedseeds) {
foreach ($question->deployedseeds as $seed) {
$question->undeploy_variant($seed);
}
}
// Deploy all new variants.
foreach ($newseeds as $seed) {
$question->deploy_variant($seed);
}
redirect($nexturl);
}
$deploy = optional_param('deploymany', null, PARAM_INT);
$deploytxt = optional_param('deploymany', null, PARAM_TEXT);
$starttime = time();
......
......@@ -499,6 +499,8 @@ $string['deploymanysuccess'] = 'Number of new variants successfully created, tes
$string['deployoutoftime'] = 'Time limit exceeded by using approx {$a->time} seconds. Please try again to deploy more.';
$string['deployremoveall'] = 'Undeploy all variants: ';
$string['deploytestall'] = 'Run all tests on all deployed variants (slow): ';
$string['deployfromlist'] = 'Remove all existing variants and deploy from a list of positive integer seeds, one on each line: ';
$string['deployfromlisterror'] = 'An error was detected in your list of integers, and so no changes were made to the list of deployed variants.';
$string['editingtestcase'] = 'Editing test case {$a->no} for question {$a->question}';
$string['editthistestcase'] = 'Edit this test case...';
$string['expectedanswernote'] = 'Expected answer note';
......
......@@ -263,6 +263,17 @@ if (!$variantmatched) {
array('class' => 'undeployedvariant'));
}
if (!(empty($question->deployedseeds)) && $canedit) {
// Undeploy all the variants.
echo html_writer::start_tag('form', array('method' => 'get', 'class' => 'deploymany',
'action' => new moodle_url('/question/type/stack/deploy.php', $urlparams)));
echo stack_string('deployremoveall');
echo html_writer::input_hidden_params(new moodle_url($PAGE->url, array('sesskey' => sesskey(),
'undeployall' => 'true')));
echo ' ' . html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
echo html_writer::end_tag('form');
}
// Add in some logic for a case where the author removes randomization after variants have been deployed.
if ($question->has_random_variants()) {
echo html_writer::start_tag('p');
......@@ -277,15 +288,6 @@ if ($question->has_random_variants()) {
echo html_writer::end_tag('form');
if ($canedit) {
// Run tests on all the variants.
echo html_writer::start_tag('form', array('method' => 'get', 'class' => 'deploymany',
'action' => new moodle_url('/question/type/stack/questiontestrun.php', $urlparams)));
echo stack_string('deploytestall');
echo html_writer::input_hidden_params(new moodle_url($PAGE->url, array('sesskey' => sesskey(),
'testall' => '1')));
echo ' ' . html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
echo html_writer::end_tag('form');
// Deploy many variants.
echo html_writer::start_tag('form', array('method' => 'get', 'class' => 'deploymany',
'action' => new moodle_url('/question/type/stack/deploy.php', $urlparams)));
......@@ -296,20 +298,42 @@ if ($question->has_random_variants()) {
echo ' ' . html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
echo ' ' . stack_string('deploymanynotes');
echo html_writer::end_tag('form');
}
echo html_writer::end_tag('p');
}
if (!(empty($question->deployedseeds)) && $canedit) {
// Undeploy all the variants.
echo html_writer::start_tag('form', array('method' => 'get', 'class' => 'deploymany',
// Deploy many from a CS list of integer seeds.
echo "\n" . html_writer::start_tag('form', array('method' => 'get', 'class' => 'deployfromlist',
'action' => new moodle_url('/question/type/stack/deploy.php', $urlparams)));
echo stack_string('deployremoveall');
echo html_writer::input_hidden_params(new moodle_url($PAGE->url, array('sesskey' => sesskey())), array('seed'));
echo "\n<table>" . html_writer::start_tag('table');
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td');
echo stack_string('deployfromlist');
echo html_writer::end_tag('td');
echo html_writer::start_tag('td');
echo ' ' . html_writer::start_tag('textarea', array('cols' => 15, 'rows' => count($question->deployedseeds),
'id' => 'deployfromlist', 'name' => 'deployfromlist', 'value' => ''));
echo html_writer::end_tag('textarea');
echo html_writer::end_tag('td');
echo html_writer::start_tag('td');
echo ' ' . html_writer::tag('tt', implode("<br />", $question->deployedseeds));
echo html_writer::end_tag('td');
echo html_writer::start_tag('td');
echo ' ' . html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
echo "\n" . html_writer::end_tag('table');
echo "\n" . html_writer::end_tag('form');
// Run tests on all the variants.
echo html_writer::start_tag('form', array('method' => 'get', 'class' => 'deploymany',
'action' => new moodle_url('/question/type/stack/questiontestrun.php', $urlparams)));
echo stack_string('deploytestall');
echo html_writer::input_hidden_params(new moodle_url($PAGE->url, array('sesskey' => sesskey(),
'undeployall' => 'true')));
'testall' => '1')));
echo ' ' . html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
echo html_writer::end_tag('form');
}
echo html_writer::end_tag('p');
}
echo $OUTPUT->heading(stack_string('questiontestsfor', $seed), 2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment