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

Add in functionality to the main codebase to export as YAML.

parent 07a32308
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,10 @@
require_once(__DIR__.'/../../../config.php');
require_once(__DIR__ . '/api/libs/yaml.php');
require_once(__DIR__ . '/api/libs/yaml_defaults.php');
require_once(__DIR__ . '/api/libs/export.php');
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->dirroot . '/question/format/xml/format.php');
require_once(__DIR__ . '/locallib.php');
......@@ -30,6 +34,7 @@ require_once(__DIR__ . '/locallib.php');
// Get the parameters from the URL.
$questionid = required_param('questionid', PARAM_INT);
$exportformat = required_param('exportformat', PARAM_TEXT);
// Load the necessary data.
$questiondata = $DB->get_record('question', array('id' => $questionid), '*', MUST_EXIST);
......@@ -67,4 +72,21 @@ if (!$qformat->exportpreprocess()) {
if (!$content = $qformat->exportprocess(true)) {
send_file_not_found();
}
if ($exportformat == 'xml') {
// Send the xml.
send_file($content, $filename, 0, 0, true, true, $qformat->mime_type());
}
// Now add in the conversion to YAML.
$defaults = new qtype_stack_api_yaml_defaults(null);
$export = new qtype_stack_api_export($content, $defaults);
$yaml_string = $export->YAML();
$rows = substr_count($yaml_string, "\n")+3;
echo "<form method = 'post' action = 'exportone.php'>";
echo "<textarea name = 'yaml' cols = '200' rows = '$rows'>";
echo $yaml_string;
echo "</textarea>\n";
echo "</form>\n\n";
......@@ -69,9 +69,18 @@ $qbankparams['lastchanged'] = $question->id;
if ($questiondata->hidden) {
$qbankparams['showhidden'] = 1;
}
// Create some other useful links.
$yamlparams = $urlparams;
$yamlparams['exportformat'] = 'yaml';
$urlparams['exportformat'] = 'xml';
$questionbanklink = new moodle_url('/question/edit.php', $qbankparams);
$exportquestionlink = new moodle_url('/question/type/stack/exportone.php', $urlparams);
$exportquestionlink->param('sesskey', sesskey());
$yamlquestionlink = new moodle_url('/question/type/stack/exportone.php', $yamlparams);
$yamlquestionlink->param('sesskey', sesskey());
// Create the question usage we will use.
$quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context);
......@@ -402,7 +411,9 @@ echo html_writer::tag('p', html_writer::link($questionbanklink,
if ($canedit) {
echo html_writer::tag('p',
html_writer::link($exportquestionlink, stack_string('exportthisquestion')) .
stack_string('exportthisquestion') . ' ' .
html_writer::link($exportquestionlink, 'XML') . ' ' .
html_writer::link($yamlquestionlink, 'YAML') .
$OUTPUT->help_icon('exportthisquestion', 'qtype_stack'));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment