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

Fine tune export format.

parent 06569f82
Branches
No related tags found
No related merge requests found
......@@ -50,4 +50,3 @@ response_trees:
score: 0
penalty: 0
next_node: -1
......@@ -47,12 +47,22 @@ class qtype_stack_api_export {
$multilang = new stack_multilang();
$languages = $multilang->languages_used($value);
if ($languages == array()) {
$yaml[$propertyname] = $value;
$yaml[$propertyname] = (string) $value;
} else {
foreach($languages as $lang) {
$yaml[$propertyname.'_'.$lang] = $multilang->filter($value, $lang);
$yaml[$propertyname.'_'.$lang] = (string) $multilang->filter($value, $lang);
}
}
} else if ($type == 'float') {
// Prune out some trailing zeros, but this is in the yaml encode function.
$disp = $value;
if ($value === 0.0) {
$disp = 0;
}
if ($value === 1.0) {
$disp = 1;
}
$yaml[$propertyname] = $disp;
} else {
$yaml[$propertyname] = $value;
}
......@@ -148,7 +158,7 @@ class qtype_stack_api_export {
// Add in the deployed seeds.
foreach ($q->deployedseed as $seed) {
$yaml['deployedseed'][] = self::processvalue((string) $seed, 'int');
$yaml['deployedseed'][] = self::processvalue($seed, 'int');
}
return yaml_emit($yaml, YAML_UTF8_ENCODING);
}
......@@ -202,7 +212,9 @@ class qtype_stack_api_export {
$this->property($res, 'quiet', $node->quiet, 'bool', $section);
$this->property($res, 'answer', $node->sans, 'string', $section);
$this->property($res, 'model_answer', $node->tans, 'string', $section);
if (trim($node->testoptions) != '') {
$this->property($res, 'test_options', $node->testoptions, 'string', $section);
}
// True branch.
$section = 'branch-T';
......@@ -277,10 +289,12 @@ class qtype_stack_api_export {
foreach ($test->testinput as $input) {
$this->property($res, (string) $input->name, (string) $input->value, 'string', 'input');
}
$yaml['tests'][(string) $test->testcase] = array();
foreach ($test->expected as $prt) {
$expect['score'] = self::processvalue((string) $prt->expectedscore, 'float');
$expect['penalty'] = self::processvalue((string) $prt->expectedpenalty, 'float');
$expect['answer_note'] = self::processvalue((string) $prt->expectedanswernote, 'string');
$expect = array();
$this->property($expect, 'score', $prt->expectedscore, 'float', 'tests');
$this->property($expect, 'penalty', $prt->expectedpenalty, 'float', 'tests');
$this->property($expect, 'answer_note', $prt->expectedanswernote, 'string', 'tests');
$res[(string) $prt->name] = $expect;
}
$yaml['tests'][(string) $test->testcase] = $res;
......
......@@ -73,6 +73,8 @@ class qtype_stack_api_yaml_defaults {
$this->defaults['prt_correct_html'] = $settings->prtcorrect;
$this->defaults['prt_partially_correct_html'] = $settings->prtincorrect;
$this->defaults['prt_incorrect_html'] = $settings->prtpartiallycorrect;
$this->defaults['tests'] = '';
}
private function get_root($section) {
......
......@@ -90,12 +90,12 @@ $settings = get_config('qtype_stack');
$defaults->moodle_settings_to_yaml_defaults($settings);
$export = new qtype_stack_api_export($content, $defaults);
$yaml_string = $export->yaml();
$yamlstring = $export->yaml();
$rows = substr_count($yaml_string, "\n")+3;
$rows = substr_count($yamlstring, "\n") + 3;
echo "<form method = 'post' action = 'exportone.php'>";
echo "<textarea name = 'yaml' cols = '200' rows = '$rows'>";
echo $yaml_string;
echo $yamlstring;
echo "</textarea>\n";
echo "</form>\n\n";
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment