| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: format.php,v 1.6.2.2 2008/08/15 03:13:39 tjhunt Exp $ 2 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 //////////////////////////////////////////////////////////////////////////// 24 25 class qformat_aiken extends qformat_default { 26 27 function provide_import() { 28 return true; 29 } 30 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(trim($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; 45 } 46 // This will show everyline when file is being processed 47 // print("$nowline<br />"); 48 $leader = substr($nowline,0,2); 49 if (preg_match('/[A-Z][).]/',$leader)){ 50 //trim off the label and space 51 $question->answer[] = htmlspecialchars(trim(substr($nowline,2)), ENT_NOQUOTES); 52 $question->fraction[] = 0; 53 $question->feedback[] = ''; 54 continue; 55 } 56 if ($leader == "AN"){ 57 $ans = trim(substr($nowline,strpos($nowline,':') + 1)); 58 $ans = substr($ans,0,1); 59 //A becomes 0 since array starts from 0 60 $rightans = ord($ans) - ord('A'); 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 = htmlspecialchars(substr($nowline,0,50)); 70 $question->questiontext = htmlspecialchars($nowline); 71 $question->single = 1; 72 $question->feedback[] = ""; 73 } 74 } 75 } 76 return $questions; 77 } 78 79 function readquestion($lines) { 80 //this is no longer needed but might still be called by default.php 81 return; 82 } 83 } 84 85 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |