Skip to content
Browse files

CONTRIB-490 Adding support for generation of test calculated question…

… type (thanks Pierre Pichet)
  • Loading branch information...
1 parent 9af3558 commit cb41c95acee0ea95265a8e0520019ab8a51f50c8 nicolasconnault committed Jun 20, 2008
Showing with 46 additions and 47 deletions.
  1. +46 −47 question/type/calculated/questiontype.php
View
93 question/type/calculated/questiontype.php
@@ -1074,53 +1074,52 @@ function restore($old_question_id,$new_question_id,$info,$restore) {
return $status;
}
- /**
- * Runs all the code required to set up and save an essay question for testing purposes.
- * Alternate DB table prefix may be used to facilitate data deletion.
- */
- function generate_test($name, $courseid = null) {
- list($form, $question) = parent::generate_test($name, $courseid);
- $form->feedback = 1;
- $form->multiplier = array(1, 1);
- $form->shuffleanswers = 1;
- $form->noanswers = 1;
-
- $form->answers = array('{a} + {b}');
- $form->fraction = array(1);
- $form->tolerance = array(0.01);
- $form->tolerancetype = array(1);
- $form->correctanswerlength = array(2);
- $form->correctanswerformat = array(1);
- $form->questiontext = "What is {a} + {b}?";
-
- if ($courseid) {
- $course = get_record('course', 'id', $courseid);
- }
-
- $new_question = $this->save_question($question, $form, $course);
-
- $dataset_form = new stdClass();
- $dataset_form->number = array(1 => 2.4, 2 => 7.2, 3 => 6.7, 4 => 6.3);
- $dataset_form->calcmin = array(1 => 1.0, 2 => 1.0);
- $dataset_form->calcmax = array(1 => 10.0, 2 => 10.0);
- $dataset_form->calclength = array(1 => 1, 2 => 1);
- $dataset_form->calcdistribution = array(1 => 'uniform', 2 => 'uniform');
- $dataset_form->definition = array(1 => "1-$new_question->category-b",
- 2 => "1-$new_question->category-a",
- 3 => "1-$new_question->category-b",
- 4 => "1-$new_question->category-a");
- $dataset_form->itemid = array(1 => 2, 2 => 1, 3 => 0, 4 => 0);
- $dataset_form->nextpageparam = array('forceregeneration' => false);
- $dataset_form->addbutton = 1;
- $dataset_form->selectadd = 1;
- $dataset_form->selectdelete = 1;
- $dataset_form->courseid = $courseid;
- $dataset_form->cmid = 0;
-
- $this->save_dataset_items($new_question, $dataset_form);
-
- return $new_question;
- }
+/**
+ * Runs all the code required to set up and save an essay question for testing purposes.
+ * Alternate DB table prefix may be used to facilitate data deletion.
+ */
+ function generate_test($name, $courseid = null) {
+ list($form, $question) = parent::generate_test($name, $courseid);
+ $form->feedback = 1;
+ $form->multiplier = array(1, 1);
+ $form->shuffleanswers = 1;
+ $form->noanswers = 1;
+ $form->qtype ='calculated';
+ $question->qtype ='calculated';
+ $form->answers = array('{a} + {b}');
+ $form->fraction = array(1);
+ $form->tolerance = array(0.01);
+ $form->tolerancetype = array(1);
+ $form->correctanswerlength = array(2);
+ $form->correctanswerformat = array(1);
+ $form->questiontext = "What is {a} + {b}?";
+
+ if ($courseid) {
+ $course = get_record('course', 'id', $courseid);
+ }
+
+ $new_question = $this->save_question($question, $form, $course);
+
+ $dataset_form = new stdClass();
+ $dataset_form->nextpageparam["forceregeneration"]= 1;
+ $dataset_form->calcmin = array(1 => 1.0, 2 => 1.0);
+ $dataset_form->calcmax = array(1 => 10.0, 2 => 10.0);
+ $dataset_form->calclength = array(1 => 1, 2 => 1);
+ $dataset_form->number = array(1 => 5.4 , 2 => 4.9);
+ $dataset_form->itemid = array(1 => '' , 2 => '');
+ $dataset_form->calcdistribution = array(1 => 'uniform', 2 => 'uniform');
+ $dataset_form->definition = array(1 => "1-0-a",
+ 2 => "1-0-b");
+ $dataset_form->nextpageparam = array('forceregeneration' => false);
+ $dataset_form->addbutton = 1;
+ $dataset_form->selectadd = 1;
+ $dataset_form->courseid = $courseid;
+ $dataset_form->cmid = 0;
+ $dataset_form->id = $new_question->id;
+ $this->save_dataset_items($new_question, $dataset_form);
+
+ return $new_question;
+ }
}
//// END OF CLASS ////

0 comments on commit cb41c95

Please sign in to comment.
Something went wrong with that request. Please try again.