class qformat_aiken in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format/aiken/format.php \qformat_aiken
Aiken format - a simple format for creating multiple choice questions (with only one correct choice, and no feedback).
The format looks like this:
Question text A) Choice #1 B) Choice #2 C) Choice #3 D) Choice #4 ANSWER: B
That is, + question text all one one line. + then a number of choices, one to a line. Each line must comprise a letter, then ')' or '.', then a space, then the choice text. + Then a line of the form 'ANSWER: X' to indicate the correct answer.
Be sure to word "All of the above" type choices like "All of these" in case choices are being shuffled.
Hierarchy
- class \qformat_default
- class \qformat_aiken
Expanded class hierarchy of qformat_aiken
File
- includes/
moodle/ question/ format/ aiken/ format.php, line 48
View source
class qformat_aiken extends qformat_default {
function provide_import() {
return true;
}
function readquestions($lines) {
$questions = array();
$question = $this
->defaultquestion();
$endchar = chr(13);
foreach ($lines as $line) {
$stp = strpos($line, $endchar, 0);
$newlines = explode($endchar, $line);
$foundQ = 0;
$linescount = count($newlines);
for ($i = 0; $i < $linescount; $i++) {
$nowline = addslashes(trim($newlines[$i]));
// Go through the array and build an object called $question
// When done, add $question to $questions
if (strlen($nowline) < 2) {
continue;
}
if (preg_match('/^[A-Z][).][ \\t]/', $nowline)) {
// A choice. Trim off the label and space, then save
$question->answer[] = htmlspecialchars(trim(substr($nowline, 2)), ENT_NOQUOTES);
$question->fraction[] = 0;
$question->feedback[] = '';
continue;
}
if (preg_match('/^ANSWER:/', $nowline)) {
// The line that indicates the correct answer. This question is finised.
$ans = trim(substr($nowline, strpos($nowline, ':') + 1));
$ans = substr($ans, 0, 1);
// We want to map A to 0, B to 1, etc.
$rightans = ord($ans) - ord('A');
$question->fraction[$rightans] = 1;
$questions[] = $question;
// Clear array for next question set
$question = $this
->defaultquestion();
continue;
}
else {
// Must be the first line of a new question, since no recognised prefix.
$question->qtype = MULTICHOICE;
$question->name = htmlspecialchars(substr($nowline, 0, 50));
$question->questiontext = htmlspecialchars($nowline);
$question->single = 1;
$question->feedback[] = '';
}
}
}
return $questions;
}
function readquestion($lines) {
//this is no longer needed but might still be called by default.php
return;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
qformat_aiken:: |
function |
Overrides qformat_default:: |
||
qformat_aiken:: |
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:: |
||
qformat_aiken:: |
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. Overrides qformat_default:: |
||
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 | 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 |