|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 00055 class qformat_aiken extends qformat_default { 00056 00057 public function provide_import() { 00058 return true; 00059 } 00060 00061 public function readquestions($lines) { 00062 $questions = array(); 00063 $question = $this->defaultquestion(); 00064 $endchar = chr(13); 00065 foreach ($lines as $line) { 00066 $stp = strpos($line, $endchar, 0); 00067 $newlines = explode($endchar, $line); 00068 $foundQ = 0; 00069 $linescount = count($newlines); 00070 for ($i=0; $i < $linescount; $i++) { 00071 $nowline = trim($newlines[$i]); 00072 // Go through the array and build an object called $question 00073 // When done, add $question to $questions 00074 if (strlen($nowline) < 2) { 00075 continue; 00076 } 00077 if (preg_match('/^[A-Z][).][ \t]/', $nowline)) { 00078 // A choice. Trim off the label and space, then save 00079 $question->answer[] = $this->text_field( 00080 htmlspecialchars(trim(substr($nowline, 2)), ENT_NOQUOTES)); 00081 $question->fraction[] = 0; 00082 $question->feedback[] = $this->text_field(''); 00083 } else if (preg_match('/^ANSWER:/', $nowline)) { 00084 // The line that indicates the correct answer. This question is finised. 00085 $ans = trim(substr($nowline, strpos($nowline, ':') + 1)); 00086 $ans = substr($ans, 0, 1); 00087 // We want to map A to 0, B to 1, etc. 00088 $rightans = ord($ans) - ord('A'); 00089 $question->fraction[$rightans] = 1; 00090 $questions[] = $question; 00091 00092 // Clear array for next question set 00093 $question = $this->defaultquestion(); 00094 continue; 00095 } else { 00096 // Must be the first line of a new question, since no recognised prefix. 00097 $question->qtype = MULTICHOICE; 00098 $question->name = shorten_text(s($nowline), 50); 00099 $question->questiontext = htmlspecialchars(trim($nowline), ENT_NOQUOTES); 00100 $question->questiontextformat = FORMAT_HTML; 00101 $question->generalfeedback = ''; 00102 $question->generalfeedbackformat = FORMAT_HTML; 00103 $question->single = 1; 00104 $question->answer = array(); 00105 $question->fraction = array(); 00106 $question->feedback = array(); 00107 $question->correctfeedback = $this->text_field(''); 00108 $question->partiallycorrectfeedback = $this->text_field(''); 00109 $question->incorrectfeedback = $this->text_field(''); 00110 } 00111 } 00112 } 00113 return $questions; 00114 } 00115 00116 protected function text_field($text) { 00117 return array( 00118 'text' => htmlspecialchars(trim($text), ENT_NOQUOTES), 00119 'format' => FORMAT_HTML, 00120 'files' => array(), 00121 ); 00122 } 00123 00124 public function readquestion($lines) { 00125 //this is no longer needed but might still be called by default.php 00126 return; 00127 } 00128 } 00129 00130