adding some strings
[moodle-linuxchix.git] / question / format / aiken / format.php
blob1d53d6b0f7b36e8a25eb52cb089ba24cc535bddf
1 <?php // $Id$
3 ////////////////////////////////////////////////////////////////////////////
4 /// AIKEN FORMAT
5 ///
6 /// This Moodle class provides all functions necessary to import and export
7 /// one-correct-answer multiple choice questions in this format:
8 ///
9 /// Question text
10 /// A) Choice #1
11 /// B) Choice #2
12 /// C) Choice #3
13 /// D) Choice #4
14 /// ANSWER: B
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.
17 ///
18 ///Only ONE correct answer is allowed with no feedback responses.
19 ///
20 ///Be sure to reword "All of the above" type questions as "All of these" (etc.) so that choices can
21 /// be randomized
22 ///
23 ////////////////////////////////////////////////////////////////////////////
25 class qformat_aiken extends qformat_default {
27 function provide_import() {
28 return true;
31 function readquestions($lines){
32 $questions = array();
33 $question = $this->defaultquestion();
34 $endchar = chr(13);
35 foreach ($lines as $line) {
36 $stp = strpos($line,$endchar,0);
37 $newlines = explode($endchar,$line);
38 $foundQ = 0;
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) {
44 continue;
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[] = '';
54 continue;
56 if ($leader == "AN"){
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();
65 continue;
66 } else {
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[] = "";
76 return $questions;
79 function readquestion($lines) {
80 //this is no longer needed but might still be called by default.php
81 return;