You are here

class qformat_aiken in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 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

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

Namesort descending Modifiers Type Description Overrides
qformat_aiken::provide_import function Overrides qformat_default::provide_import
qformat_aiken::readquestion 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::readquestion
qformat_aiken::readquestions 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::readquestions
qformat_default::$canaccessbackupdata property
qformat_default::$category property
qformat_default::$catfromfile property
qformat_default::$cattofile property
qformat_default::$contextfromfile property
qformat_default::$contexttofile property
qformat_default::$course property
qformat_default::$displayerrors property
qformat_default::$filename property
qformat_default::$importerrors property
qformat_default::$matchgrades property
qformat_default::$questionids property
qformat_default::$questions property
qformat_default::$realfilename property
qformat_default::$stoponerror property
qformat_default::$translator property
qformat_default::count_questions function Count all non-category questions in the questions array.
qformat_default::create_category_path function find and/or create the category described by a delimited list e.g. $course$/tom/dick/harry or tom/dick/harry
qformat_default::defaultquestion 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::error function Handle parsing error
qformat_default::exportpostprocess function Do an post-processing that may be required
qformat_default::exportpreprocess function Do any pre-processing that may be required 1
qformat_default::exportprocess function Do the export For most types this should not need to be overrided 1
qformat_default::export_file_extension function Return the files extension appropriate for this type override if you don't want .txt 3
qformat_default::format_question_text function where question specifies a moodle (text) format this performs the conversion.
qformat_default::get_category_path function get the category as a path (e.g., tom/dick/harry)
qformat_default::importimagefile function Import an image file encoded in base64 format
qformat_default::importpostprocess function Override if any post-processing is required 2
qformat_default::importpreprocess function Perform any required pre-processing 2
qformat_default::importprocess function Process the file This method should not normally be overidden 1
qformat_default::presave_process 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::provide_export function 4
qformat_default::question_get_export_dir function get directory into which export is going
qformat_default::readdata function Return complete file within an array, one item per line 1
qformat_default::setCategory function set the category
qformat_default::setCatfromfile function set catfromfile
qformat_default::setCattofile function set cattofile
qformat_default::setContextfromfile function set contextfromfile
qformat_default::setContexts function set an array of contexts.
qformat_default::setContexttofile function set contexttofile
qformat_default::setCourse function set the course class variable
qformat_default::setFilename function set the filename
qformat_default::setMatchgrades function set matchgrades
qformat_default::setQuestions 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::setRealfilename function set the "real" filename (this is what the user typed, regardless of wha happened next)
qformat_default::setStoponerror function set stoponerror
qformat_default::set_can_access_backupdata function
qformat_default::try_exporting_using_qtypes function Provide export functionality for plugin questiontypes Do not override
qformat_default::try_importing_using_qtypes function Import for questiontype plugins Do not override.
qformat_default::writequestion function convert a single question object into text output in the given format. This must be overriden 4