class qformat_missingword in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format/missingword/format.php \qformat_missingword
@package questionbank @subpackage importexport
Hierarchy
- class \qformat_default
- class \qformat_missingword
Expanded class hierarchy of qformat_missingword
File
- includes/
moodle/ question/ format/ missingword/ format.php, line 32
View source
class qformat_missingword extends qformat_default {
function provide_import() {
return true;
}
function readquestion($lines) {
/// Given an array of lines known to define a question in
/// this format, this function converts it into a question
/// object suitable for processing and insertion into Moodle.
$question = $this
->defaultquestion();
///$comment added by T Robb
$comment = NULL;
$text = implode(" ", $lines);
/// Find answer section
$answerstart = strpos($text, "{");
if ($answerstart === false) {
if ($this->displayerrors) {
echo "<p>{$text}<p>Could not find a {";
}
return false;
}
$answerfinish = strpos($text, "}");
if ($answerfinish === false) {
if ($this->displayerrors) {
echo "<p>{$text}<p>Could not find a }";
}
return false;
}
$answerlength = $answerfinish - $answerstart;
$answertext = substr($text, $answerstart + 1, $answerlength - 1);
/// Save the new question text
$question->questiontext = addslashes(substr_replace($text, "_____", $answerstart, $answerlength + 1));
$question->name = $question->questiontext;
/// Parse the answers
$answertext = str_replace("=", "~=", $answertext);
$answers = explode("~", $answertext);
if (isset($answers[0])) {
$answers[0] = trim($answers[0]);
}
if (empty($answers[0])) {
array_shift($answers);
}
$countanswers = count($answers);
switch ($countanswers) {
case 0:
// invalid question
if ($this->displayerrors) {
echo "<p>No answers found in {$answertext}";
}
return false;
case 1:
$question->qtype = SHORTANSWER;
$answer = trim($answers[0]);
if ($answer[0] == "=") {
$answer = substr($answer, 1);
}
$question->answer[] = addslashes($answer);
$question->fraction[] = 1;
$question->feedback[] = "";
return $question;
default:
$question->qtype = MULTICHOICE;
foreach ($answers as $key => $answer) {
$answer = trim($answer);
// Tom's addition starts here
$answeight = 0;
if (strspn($answer, "1234567890%") > 0) {
//Make sure that the percent sign is the last in the span
if (strpos($answer, "%") == strspn($answer, "1234567890%") - 1) {
$answeight0 = substr($answer, 0, strspn($answer, "1234567890%"));
$answeight = round($answeight0 / 100, 2);
$answer = substr($answer, strspn($answer, "1234567890%"));
}
}
if ($answer[0] == "=") {
$answeight = 1;
}
//remove the protective underscore for leading numbers in answers
if ($answer[0] == "_") {
$answer = substr($answer, 1);
}
$answer = trim($answer);
if (strpos($answer, "#") > 0) {
$hashpos = strpos($answer, "#");
$comment = addslashes(substr($answer, $hashpos + 1));
$answer = substr($answer, 0, $hashpos);
}
else {
$comment = " ";
}
// End of Tom's addition
if ($answer[0] == "=") {
# $question->fraction[$key] = 1;
$question->fraction[$key] = $answeight;
$answer = substr($answer, 1);
}
else {
# $question->fraction[$key] = 0;
$question->fraction[$key] = $answeight;
}
$question->answer[$key] = addslashes($answer);
$question->feedback[$key] = $comment;
}
return $question;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
property | |||
qformat_default:: |
function | Count all non-category questions in the questions array. | ||
qformat_default:: |
function | find and/or create the category described by a delimited list e.g. $course$/tom/dick/harry or tom/dick/harry | ||
qformat_default:: |
function | return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields. This should not be overridden. | ||
qformat_default:: |
function | Handle parsing error | ||
qformat_default:: |
function | Do an post-processing that may be required | ||
qformat_default:: |
function | Do any pre-processing that may be required | 1 | |
qformat_default:: |
function | Do the export For most types this should not need to be overrided | 1 | |
qformat_default:: |
function | Return the files extension appropriate for this type override if you don't want .txt | 3 | |
qformat_default:: |
function | where question specifies a moodle (text) format this performs the conversion. | ||
qformat_default:: |
function | get the category as a path (e.g., tom/dick/harry) | ||
qformat_default:: |
function | Import an image file encoded in base64 format | ||
qformat_default:: |
function | Override if any post-processing is required | 2 | |
qformat_default:: |
function | Perform any required pre-processing | 2 | |
qformat_default:: |
function | Process the file This method should not normally be overidden | 1 | |
qformat_default:: |
function | Enable any processing to be done on the content just prior to the file being saved default is to do nothing | 2 | |
qformat_default:: |
function | 4 | ||
qformat_default:: |
function | get directory into which export is going | ||
qformat_default:: |
function | Return complete file within an array, one item per line | 1 | |
qformat_default:: |
function | Parses an array of lines into an array of questions, where each item is a question object as defined by readquestion(). Questions are defined as anything between blank lines. | 9 | |
qformat_default:: |
function | set the category | ||
qformat_default:: |
function | set catfromfile | ||
qformat_default:: |
function | set cattofile | ||
qformat_default:: |
function | set contextfromfile | ||
qformat_default:: |
function | set an array of contexts. | ||
qformat_default:: |
function | set contexttofile | ||
qformat_default:: |
function | set the course class variable | ||
qformat_default:: |
function | set the filename | ||
qformat_default:: |
function | set matchgrades | ||
qformat_default:: |
function | Set the specific questions to export. Should not include questions with parents (sub questions of cloze question type). Only used for question export. | ||
qformat_default:: |
function | set the "real" filename (this is what the user typed, regardless of wha happened next) | ||
qformat_default:: |
function | set stoponerror | ||
qformat_default:: |
function | |||
qformat_default:: |
function | Provide export functionality for plugin questiontypes Do not override | ||
qformat_default:: |
function | Import for questiontype plugins Do not override. | ||
qformat_default:: |
function | convert a single question object into text output in the given format. This must be overriden | 4 | |
qformat_missingword:: |
function |
Overrides qformat_default:: |
||
qformat_missingword:: |
function |
Given the data known to define a question in
this format, this function converts it into a question
object suitable for processing and insertion into Moodle. Overrides qformat_default:: |