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

Add in the YAML to the question editing form (doesn't do anything at this point).

parent 057af0d7
Branches
No related tags found
No related merge requests found
...@@ -156,6 +156,7 @@ class qtype_stack_api_export { ...@@ -156,6 +156,7 @@ class qtype_stack_api_export {
// Process question tests. // Process question tests.
$this->processresponsetests($yaml); $this->processresponsetests($yaml);
$yaml['stackversion'] = self::processvalue($q->stackversion->text, 'int');
// Add in the deployed seeds. // Add in the deployed seeds.
foreach ($q->deployedseed as $seed) { foreach ($q->deployedseed as $seed) {
$yaml['deployedseed'][] = self::processvalue($seed, 'int'); $yaml['deployedseed'][] = self::processvalue($seed, 'int');
......
...@@ -22,13 +22,20 @@ ...@@ -22,13 +22,20 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/type/edit_question_form.php'); require_once($CFG->dirroot . '/question/type/edit_question_form.php');
require_once($CFG->dirroot . '/question/type/stack/question.php'); require_once($CFG->dirroot . '/question/type/stack/question.php');
require_once($CFG->dirroot . '/question/type/stack/questiontype.php'); require_once($CFG->dirroot . '/question/type/stack/questiontype.php');
if (function_exists('yaml_parse_file')) {
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');
}
/** /**
* Stack question editing form definition. * Stack question editing form definition.
...@@ -146,6 +153,14 @@ class qtype_stack_edit_form extends question_edit_form { ...@@ -146,6 +153,14 @@ class qtype_stack_edit_form extends question_edit_form {
$mform->addHelpButton('fixdollars', 'fixdollars', 'qtype_stack'); $mform->addHelpButton('fixdollars', 'fixdollars', 'qtype_stack');
$mform->closeHeaderBefore('fixdollars'); $mform->closeHeaderBefore('fixdollars');
if (function_exists('yaml_parse_file')) {
$yamledit = $mform->createElement('advcheckbox', 'yamledit',
stack_string('yamledit'), stack_string('yamleditlabel'),
array(), array(0, 1));
$mform->insertElementBefore($yamledit, 'fixdollars');
$mform->addHelpButton('yamledit', 'yamledit', 'qtype_stack');
}
// There is no un-closeHeaderBefore, so fake it. // There is no un-closeHeaderBefore, so fake it.
$closebeforebuttonarr = array_search('buttonar', $mform->defaultRenderer()->_stopFieldsetElements); $closebeforebuttonarr = array_search('buttonar', $mform->defaultRenderer()->_stopFieldsetElements);
if ($closebeforebuttonarr !== false) { if ($closebeforebuttonarr !== false) {
...@@ -233,6 +248,11 @@ class qtype_stack_edit_form extends question_edit_form { ...@@ -233,6 +248,11 @@ class qtype_stack_edit_form extends question_edit_form {
stack_string('questionnote'), array('rows' => 2, 'cols' => 80)); stack_string('questionnote'), array('rows' => 2, 'cols' => 80));
$mform->addHelpButton('questionnote', 'questionnote', 'qtype_stack'); $mform->addHelpButton('questionnote', 'questionnote', 'qtype_stack');
if (function_exists('yaml_parse_file')) {
$mform->addElement('textarea', 'yaml',
stack_string('yamledit'), array('rows' => 20, 'cols' => 80));
}
$mform->addElement('submit', 'verify', stack_string('verifyquestionandupdate')); $mform->addElement('submit', 'verify', stack_string('verifyquestionandupdate'));
$mform->registerNoSubmitButton('verify'); $mform->registerNoSubmitButton('verify');
...@@ -322,6 +342,7 @@ class qtype_stack_edit_form extends question_edit_form { ...@@ -322,6 +342,7 @@ class qtype_stack_edit_form extends question_edit_form {
$mform->addHelpButton('penalty', 'penalty', 'qtype_stack'); $mform->addHelpButton('penalty', 'penalty', 'qtype_stack');
$mform->setDefault('penalty', 0.1000000); $mform->setDefault('penalty', 0.1000000);
$mform->addRule('penalty', null, 'required', null, 'client'); $mform->addRule('penalty', null, 'required', null, 'client');
} }
/** /**
...@@ -554,6 +575,7 @@ class qtype_stack_edit_form extends question_edit_form { ...@@ -554,6 +575,7 @@ class qtype_stack_edit_form extends question_edit_form {
} }
public function data_preprocessing($question) { public function data_preprocessing($question) {
$question = parent::data_preprocessing($question); $question = parent::data_preprocessing($question);
$question = $this->data_preprocessing_options($question); $question = $this->data_preprocessing_options($question);
$question = $this->data_preprocessing_inputs($question); $question = $this->data_preprocessing_inputs($question);
...@@ -566,6 +588,25 @@ class qtype_stack_edit_form extends question_edit_form { ...@@ -566,6 +588,25 @@ class qtype_stack_edit_form extends question_edit_form {
$question->questiontext['text'] = self::DEFAULT_QUESTION_TEXT; $question->questiontext['text'] = self::DEFAULT_QUESTION_TEXT;
} }
if (function_exists('yaml_parse_file')) {
global $DB, $COURSE;
// Slightly mad, but we generate XML->YAML to avoid code duplication.
// This ensures all fields, including question tests, are here.
$questiondata = $DB->get_record('question', array('id' => $question->id), '*', MUST_EXIST);
get_question_options($questiondata);
$qformat = new qformat_xml();
$qformat->setCourse($COURSE);
$qformat->setQuestions(array($questiondata));
$content = $qformat->exportprocess(true);
$defaults = new qtype_stack_api_yaml_defaults(null);
$settings = get_config('qtype_stack');
$defaults->moodle_settings_to_yaml_defaults($settings);
$export = new qtype_stack_api_export($content, $defaults);
$question->yaml = $export->yaml();
}
return $question; return $question;
} }
......
...@@ -50,7 +50,6 @@ $contexts = new question_edit_contexts($context); ...@@ -50,7 +50,6 @@ $contexts = new question_edit_contexts($context);
// Check permissions. // Check permissions.
question_require_capability_on($questiondata, 'edit'); question_require_capability_on($questiondata, 'edit');
require_sesskey(); require_sesskey();
// Initialise $PAGE. // Initialise $PAGE.
$nexturl = new moodle_url('/question/type/stack/questiontestrun.php', $urlparams); $nexturl = new moodle_url('/question/type/stack/questiontestrun.php', $urlparams);
$PAGE->set_url($nexturl); // Since this script always ends in a redirect. $PAGE->set_url($nexturl); // Since this script always ends in a redirect.
......
...@@ -116,6 +116,9 @@ $string['firstnodemusthavelowestnumber'] = 'The first node must have the lowest ...@@ -116,6 +116,9 @@ $string['firstnodemusthavelowestnumber'] = 'The first node must have the lowest
$string['fixdollars'] = 'Fix dollars'; $string['fixdollars'] = 'Fix dollars';
$string['fixdollarslabel'] = 'Replace <code>$...$</code> with <code>\(...\)</code>, <code>$$...$$</code> with <code>\[...\]</code> and <code>@...@</code> with <code>{@...@}</code> on save.'; $string['fixdollarslabel'] = 'Replace <code>$...$</code> with <code>\(...\)</code>, <code>$$...$$</code> with <code>\[...\]</code> and <code>@...@</code> with <code>{@...@}</code> on save.';
$string['fixdollars_help'] = 'This option is useful if are copying and pasting (or typing) TeX with <code>$...$</code> and <code>$$...$$</code> delimiters. Those delimiters will be replaced by the recommended delimiters during the save process.'; $string['fixdollars_help'] = 'This option is useful if are copying and pasting (or typing) TeX with <code>$...$</code> and <code>$$...$$</code> delimiters. Those delimiters will be replaced by the recommended delimiters during the save process.';
$string['yamledit'] = 'Edit YAML';
$string['yamleditlabel'] = 'STACK supports a YAML (text-based) representation of the question.';
$string['yamledit_help'] = 'This option is for advanced users who want to cut and paste parts of a question, including parts of the PRT.';
$string['forbiddendoubledollars'] = 'Please use the delimiters <code>\(...\)</code> for inline maths and <code>\[...\]</code> for display maths. <code>$...$</code> and <code>$$...$$</code> are not permitted. There is an option at the end of the form to fix this automatically.'; $string['forbiddendoubledollars'] = 'Please use the delimiters <code>\(...\)</code> for inline maths and <code>\[...\]</code> for display maths. <code>$...$</code> and <code>$$...$$</code> are not permitted. There is an option at the end of the form to fix this automatically.';
$string['forbidfloat'] = 'Forbid float'; $string['forbidfloat'] = 'Forbid float';
$string['forbidfloat_help'] = 'If set to yes, then any answer of the student which has a floating point number will be rejected as invalid.'; $string['forbidfloat_help'] = 'If set to yes, then any answer of the student which has a floating point number will be rejected as invalid.';
......
...@@ -189,6 +189,12 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -189,6 +189,12 @@ class qtype_stack_question extends question_graded_automatically_with_countback
*/ */
protected $prtresults = array(); protected $prtresults = array();
/**
* @var string The YAML representation, if known.
*/
public $yaml = null;
public $edityaml = false;
/** /**
* Make sure the cache is valid for the current response. If not, clear it. * Make sure the cache is valid for the current response. If not, clear it.
* @param bool $acceptvalid if this is true, then we will grade things even * @param bool $acceptvalid if this is true, then we will grade things even
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment