[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Aiken format question importer. 19 * 20 * @package qformat_aiken 21 * @copyright 2003 Tom Robb <tom@robb.net> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 29 /** 30 * Aiken format - a simple format for creating multiple choice questions (with 31 * only one correct choice, and no feedback). 32 * 33 * The format looks like this: 34 * 35 * Question text 36 * A) Choice #1 37 * B) Choice #2 38 * C) Choice #3 39 * D) Choice #4 40 * ANSWER: B 41 * 42 * That is, 43 * + question text all one one line. 44 * + then a number of choices, one to a line. Each line must comprise a letter, 45 * then ')' or '.', then a space, then the choice text. 46 * + Then a line of the form 'ANSWER: X' to indicate the correct answer. 47 * 48 * Be sure to word "All of the above" type choices like "All of these" in 49 * case choices are being shuffled. 50 * 51 * @copyright 2003 Tom Robb <tom@robb.net> 52 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 53 */ 54 class qformat_aiken extends qformat_default { 55 56 public function provide_import() { 57 return true; 58 } 59 60 public function readquestions($lines) { 61 $questions = array(); 62 $question = $this->defaultquestion(); 63 $endchar = chr(13); 64 foreach ($lines as $line) { 65 $stp = strpos($line, $endchar, 0); 66 $newlines = explode($endchar, $line); 67 $linescount = count($newlines); 68 for ($i=0; $i < $linescount; $i++) { 69 $nowline = trim($newlines[$i]); 70 // Go through the array and build an object called $question 71 // When done, add $question to $questions. 72 if (strlen($nowline) < 2) { 73 continue; 74 } 75 if (preg_match('/^[A-Z][).][ \t]/', $nowline)) { 76 // A choice. Trim off the label and space, then save. 77 $question->answer[] = $this->text_field( 78 htmlspecialchars(trim(substr($nowline, 2)), ENT_NOQUOTES)); 79 $question->fraction[] = 0; 80 $question->feedback[] = $this->text_field(''); 81 } else if (preg_match('/^ANSWER:/', $nowline)) { 82 // The line that indicates the correct answer. This question is finised. 83 $ans = trim(substr($nowline, strpos($nowline, ':') + 1)); 84 $ans = substr($ans, 0, 1); 85 // We want to map A to 0, B to 1, etc. 86 $rightans = ord($ans) - ord('A'); 87 $question->fraction[$rightans] = 1; 88 $questions[] = $question; 89 90 // Clear array for next question set. 91 $question = $this->defaultquestion(); 92 continue; 93 } else { 94 // Must be the first line of a new question, since no recognised prefix. 95 $question->qtype = 'multichoice'; 96 $question->name = $this->create_default_question_name($nowline, get_string('questionname', 'question')); 97 $question->questiontext = htmlspecialchars(trim($nowline), ENT_NOQUOTES); 98 $question->questiontextformat = FORMAT_HTML; 99 $question->generalfeedback = ''; 100 $question->generalfeedbackformat = FORMAT_HTML; 101 $question->single = 1; 102 $question->answer = array(); 103 $question->fraction = array(); 104 $question->feedback = array(); 105 $question->correctfeedback = $this->text_field(''); 106 $question->partiallycorrectfeedback = $this->text_field(''); 107 $question->incorrectfeedback = $this->text_field(''); 108 } 109 } 110 } 111 return $questions; 112 } 113 114 protected function text_field($text) { 115 return array( 116 'text' => htmlspecialchars(trim($text), ENT_NOQUOTES), 117 'format' => FORMAT_HTML, 118 'files' => array(), 119 ); 120 } 121 122 public function readquestion($lines) { 123 // This is no longer needed but might still be called by default.php. 124 return; 125 } 126 } 127 128
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |