Removing some more references to quiz from import/export code

This commit is contained in:
gustav_delius
2006-03-01 07:36:09 +00:00
parent 28dad8b90a
commit f5565b6969
20 changed files with 800 additions and 787 deletions
+10
View File
@@ -913,6 +913,16 @@ function print_question(&$question, &$state, $number, $cmoptions, $options=null)
$QTYPES[$question->qtype]->print_question($question, $state, $number,
$cmoptions, $options);
}
/**
* Saves question options
*
* Simply calls the question type specific save_question_options() method.
*/
function save_question_options($question) {
global $QTYPES;
$QTYPES[$question->qtype]->save_question_options($question);
}
/**
* Gets all teacher stored answers for a given question
+6 -6
View File
@@ -2,7 +2,7 @@
/**
* Class question_category_object
*
* Used for handling changes to the quiz categories
* Used for handling changes to the question categories
*
* @version $Id$
* @author Martin Dougiamas and many others. {@link http://moodle.org}
@@ -255,7 +255,7 @@ class question_category_object {
$up = $first ? false : true;
$down = $last ? false : true;
$first = false;
$this->quiz_edit_category_row($category, $depth, $up, $down, $page);
$this->edit_question_category_row($category, $depth, $up, $down, $page);
if (isset($category->children)) {
$this->build_edit_table_body($category->children, $page, $firstcat, $lastcat, $depth + 1);
}
@@ -289,7 +289,7 @@ class question_category_object {
* @param boolean down can it be moved down?
* @param int page page number
*/
function quiz_edit_category_row($category, $depth, $up = false, $down = false, $page = 0) {
function edit_question_category_row($category, $depth, $up = false, $down = false, $page = 0) {
global $USER;
$fill = str_repeat($this->tab, $depth);
@@ -546,7 +546,7 @@ class question_category_object {
}
/**
* Gets quiz categories
* Gets question categories
*
* @param int parent - if given, restrict records to those with this parent id.
* @param string sort - [[sortfield [,sortfield]] {ASC|DESC}]
@@ -565,7 +565,7 @@ class question_category_object {
/**
* Deletes an existing quiz category
* Deletes an existing question category
*
* @param int deletecat id of category to delete
* @param int destcategoryid id of category which will inherit the orphans of deletecat
@@ -740,7 +740,7 @@ class question_category_object {
$cat->sortorder = 999;
$cat->stamp = make_unique_id_code();
if (!insert_record("question_categories", $cat)) {
error("Could not insert the new quiz category '$newcategory'", "category.php?id={$newcourse}");
error("Could not insert the new question category '$newcategory'", "category.php?id={$newcourse}");
} else {
notify(get_string("categoryadded", "quiz", $newcategory), 'green');
}
+6 -6
View File
@@ -86,27 +86,27 @@
require("format.php"); // Parent class
require("format/$format/format.php");
$classname = "quiz_format_$format";
$quiz_format = new $classname();
$classname = "qformat_$format";
$qformat = new $classname();
if (! $quiz_format->exportpreprocess($category, $course)) { // Do anything before that we need to
if (! $qformat->exportpreprocess($category, $course)) { // Do anything before that we need to
error("Error occurred during pre-processing!",
"$CFG->wwwroot/mod/quiz/export.php?category=$category->id");
}
if (! $quiz_format->exportprocess($exportfilename)) { // Process the export data
if (! $qformat->exportprocess($exportfilename)) { // Process the export data
error("Error occurred during processing!",
"$CFG->wwwroot/mod/quiz/export.php?category=$category->id");
}
if (! $quiz_format->exportpostprocess()) { // In case anything needs to be done after
if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
error("Error occurred during post-processing!",
"$CFG->wwwroot/mod/quiz/export.php?category=$category->id");
}
echo "<hr />";
// link to download the finished file
$file_ext = $quiz_format->export_file_extension();
$file_ext = $qformat->export_file_extension();
$download_str = get_string( 'download', 'quiz' );
$downloadextra_str = get_string( 'downloadextra','quiz' );
if ($CFG->slasharguments) {
+1 -1
View File
@@ -8,7 +8,7 @@
// Included by import.php and export.php
class quiz_default_format {
class qformat_default {
var $displayerrors = true;
var $category = NULL;
+1 -1
View File
@@ -12,7 +12,7 @@ For correct operation the class name must be based on the
name of the containing directory, e.g.,
directory: webct
class: class quiz_format_webct extends quiz_default_format {
class: class qformat_webct extends qformat_default {
Most of them are based on the class found in mod/quiz/format.php.
See the comments therein for more information.
+1 -1
View File
@@ -30,7 +30,7 @@
// Based on format.php, included by ../../import.php
class quiz_format_aiken extends quiz_default_format {
class qformat_aiken extends qformat_default {
function provide_import() {
return true;
+2 -2
View File
@@ -22,7 +22,7 @@
// Based on format.php, included by ../../import.php
class quiz_format_aon extends quiz_default_format {
class qformat_aon extends qformat_default {
function provide_import() {
return true;
@@ -181,7 +181,7 @@ class quiz_format_aon extends quiz_default_format {
$question->subanswers[] = addslashes($shortanswer->answer);
}
$result = quiz_save_question_options($question);
$result = save_question_options($question);
if (!empty($result->error)) {
notify("Error: $result->error");
+1 -1
View File
@@ -11,7 +11,7 @@
require_once ("$CFG->libdir/xmlize.php");
class quiz_format_blackboard extends quiz_default_format {
class qformat_blackboard extends qformat_default {
function provide_import() {
return true;
+2 -2
View File
@@ -8,7 +8,7 @@
// Based on format.php, included by ../../import.php
require_once($CFG->dirroot.'/lib/uploadlib.php');
class quiz_format_coursetestmanager extends quiz_default_format {
class qformat_coursetestmanager extends qformat_default {
function provide_import() {
return true;
@@ -248,7 +248,7 @@ class quiz_format_coursetestmanager extends quiz_default_format {
}
$this->questionids[] = $question->id;
// Now to save all the answers and type-specific options
$result = quiz_save_question_options($question);
$result = save_question_options($question);
if (!empty($result->error)) {
notify($result->error);
$this->deletedatabase($filename);
+4 -1
View File
@@ -11,6 +11,9 @@
** Support of rejoinders
**
** $Log$
** Revision 1.2 2006/03/01 07:36:08 gustav_delius
** Removing some more references to quiz from import/export code
**
** Revision 1.1 2006/02/24 15:14:04 thepurpleblob
** Moving quiz import/export files to new question area.
**
@@ -45,7 +48,7 @@ define("MULTIANSWER", "9");
define("CALCULATED", "10");
*/
class quiz_format_examview extends quiz_default_format {
class qformat_examview extends qformat_default {
var $qtypes = array('tf' => TRUEFALSE,
'mc' => MULTICHOICE,
+1 -1
View File
@@ -32,7 +32,7 @@
//////////////////////////////////////////////////////////////////////////
// Based on default.php, included by ../import.php
class quiz_format_gift extends quiz_default_format {
class qformat_gift extends qformat_default {
function provide_import() {
return true;
File diff suppressed because it is too large Load Diff
+147 -147
View File
@@ -1,147 +1,147 @@
<?php // $Id$
// Alton College, Hampshire, UK - Tom Flannaghan, Andrew Walker
// Imports learnwise multiple choice quizzes (single and multiple answers)
// currently ignores the deduct attribute for multiple answer questions
// deductions are currently simply found by dividing the award for the incorrect
// answer by the total number of options
// Based on format.php, included by ../../import.php
class quiz_format_learnwise extends quiz_default_format {
function provide_import() {
return true;
}
function readquestions($lines) {
$questions = array();
$currentquestion = array();
foreach($lines as $line) {
$line = trim($line);
$currentquestion[] = $line;
if ($question = $this->readquestion($currentquestion)) {
$questions[] = $question;
$currentquestion = array();
}
}
return $questions;
}
function readquestion($lines) {
$text = implode(' ', $lines);
$text = str_replace(array('\t','\n','\r','\''), array('','','','\\\''), $text);
$startpos = strpos($text, '<question type');
$endpos = strpos($text, '</question>');
if ($startpos === false || $endpos === false) {
return false;
}
preg_match("/<question type=[\"\']([^\"\']+)[\"\']>/i", $text, $matches);
$type = strtolower($matches[1]); // multichoice or multianswerchoice
$questiontext = $this->unhtmlentities($this->stringbetween($text, '<text>', '</text>'));
$questionhint = $this->unhtmlentities($this->stringbetween($text, '<hint>', '</hint>'));
$questionaward = $this->stringbetween($text, '<award>', '</award>');
$optionlist = $this->stringbetween($text, '<answer>', '</answer>');
$optionlist = explode('<option', $optionlist);
$n = 0;
$optionscorrect = array();
$optionstext = array();
if ($type == 'multichoice') {
foreach ($optionlist as $option) {
$correct = $this->stringbetween($option, ' correct="', '">');
$answer = $this->stringbetween($option, '">', '</option>');
$optionscorrect[$n] = $correct;
$optionstext[$n] = $this->unhtmlentities($answer);
++$n;
}
} else if ($type == 'multianswerchoice') {
$numcorrect = 0;
$totalaward = 0;
$optionsaward = array();
foreach ($optionlist as $option) {
preg_match("/correct=\"([^\"]*)\"/i", $option, $correctmatch);
preg_match("/award=\"([^\"]*)\"/i", $option, $awardmatch);
$correct = $correctmatch[1];
$award = $awardmatch[1];
if ($correct == 'yes') {
$totalaward += $award;
++$numcorrect;
}
$answer = $this->stringbetween($option, '">', '</option>');
$optionscorrect[$n] = $correct;
$optionstext[$n] = $this->unhtmlentities($answer);
$optionsaward[$n] = $award;
++$n;
}
} else {
echo "<p>I don't understand this question type (type = <strong>$type</strong>).</p>\n";
}
$question = $this->defaultquestion();
$question->qtype = MULTICHOICE;
$question->name = substr($questiontext, 0, 30);
if (strlen($questiontext) > 30) {
$question->name .= '...';
}
$question->questiontext = $questiontext;
$question->single = ($type == 'multichoice') ? 1 : 0;
$question->feedback[] = '';
$question->fraction = array();
$question->answer = array();
for ($n = 0; $n < count($optionstext); ++$n) {
if ($optionstext[$n]) {
if (!isset($numcorrect)) { // single answer
if ($optionscorrect[$n] == 'yes') {
$fraction = (int) $questionaward;
} else {
$fraction = 0;
}
} else { // mulitple answers
if ($optionscorrect[$n] == 'yes') {
$fraction = $optionsaward[$n] / $totalaward;
} else {
$fraction = -$optionsaward[$n] / count($optionstext);
}
}
$question->fraction[] = $fraction;
$question->answer[] = $optionstext[$n];
$question->feedback[] = ''; // no feedback in this type
}
}
return $question;
}
function stringbetween($text, $start, $end) {
$startpos = strpos($text, $start) + strlen($start);
$endpos = strpos($text, $end);
if ($startpos <= $endpos) {
return substr($text, $startpos, $endpos - $startpos);
}
}
function unhtmlentities($string) {
$transtable = get_html_translation_table(HTML_ENTITIES);
$transtable = array_flip($transtable);
return strtr($string, $transtable);
}
}
?>
<?php // $Id$
// Alton College, Hampshire, UK - Tom Flannaghan, Andrew Walker
// Imports learnwise multiple choice quizzes (single and multiple answers)
// currently ignores the deduct attribute for multiple answer questions
// deductions are currently simply found by dividing the award for the incorrect
// answer by the total number of options
// Based on format.php, included by ../../import.php
class qformat_learnwise extends qformat_default {
function provide_import() {
return true;
}
function readquestions($lines) {
$questions = array();
$currentquestion = array();
foreach($lines as $line) {
$line = trim($line);
$currentquestion[] = $line;
if ($question = $this->readquestion($currentquestion)) {
$questions[] = $question;
$currentquestion = array();
}
}
return $questions;
}
function readquestion($lines) {
$text = implode(' ', $lines);
$text = str_replace(array('\t','\n','\r','\''), array('','','','\\\''), $text);
$startpos = strpos($text, '<question type');
$endpos = strpos($text, '</question>');
if ($startpos === false || $endpos === false) {
return false;
}
preg_match("/<question type=[\"\']([^\"\']+)[\"\']>/i", $text, $matches);
$type = strtolower($matches[1]); // multichoice or multianswerchoice
$questiontext = $this->unhtmlentities($this->stringbetween($text, '<text>', '</text>'));
$questionhint = $this->unhtmlentities($this->stringbetween($text, '<hint>', '</hint>'));
$questionaward = $this->stringbetween($text, '<award>', '</award>');
$optionlist = $this->stringbetween($text, '<answer>', '</answer>');
$optionlist = explode('<option', $optionlist);
$n = 0;
$optionscorrect = array();
$optionstext = array();
if ($type == 'multichoice') {
foreach ($optionlist as $option) {
$correct = $this->stringbetween($option, ' correct="', '">');
$answer = $this->stringbetween($option, '">', '</option>');
$optionscorrect[$n] = $correct;
$optionstext[$n] = $this->unhtmlentities($answer);
++$n;
}
} else if ($type == 'multianswerchoice') {
$numcorrect = 0;
$totalaward = 0;
$optionsaward = array();
foreach ($optionlist as $option) {
preg_match("/correct=\"([^\"]*)\"/i", $option, $correctmatch);
preg_match("/award=\"([^\"]*)\"/i", $option, $awardmatch);
$correct = $correctmatch[1];
$award = $awardmatch[1];
if ($correct == 'yes') {
$totalaward += $award;
++$numcorrect;
}
$answer = $this->stringbetween($option, '">', '</option>');
$optionscorrect[$n] = $correct;
$optionstext[$n] = $this->unhtmlentities($answer);
$optionsaward[$n] = $award;
++$n;
}
} else {
echo "<p>I don't understand this question type (type = <strong>$type</strong>).</p>\n";
}
$question = $this->defaultquestion();
$question->qtype = MULTICHOICE;
$question->name = substr($questiontext, 0, 30);
if (strlen($questiontext) > 30) {
$question->name .= '...';
}
$question->questiontext = $questiontext;
$question->single = ($type == 'multichoice') ? 1 : 0;
$question->feedback[] = '';
$question->fraction = array();
$question->answer = array();
for ($n = 0; $n < count($optionstext); ++$n) {
if ($optionstext[$n]) {
if (!isset($numcorrect)) { // single answer
if ($optionscorrect[$n] == 'yes') {
$fraction = (int) $questionaward;
} else {
$fraction = 0;
}
} else { // mulitple answers
if ($optionscorrect[$n] == 'yes') {
$fraction = $optionsaward[$n] / $totalaward;
} else {
$fraction = -$optionsaward[$n] / count($optionstext);
}
}
$question->fraction[] = $fraction;
$question->answer[] = $optionstext[$n];
$question->feedback[] = ''; // no feedback in this type
}
}
return $question;
}
function stringbetween($text, $start, $end) {
$startpos = strpos($text, $start) + strlen($start);
$endpos = strpos($text, $end);
if ($startpos <= $endpos) {
return substr($text, $startpos, $endpos - $startpos);
}
}
function unhtmlentities($string) {
$transtable = get_html_translation_table(HTML_ENTITIES);
$transtable = array_flip($transtable);
return strtr($string, $transtable);
}
}
?>
+1 -1
View File
@@ -26,7 +26,7 @@
// Based on format.php, included by ../../import.php
class quiz_format_missingword extends quiz_default_format {
class qformat_missingword extends qformat_default {
function provide_import() {
return true;
+1 -1
View File
@@ -9,7 +9,7 @@
// Based on format.php, included by ../../import.php
class quiz_format_multianswer extends quiz_default_format {
class qformat_multianswer extends qformat_default {
function provide_import() {
return true;
+1 -1
View File
@@ -10,7 +10,7 @@ require_once("$CFG->dirroot/question/format/qti2/qt_common.php");
define('CLOZE_TRAILING_TEXT_ID', 9999999);
class quiz_format_qti2 extends quiz_default_format {
class qformat_qti2 extends qformat_default {
var $lang;
+8 -8
View File
@@ -58,7 +58,7 @@ function unhtmlentities($string){
return preg_replace ($search, $replace, $string);
}
class quiz_format_webct_modified_calculated_qtype extends quiz_calculated_qtype {
class qformat_webct_modified_calculated_qtype extends quiz_calculated_qtype {
// We need to make a modification of this qtype so that
// it will be able to save webct style calculated questions
// The difference between webct and Moodle is that webct
@@ -142,9 +142,9 @@ class quiz_format_webct_modified_calculated_qtype extends quiz_calculated_qtype
return true;
}
}
$QTYPES[CALCULATED] = new quiz_format_webct_modified_calculated_qtype();
$QTYPES[CALCULATED] = new qformat_webct_modified_calculated_qtype();
function quiz_format_webct_convert_formula($formula) {
function qformat_webct_convert_formula($formula) {
// Remove empty space, as it would cause problems otherwise:
$formula = str_replace(' ', '', $formula);
@@ -239,7 +239,7 @@ function quiz_format_webct_convert_formula($formula) {
return $formula;
}
class quiz_format_webct extends quiz_default_format {
class qformat_webct extends qformat_default {
function provide_import() {
return true;
@@ -247,7 +247,7 @@ class quiz_format_webct extends quiz_default_format {
function readquestions ($lines) {
$qtypecalculated = new quiz_format_webct_modified_calculated_qtype();
$qtypecalculated = new qformat_webct_modified_calculated_qtype();
$webctnumberregex =
'[+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)((e|E|\\*10\\*\\*)([+-]?[0-9]+|\\([+-]?[0-9]+\\)))?';
@@ -506,7 +506,7 @@ class quiz_format_webct extends quiz_default_format {
if (CALCULATED == $question->qtype && ereg(
"^:([[:lower:]].*|::.*)-(MIN|MAX|DEC|VAL([0-9]+))::?:?($webctnumberregex)", $line, $webct_options)) {
$datasetname = ereg_replace('^::', '', $webct_options[1]);
$datasetvalue = quiz_format_webct_convert_formula($webct_options[4]);
$datasetvalue = qformat_webct_convert_formula($webct_options[4]);
switch ($webct_options[2]) {
case 'MIN':
$question->datasets[$datasetname]->min = $datasetvalue;
@@ -551,7 +551,7 @@ class quiz_format_webct extends quiz_default_format {
// Answer for a CALCULATED question
++$currentchoice;
$question->answers[$currentchoice]->answer =
quiz_format_webct_convert_formula($webct_options[1]);
qformat_webct_convert_formula($webct_options[1]);
// Default settings:
$question->answers[$currentchoice]->fraction = 1.0;
@@ -595,7 +595,7 @@ class quiz_format_webct extends quiz_default_format {
if (CALCULATED == $question->qtype && eregi("^:TOL:($webctnumberregex)", $line, $webct_options)) {
// We can but hope that this always appear before the TOL property
$question->answers[$currentchoice]->tolerance =
quiz_format_webct_convert_formula($webct_options[1]);
qformat_webct_convert_formula($webct_options[1]);
continue;
}
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
// Based on default.php, included by ../import.php
class quiz_format_xhtml extends quiz_default_format {
class qformat_xhtml extends qformat_default {
function provide_export() {
return true;
+1 -1
View File
@@ -9,7 +9,7 @@
require_once( "$CFG->libdir/xmlize.php" );
class quiz_format_xml extends quiz_default_format {
class qformat_xml extends qformat_default {
function provide_import() {
return true;
+5 -5
View File
@@ -100,20 +100,20 @@
require("format.php"); // Parent class
require("format/$format/format.php");
$classname = "quiz_format_$format";
$quiz_format = new $classname();
$classname = "qformat_$format";
$qformat = new $classname();
if (! $quiz_format->importpreprocess($category,$course)) { // Do anything before that we need to
if (! $qformat->importpreprocess($category,$course)) { // Do anything before that we need to
error("Error occurred during pre-processing!",
"$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
}
if (! $quiz_format->importprocess($_FILES['newfile']['tmp_name'])) { // Process the uploaded file
if (! $qformat->importprocess($_FILES['newfile']['tmp_name'])) { // Process the uploaded file
error("Error occurred during processing!",
"$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
}
if (! $quiz_format->importpostprocess()) { // In case anything needs to be done after
if (! $qformat->importpostprocess()) { // In case anything needs to be done after
error("Error occurred during post-processing!",
"$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
}