CONTRIB-490 Added support for scripted generation of questions. Calculated type not yet supported (datasets too complicated ;)
This commit is contained in:
@@ -1582,5 +1582,29 @@ class default_questiontype {
|
||||
// There is nothing to decode
|
||||
return $state->answer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract function implemented by each question type. It runs all the code
|
||||
* required to set up and save a question of any type for testing purposes.
|
||||
* Alternate DB table prefix may be used to facilitate data deletion.
|
||||
*/
|
||||
function generate_test($name, $courseid=null) {
|
||||
$form = new stdClass();
|
||||
$form->name = $name;
|
||||
$form->questiontextformat = 1;
|
||||
$form->questiontext = 'test question, generated by script';
|
||||
$form->defaultgrade = 1;
|
||||
$form->penalty = 0.1;
|
||||
$form->generalfeedback = "Well done";
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$newcategory = question_make_default_categories(array($context));
|
||||
$form->category = $newcategory->id . ',1';
|
||||
|
||||
$question = new stdClass();
|
||||
$question->courseid = $courseid;
|
||||
$question->qtype = $this->qtype;
|
||||
return array($form, $question);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user