3 ////////////////////////////////////////////////////////////////////////////
6 /// This Moodle class provides all functions necessary to import and export
7 /// one-correct-answer multiple choice questions in this format:
15 /// (blank line next not necessary since "AN" at the beginning of a line
16 /// triggers the question input and causes input to start all over.
18 ///Only ONE correct answer is allowed with no feedback responses.
20 ///Be sure to reword "All of the above" type questions as "All of these" (etc.) so that choices can
23 ////////////////////////////////////////////////////////////////////////////
25 class qformat_aiken
extends qformat_default
{
27 function provide_import() {
31 function readquestions($lines){
33 $question = $this->defaultquestion();
35 foreach ($lines as $line) {
36 $stp = strpos($line,$endchar,0);
37 $newlines = explode($endchar,$line);
39 for ($i=0; $i < count($newlines);$i++
){
40 $nowline = addslashes($newlines[$i]);
41 ///Go through the array and build an object called $question
42 ///When done, add $question to $questions
43 if (strlen($nowline)< 2) {
46 // This will show everyline when file is being processed
47 // print("$nowline<br />");
48 $leader = substr(ltrim($nowline),0,2);
49 if (strpos(".A)B)C)D)E)F)G)H)I)J)A.B.C.D.E.F.G.H.I.J.",$leader)>0){
50 //trim off the label and space
51 $question->answer
[] = substr($nowline,3);
52 $question->fraction
[] = 0;
53 $question->feedback
[] = '';
57 $ans = trim(strstr($nowline,":"));
58 $ans = substr($ans,2,1);
59 //A becomes 0 since array starts from 0
60 $rightans = ord($ans) - 65;
61 $question->fraction
[$rightans] = 1;
62 $questions[] = $question;
63 //clear array for next question set
64 $question = $this->defaultquestion();
67 //Must be the first line since no leader
68 $question->qtype
= MULTICHOICE
;
69 $question->name
= addslashes( substr($nowline,0,50) );
70 $question->questiontext
= $nowline;
71 $question->single
= 1;
72 $question->feedback
[] = "";
79 function readquestion($lines) {
80 //this is no longer needed but might still be called by default.php