';
$html .= '
';
$html .= '
';
diff --git a/admin/report/questioninstances/index.php b/admin/report/questioninstances/index.php
index d69098280ff..24299d32a5d 100644
--- a/admin/report/questioninstances/index.php
+++ b/admin/report/questioninstances/index.php
@@ -22,8 +22,9 @@ echo $OUTPUT->header();
add_to_log(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype);
// Prepare the list of capabilities to choose from
+$qtypes = question_bank::get_all_qtypes();
$qtypechoices = array();
-foreach ($QTYPES as $qtype) {
+foreach ($qtypes as $qtype) {
$qtypechoices[$qtype->name()] = $qtype->local_name();
}
@@ -45,7 +46,7 @@ if ($requestedqtype) {
// Work out the bits needed for the SQL WHERE clauses.
if ($requestedqtype == 'missingtype') {
- $othertypes = array_keys($QTYPES);
+ $othertypes = array_keys($qtypes);
$key = array_search('missingtype', $othertypes);
unset($othertypes[$key]);
list($sqlqtypetest, $params) = $DB->get_in_or_equal($othertypes, SQL_PARAMS_QM, '', false);
@@ -58,7 +59,8 @@ if ($requestedqtype) {
} else {
$sqlqtypetest = 'WHERE qtype = ?';
$params = array($requestedqtype);
- $title = get_string('reportforqtype', 'report_questioninstances', $QTYPES[$requestedqtype]->local_name());
+ $title = get_string('reportforqtype', 'report_questioninstances',
+ question_bank::get_qtype($requestedqtype)->local_name());
}
// Get the question counts, and all the context information, for each
diff --git a/lib/questionlib.php b/lib/questionlib.php
index c640da23c7e..410d1e41a0e 100644
--- a/lib/questionlib.php
+++ b/lib/questionlib.php
@@ -82,81 +82,6 @@ define("QUESTION_NUMANS_ADD", 3);
*/
define('QUESTION_PREVIEW_POPUP_OPTIONS', 'scrollbars=yes,resizable=yes,width=800,height=600');
-/**
- * @global array holding question type objects
- * @deprecated
- */
-global $QTYPES;
-$QTYPES = question_bank::get_all_qtypes();
-function question_register_questiontype() {
- // TODO kill this.
-}
-// TODO kill this.
-class default_questiontype {
- function plugin_dir() {
- return '';
- }
-}
-
-/**
- * An array of question type names translated to the user's language, suitable for use when
- * creating a drop-down menu of options.
- *
- * Long-time Moodle programmers will realise that this replaces the old $QTYPE_MENU array.
- * The array returned will only hold the names of all the question types that the user should
- * be able to create directly. Some internal question types like random questions are excluded.
- *
- * @return array an array of question type names translated to the user's language.
- */
-function question_type_menu() {
- static $menuoptions = null;
- if (is_null($menuoptions)) {
- $config = get_config('question');
- $menuoptions = array();
- foreach (question_bank::get_all_qtypes() as $name => $qtype) {
- $menuname = $qtype->menu_name();
- $enabledvar = $name . '_disabled';
- if ($menuname && !isset($config->$enabledvar)) {
- $menuoptions[$name] = $menuname;
- }
- }
-
- $menuoptions = question_sort_qtype_array($menuoptions, $config);
- }
- return $menuoptions;
-}
-
-/**
- * Sort an array of question type names according to the question type sort order stored in
- * config_plugins. Entries for which there is no xxx_sortorder defined will go
- * at the end, sorted according to textlib_get_instance()->asort($inarray).
- * @param $inarray an array $qtypename => $qtype->local_name().
- * @param $config get_config('question'), if you happen to have it around, to save one DB query.
- * @return array the sorted version of $inarray.
- */
-function question_sort_qtype_array($inarray, $config = null) {
- if (is_null($config)) {
- $config = get_config('question');
- }
-
- $sortorder = array();
- foreach ($inarray as $name => $notused) {
- $sortvar = $name . '_sortorder';
- if (isset($config->$sortvar)) {
- $sortorder[$config->$sortvar] = $name;
- }
- }
-
- ksort($sortorder);
- $outarray = array();
- foreach ($sortorder as $name) {
- $outarray[$name] = $inarray[$name];
- unset($inarray[$name]);
- }
- textlib_get_instance()->asort($inarray);
- return array_merge($outarray, $inarray);
-}
-
/**
* Move one question type in a list of question types. If you try to move one element
* off of the end, nothing will change.
@@ -692,7 +617,7 @@ function question_delete_activity($cm, $feedback=true) {
* @param integer $newcategoryid the id of the category to move to.
*/
function question_move_questions_to_category($questionids, $newcategoryid) {
- global $DB, $QTYPES;
+ global $DB;
$newcontextid = $DB->get_field('question_categories', 'contextid',
array('id' => $newcategoryid));
@@ -704,8 +629,8 @@ function question_move_questions_to_category($questionids, $newcategoryid) {
WHERE q.id $questionidcondition", $params);
foreach ($questions as $question) {
if ($newcontextid != $question->contextid) {
- $QTYPES[$question->qtype]->move_files($question->id,
- $question->contextid, $newcontextid);
+ question_bank::get_qtype($question->qtype)->move_files(
+ $question->id, $question->contextid, $newcontextid);
}
}
@@ -729,12 +654,12 @@ function question_move_questions_to_category($questionids, $newcategoryid) {
* @param integer $newcontextid the new context id.
*/
function question_move_category_to_context($categoryid, $oldcontextid, $newcontextid) {
- global $DB, $QTYPES;
+ global $DB;
$questionids = $DB->get_records_menu('question',
array('category' => $categoryid), '', 'id,qtype');
foreach ($questionids as $questionid => $qtype) {
- $QTYPES[$qtype]->move_files($questionid, $oldcontextid, $newcontextid);
+ question_bank::get_qtype($qtype)->move_files($questionid, $oldcontextid, $newcontextid);
}
$subcatids = $DB->get_records_menu('question_categories',
@@ -851,12 +776,12 @@ function question_load_questions($questionids, $extrafields = '', $join = '') {
* @param boolean $loadtags load the question tags from the tags table. Optional, default false.
*/
function _tidy_question($question, $loadtags = false) {
- global $CFG, $QTYPES;
- if (!array_key_exists($question->qtype, $QTYPES)) {
- $question->qtype = 'missingtype';
- $question->questiontext = '
' . get_string('warningmissingtype', 'quiz') . '
' . $question->questiontext;
+ global $CFG;
+ if (question_bank::is_qtype_installed($question->qtype)) {
+ $question->questiontext = html_writer::tag('p', get_string('warningmissingtype',
+ 'qtype_missingtype')) . $question->questiontext;
}
- $QTYPES[$question->qtype]->get_question_options($question);
+ question_bank::get_qtype($question->qtype)->get_question_options($question);
if (isset($question->_partiallyloaded)) {
unset($question->_partiallyloaded);
}
@@ -940,9 +865,7 @@ function question_get_editing_head_contributions($question) {
* Simply calls the question type specific save_question_options() method.
*/
function save_question_options($question) {
- global $QTYPES;
-
- $QTYPES[$question->qtype]->save_question_options($question);
+ question_bank::get_qtype($question->qtype)->save_question_options($question);
}
/// CATEGORY FUNCTIONS /////////////////////////////////////////////////////////////////
diff --git a/lib/simpletest/testquestionlib.php b/lib/simpletest/testquestionlib.php
index 61e0f183985..703d5cbc4c1 100644
--- a/lib/simpletest/testquestionlib.php
+++ b/lib/simpletest/testquestionlib.php
@@ -41,22 +41,6 @@ class questionlib_test extends UnitTestCase {
public static $includecoverage = array('lib/questionlib.php');
- function test_question_sort_qtype_array() {
- $config = new stdClass();
- $config->multichoice_sortorder = '1';
- $config->calculated_sortorder = '2';
- $qtypes = array(
- 'frog' => 'toad',
- 'calculated' => 'newt',
- 'multichoice' => 'eft',
- );
- $this->assertEqual(question_sort_qtype_array($qtypes), array(
- 'multichoice' => 'eft',
- 'calculated' => 'newt',
- 'frog' => 'toad',
- ));
- }
-
function test_question_reorder_qtypes() {
$this->assertEqual(question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 't1', +1),
array(0 => 't2', 1 => 't1', 2 => 't3'));
diff --git a/question/engine/bank.php b/question/engine/bank.php
index 4a6227e8dab..c1e90606aa1 100644
--- a/question/engine/bank.php
+++ b/question/engine/bank.php
@@ -55,6 +55,15 @@ abstract class question_bank {
private static $questionconfig = null;
+ /**
+ * @param string $qtypename a question type name, e.g. 'multichoice'.
+ * @return bool whether that question type is installed in this Moodle.
+ */
+ public static function is_qtype_installed($qtypename) {
+ $plugindir = get_plugin_directory('qtype', $qtypename);
+ return $plugindir && is_readable($plugindir . '/questiontype.php');
+ }
+
/**
* Get the question type class for a particular question type.
* @param string $qtypename the question type name. For example 'multichoice' or 'shortanswer'.
@@ -131,12 +140,47 @@ abstract class question_bank {
try {
$qtypes[$plugin] = self::get_qtype($plugin);
} catch (Exception $e) {
- // TODO ingore, but reivew this later.
+ // TODO ingore, but review this later.
}
}
return $qtypes;
}
+ /**
+ * Sort an array of question types according to the order the admin set up,
+ * and then alphabetically for the rest.
+ * @param array qtype->name() => qtype->local_name().
+ * @return array sorted array.
+ */
+ public static function sort_qtype_array($qtypes, $config = null) {
+ if (is_null($config)) {
+ $config = self::get_config();
+ }
+
+ $sortorder = array();
+ $otherqtypes = array();
+ foreach ($qtypes as $name => $localname) {
+ $sortvar = $name . '_sortorder';
+ if (isset($config->$sortvar)) {
+ $sortorder[$config->$sortvar] = $name;
+ } else {
+ $otherqtypes[$name] = $localname;
+ }
+ }
+
+ ksort($sortorder);
+ textlib_get_instance()->asort($otherqtypes);
+
+ $sortedqtypes = array();
+ foreach ($sortorder as $name) {
+ $sortedqtypes[$name] = $qtypes[$name];
+ }
+ foreach ($otherqtypes as $name => $notused) {
+ $sortedqtypes[$name] = $qtypes[$name];
+ }
+ return $sortedqtypes;
+ }
+
/**
* @return array all the question types that users are allowed to create,
* sorted into the preferred order set on the admin screen.
@@ -145,29 +189,17 @@ abstract class question_bank {
$config = self::get_config();
$allqtypes = self::get_all_qtypes();
- $sortorder = array();
- $otherqtypes = array();
+ $qtypenames = array();
foreach ($allqtypes as $name => $qtype) {
- if (!self::qtype_enabled($name)) {
- unset($allqtypes[$name]);
- continue;
- }
- $sortvar = $name . '_sortorder';
- if (isset($config->$sortvar)) {
- $sortorder[$config->$sortvar] = $name;
- } else {
- $otherqtypes[$name] = $qtype->local_name();
+ if (self::qtype_enabled($name)) {
+ $qtypenames[$name] = $qtype->local_name();
}
}
- ksort($sortorder);
- textlib_get_instance()->asort($otherqtypes);
+ $qtypenames = self::sort_qtype_array($qtypenames);
$creatableqtypes = array();
- foreach ($sortorder as $name) {
- $creatableqtypes[$name] = $allqtypes[$name];
- }
- foreach ($otherqtypes as $name => $notused) {
+ foreach ($qtypenames as $name => $notused) {
$creatableqtypes[$name] = $allqtypes[$name];
}
return $creatableqtypes;
diff --git a/question/engine/simpletest/testquestionbank.php b/question/engine/simpletest/testquestionbank.php
new file mode 100644
index 00000000000..5043c3f92de
--- /dev/null
+++ b/question/engine/simpletest/testquestionbank.php
@@ -0,0 +1,62 @@
+.
+
+/**
+ * This file contains tests for the question_bank class.
+ *
+ * @package moodlecore
+ * @subpackage questionbank
+ * @copyright 2011 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+defined('MOODLE_INTERNAL') || die();
+
+require_once(dirname(__FILE__) . '/../lib.php');
+
+
+/**
+ *Unit tests for the {@link question_bank} class.
+ *
+ * @copyright 2011 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class question_bank_test extends UnitTestCase {
+
+ public function setUp() {
+ }
+
+ public function tearDown() {
+ }
+
+ function test_sort_qtype_array() {
+ $config = new stdClass();
+ $config->multichoice_sortorder = '1';
+ $config->calculated_sortorder = '2';
+ $qtypes = array(
+ 'frog' => 'toad',
+ 'calculated' => 'newt',
+ 'multichoice' => 'eft',
+ );
+ $this->assertEqual(question_bank::sort_qtype_array($qtypes, $config), array(
+ 'multichoice' => 'eft',
+ 'calculated' => 'newt',
+ 'frog' => 'toad',
+ ));
+ }
+}
\ No newline at end of file
diff --git a/question/engine/upgradefromoldqe/upgrade.php b/question/engine/upgradefromoldqe/upgrade.php
index e630b600dcb..2c708c204c9 100644
--- a/question/engine/upgradefromoldqe/upgrade.php
+++ b/question/engine/upgradefromoldqe/upgrade.php
@@ -506,7 +506,7 @@ class question_engine_upgrade_question_loader {
}
protected function load_question($questionid, $quizid) {
- global $CFG, $QTYPES;
+ global $CFG;
if ($quizid) {
$question = get_record_sql("
@@ -531,14 +531,14 @@ class question_engine_upgrade_question_loader {
unset($question->defaultgrade);
}
- if (!array_key_exists($question->qtype, $QTYPES)) {
+ $qtype = question_bank::get_qtype($question->qtype, false);
+ if ($qtype->name() === 'missingtype') {
$this->logger->log_assumption("Dealing with question id {$question->id}
that is of an unknown type {$question->qtype}.");
- $question->qtype = 'missingtype';
$question->questiontext = '
' . get_string('warningmissingtype', 'quiz') . '
' . $question->questiontext;
}
- $QTYPES[$question->qtype]->get_question_options($question);
+ $qtype->get_question_options($question);
return $question;
}
diff --git a/question/format.php b/question/format.php
index a45b2e38841..514d70581c0 100644
--- a/question/format.php
+++ b/question/format.php
@@ -273,7 +273,7 @@ class qformat_default {
* @return bool success
*/
function importprocess($category) {
- global $USER, $CFG, $DB, $OUTPUT, $QTYPES;
+ global $USER, $CFG, $DB, $OUTPUT;
$context = $category->context;
$this->importcontext = $context;
@@ -378,12 +378,14 @@ class qformat_default {
$question->id = $DB->insert_record('question', $question);
if (isset($question->questiontextfiles)) {
foreach ($question->questiontextfiles as $file) {
- $QTYPES[$question->qtype]->import_file($context, 'question', 'questiontext', $question->id, $file);
+ question_bank::get_qtype($question->qtype)->import_file(
+ $context, 'question', 'questiontext', $question->id, $file);
}
}
if (isset($question->generalfeedbackfiles)) {
foreach ($question->generalfeedbackfiles as $file) {
- $QTYPES[$question->qtype]->import_file($context, 'question', 'generalfeedback', $question->id, $file);
+ question_bank::get_qtype($question->qtype)->import_file(
+ $context, 'question', 'generalfeedback', $question->id, $file);
}
}
@@ -391,7 +393,7 @@ class qformat_default {
// Now to save all the answers and type-specific options
- $result = $QTYPES[$question->qtype]->save_question_options($question);
+ $result = question_bank::get_qtype($question->qtype)->save_question_options($question);
if (!empty($CFG->usetags) && isset($question->tags)) {
require_once($CFG->dirroot . '/tag/lib.php');
@@ -626,19 +628,13 @@ class qformat_default {
* @return string the data to append to export or false if error (or unhandled)
*/
function try_exporting_using_qtypes($name, $question, $extra=null) {
- global $QTYPES;
-
// work out the name of format in use
$formatname = substr(get_class($this), strlen('qformat_'));
$methodname = "export_to_$formatname";
- if (array_key_exists($name, $QTYPES)) {
- $qtype = $QTYPES[ $name ];
- if (method_exists($qtype, $methodname)) {
- if ($data = $qtype->$methodname($question, $this, $extra)) {
- return $data;
- }
- }
+ $qtype = question_bank::get_qtype($name, false);
+ if (method_exists($qtype, $methodname)) {
+ return $qtype->$methodname($question, $this, $extra);
}
return false;
}
diff --git a/question/format/blackboard_six/format.php b/question/format/blackboard_six/format.php
index 27911f87ccf..d875a7df7f9 100644
--- a/question/format/blackboard_six/format.php
+++ b/question/format/blackboard_six/format.php
@@ -833,11 +833,9 @@ function process_essay($quest, &$questions) {
// Process Matching Questions
//----------------------------------------
function process_matching($quest, &$questions) {
- global $QTYPES;
-
// renderedmatch is an optional plugin, so we need to check if it is defined
- if (array_key_exists('renderedmatch', $QTYPES)) {
- $question = $this->process_common( $quest );
+ if (question_bank::is_qtype_installed('renderedmatch')) {
+ $question = $this->process_common($quest);
$question->valid = true;
$question->qtype = 'renderedmatch';
diff --git a/question/format/gift/format.php b/question/format/gift/format.php
index 8e96191b23a..08436d404e1 100644
--- a/question/format/gift/format.php
+++ b/question/format/gift/format.php
@@ -619,7 +619,7 @@ class qformat_gift extends qformat_default {
}
function writequestion($question) {
- global $QTYPES, $OUTPUT;
+ global $OUTPUT;
// Start with a comment
$expout = "// question: $question->id name: $question->name\n";
@@ -747,7 +747,7 @@ class qformat_gift extends qformat_default {
} else {
$expout .= "Question type $question->qtype is not supported\n";
echo $OUTPUT->notification(get_string('nohandler', 'qformat_gift',
- $QTYPES[$question->qtype]->local_name()));
+ question_bank::get_qtype_name($question->qtype)));
}
}
diff --git a/question/format/webct/format.php b/question/format/webct/format.php
index 2897f961c5a..5fe00887da9 100644
--- a/question/format/webct/format.php
+++ b/question/format/webct/format.php
@@ -174,8 +174,6 @@ class qformat_webct extends qformat_default {
}
function readquestions ($lines) {
- global $QTYPES ;
- // $qtypecalculated = new qformat_webct_modified_calculated_qtype();
$webctnumberregex =
'[+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)((e|E|\\*10\\*\\*)([+-]?[0-9]+|\\([+-]?[0-9]+\\)))?';
@@ -344,7 +342,7 @@ class qformat_webct extends qformat_default {
case CALCULATED:
foreach ($question->answers as $answer) {
- if ($formulaerror =qtype_calculated_find_formula_errors($answer)) { //$QTYPES['calculated']->
+ if ($formulaerror = qtype_calculated_find_formula_errors($answer)) {
$warnings[] = "'$question->name': ". $formulaerror;
$QuestionOK = FALSE;
}
@@ -549,7 +547,8 @@ class qformat_webct extends qformat_default {
$question->feedback[$currentchoice] = '';
$question->correctanswerlength[$currentchoice] = 4;
- $datasetnames = $QTYPES[CALCULATED]->find_dataset_names($webct_options[1]);
+ $datasetnames = question_bank::get_qtype('calculated')->
+ find_dataset_names($webct_options[1]);
foreach ($datasetnames as $datasetname) {
$question->dataset[$datasetname] = new stdClass();
$question->dataset[$datasetname]->datasetitem = array();
diff --git a/question/format/xml/format.php b/question/format/xml/format.php
index 4e5af07bfe3..9c22c7d750d 100644
--- a/question/format/xml/format.php
+++ b/question/format/xml/format.php
@@ -1082,7 +1082,7 @@ class qformat_xml extends qformat_default {
* @return string xml segment
*/
function writequestion($question) {
- global $CFG, $QTYPES, $OUTPUT;
+ global $CFG, $OUTPUT;
$fs = get_file_storage();
$contextid = $question->contextid;
@@ -1168,7 +1168,7 @@ class qformat_xml extends qformat_default {
// not a qtype really - dummy used for category switching
break;
- case TRUEFALSE:
+ case 'truefalse':
$trueanswer = $question->options->answers[$question->options->trueanswer];
$trueanswer->answer = 'true';
$expout .= $this->write_answer($trueanswer);
@@ -1178,7 +1178,7 @@ class qformat_xml extends qformat_default {
$expout .= $this->write_answer($falseanswer);
break;
- case MULTICHOICE:
+ case 'multichoice':
$expout .= "
" . $this->get_single($question->options->single) . "\n";
$expout .= "
" . $this->get_single($question->options->shuffleanswers) . "\n";
$expout .= "
{$question->options->answernumbering}\n";
@@ -1186,12 +1186,12 @@ class qformat_xml extends qformat_default {
$expout .= $this->write_answers($question->options->answers);
break;
- case SHORTANSWER:
+ case 'shortanswer':
$expout .= "
{$question->options->usecase}\n";
$expout .= $this->write_answers($question->options->answers);
break;
- case NUMERICAL:
+ case 'numerical':
foreach ($question->options->answers as $answer) {
$expout .= $this->write_answer($answer,
"
$answer->tolerance\n");
@@ -1229,7 +1229,7 @@ class qformat_xml extends qformat_default {
}
break;
- case MATCH:
+ case 'match':
$expout .= "
" . $this->get_single($question->options->shuffleanswers) . "\n";
$expout .= $this->write_combined_feedback($question->options);
foreach ($question->options->subquestions as $subquestion) {
@@ -1244,11 +1244,11 @@ class qformat_xml extends qformat_default {
}
break;
- case DESCRIPTION:
+ case 'description':
// Nothing else to do.
break;
- case MULTIANSWER:
+ case 'multianswer':
$acount = 1;
foreach ($question->options->questions as $question) {
$thispattern = addslashes("{#".$acount."}");
@@ -1258,13 +1258,13 @@ class qformat_xml extends qformat_default {
}
break;
- case ESSAY:
+ case 'essay':
// Nothing else to do.
break;
- case CALCULATED:
- case CALCULATEDSIMPLE:
- case CALCULATEDMULTI:
+ case 'calculated':
+ case 'calculatedsimple':
+ case 'calculatedmulti':
$expout .= "
{$question->options->synchronize}\n";
$expout .= "
{$question->options->single}\n";
$expout .= "
{$question->options->answernumbering}\n";
@@ -1342,9 +1342,11 @@ class qformat_xml extends qformat_default {
$expout .= "\n";
}
}
- //The tag $question->export_process has been set so we get all the data items in the database
- // from the function $QTYPES['calculated']->get_question_options(&$question);
- // calculatedsimple defaults to calculated
+
+ // The tag $question->export_process has been set so we get all the
+ // data items in the database from the function
+ // qtype_calculated::get_question_options calculatedsimple defaults
+ // to calculated
if( isset($question->options->datasets)&&count($question->options->datasets)){// there should be
$expout .= "
\n";
foreach ($question->options->datasets as $def) {
diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php
index bd74a65b49d..e6022549420 100644
--- a/question/type/calculated/questiontype.php
+++ b/question/type/calculated/questiontype.php
@@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class question_calculated_qtype extends default_questiontype {
+class question_calculated_qtype extends question_type {
public $fileoptionsa = array(
'subdirs' => false,
@@ -2163,11 +2163,6 @@ class question_calculated_qtype extends default_questiontype {
}
//// END OF CLASS ////
-//////////////////////////////////////////////////////////////////////////
-//// INITIATION - Without this line the question type is not in use... ///
-//////////////////////////////////////////////////////////////////////////
-question_register_questiontype(new question_calculated_qtype());
-
if ( ! defined ("CALCULATEDQUESTIONMAXITEMNUMBER")) {
define("CALCULATEDQUESTIONMAXITEMNUMBER", 100);
}
diff --git a/question/type/calculatedmulti/questiontype.php b/question/type/calculatedmulti/questiontype.php
index cc6ffbbea1d..0abd637f0de 100644
--- a/question/type/calculatedmulti/questiontype.php
+++ b/question/type/calculatedmulti/questiontype.php
@@ -277,7 +277,7 @@ class question_calculatedmulti_qtype extends question_calculated_qtype {
}
function create_runtime_question($question, $form) {
- $question = default_questiontype::create_runtime_question($question, $form);
+ $question = parent::create_runtime_question($question, $form);
$question->options->answers = array();
foreach ($form->answers as $key => $answer) {
$a->answer = trim($form->answer[$key]);
@@ -621,11 +621,6 @@ class question_calculatedmulti_qtype extends question_calculated_qtype {
//// END OF CLASS ////
-//////////////////////////////////////////////////////////////////////////
-//// INITIATION - Without this line the question type is not in use... ///
-//////////////////////////////////////////////////////////////////////////
-question_register_questiontype(new question_calculatedmulti_qtype());
-
if ( ! defined ("CALCULATEDMULTI")) {
define("CALCULATEDMULTI", "calculatedmulti");
}
diff --git a/question/type/calculatedsimple/questiontype.php b/question/type/calculatedsimple/questiontype.php
index d5dce4c387a..380ed933700 100644
--- a/question/type/calculatedsimple/questiontype.php
+++ b/question/type/calculatedsimple/questiontype.php
@@ -405,11 +405,3 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
}
//// END OF CLASS ////
-//////////////////////////////////////////////////////////////////////////
-//// INITIATION - Without this line the question type is not in use... ///
-//////////////////////////////////////////////////////////////////////////
-question_register_questiontype(new question_calculatedsimple_qtype());
-
-if ( ! defined ("CALCULATEDSIMPLE")) {
- define("CALCULATEDSIMPLE", "calculatedsimple");
-}
diff --git a/question/type/multianswer/edit_multianswer_form.php b/question/type/multianswer/edit_multianswer_form.php
index 0ca189648f4..13229fb8d75 100644
--- a/question/type/multianswer/edit_multianswer_form.php
+++ b/question/type/multianswer/edit_multianswer_form.php
@@ -80,7 +80,6 @@ class question_edit_multianswer_form extends question_edit_form {
$mform->addElement('hidden', 'reload', 1);
// $mform->addElement('hidden', 'generalfeedback','');
$mform->setType('reload', PARAM_INT);
- $question_type_names = question_type_menu();
// Remove meaningless defaultgrade field.
$mform->removeElement('defaultgrade');
@@ -156,11 +155,11 @@ class question_edit_multianswer_form extends question_edit_form {
if(isset($this->savedquestiondisplay->options->questions[$sub]->qtype) &&
$this->savedquestiondisplay->options->questions[$sub]->qtype != $this->questiondisplay->options->questions[$sub]->qtype ){
$this->qtype_change = true ;
- $storemess = " STORED QTYPE ".$question_type_names[$this->savedquestiondisplay->options->questions[$sub]->qtype]."";
+ $storemess = " STORED QTYPE ".question_bank::get_qtype_name($this->savedquestiondisplay->options->questions[$sub]->qtype)."";
}
$mform->addElement('header', 'subhdr'.$sub, get_string('questionno', 'question',
- '{#'.$sub.'}').' '.$question_type_names[$this->questiondisplay->options->questions[$sub]->qtype].$storemess);
+ '{#'.$sub.'}').' '.question_bank::get_qtype_name($this->questiondisplay->options->questions[$sub]->qtype).$storemess);
$mform->addElement('static', 'sub_'.$sub."_".'questiontext', get_string('questiondefinition','qtype_multianswer'),array('cols'=>60, 'rows'=>3));
@@ -388,7 +387,7 @@ class question_edit_multianswer_form extends question_edit_form {
$maxfraction = -1;
if(isset($this->savedquestiondisplay->options->questions[$sub]->qtype) &&
$this->savedquestiondisplay->options->questions[$sub]->qtype != $questiondisplay->options->questions[$sub]->qtype ){
- $storemess = " STORED QTYPE ".$question_type_names[$this->savedquestiondisplay->options->questions[$sub]->qtype];
+ $storemess = " STORED QTYPE ".question_bank::get_qtype_name($this->savedquestiondisplay->options->questions[$sub]->qtype);
}
foreach ( $subquestion->answer as $key=>$answer) {
$trimmedanswer = trim($answer);
diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php
index cc635b1dc65..ca2b15dac22 100644
--- a/question/type/multianswer/questiontype.php
+++ b/question/type/multianswer/questiontype.php
@@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class embedded_cloze_qtype extends default_questiontype {
+class embedded_cloze_qtype extends question_type {
function name() {
return 'multianswer';
@@ -710,12 +710,6 @@ Good luck!
}
//// END OF CLASS ////
-
-//////////////////////////////////////////////////////////////////////////
-//// INITIATION - Without this line the question type is not in use... ///
-//////////////////////////////////////////////////////////////////////////
-question_register_questiontype(new embedded_cloze_qtype());
-
/////////////////////////////////////////////////////////////
//// ADDITIONAL FUNCTIONS
//// The functions below deal exclusivly with editing
diff --git a/question/type/multichoice/db/upgrade.php b/question/type/multichoice/db/upgrade.php
index a8c1d3357d0..4b869a52798 100644
--- a/question/type/multichoice/db/upgrade.php
+++ b/question/type/multichoice/db/upgrade.php
@@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
* @param int $oldversion the version we are upgrading from.
*/
function xmldb_qtype_multichoice_upgrade($oldversion) {
- global $CFG, $DB, $QTYPES;
+ global $CFG, $DB;
$dbman = $DB->get_manager();
@@ -42,7 +42,9 @@ function xmldb_qtype_multichoice_upgrade($oldversion) {
// is doing it.
// Rename random questions to give them more helpful names.
if ($oldversion < 2008021800) {
- require_once($CFG->libdir . '/questionlib.php');
+ require_once($CFG->dirroot . '/question/type/random/questiontype.php');
+ $randomqtype = new qtype_random();
+
// Get all categories containing random questions.
$categories = $DB->get_recordset_sql("
SELECT qc.id, qc.name
@@ -55,10 +57,10 @@ function xmldb_qtype_multichoice_upgrade($oldversion) {
$where = "qtype = 'random' AND category = ? AND " .
$DB->sql_compare_text('questiontext') . " = " . $DB->sql_compare_text('?');
foreach ($categories as $cat) {
- $randomqname = $QTYPES[RANDOM]->question_name($cat, false);
+ $randomqname = $randomqtype->question_name($cat, false);
$DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));
- $randomqname = $QTYPES[RANDOM]->question_name($cat, true);
+ $randomqname = $randomqtype->question_name($cat, true);
$DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
}
diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php
index 5267ae90329..587a9c9ea09 100644
--- a/question/type/numerical/questiontype.php
+++ b/question/type/numerical/questiontype.php
@@ -1310,7 +1310,7 @@ class question_numerical_qtype extends qtype_shortanswer {
*/
function generate_test($name, $courseid = null) {
global $DB;
- list($form, $question) = default_questiontype::generate_test($name, $courseid);
+ list($form, $question) = parent::generate_test($name, $courseid);
$question->category = $form->category;
$form->questiontext = "What is 674 * 36?";
@@ -1379,8 +1379,6 @@ class question_numerical_qtype extends qtype_shortanswer {
}
}
-// INITIATION - Without this line the question type is not in use.
-question_register_questiontype(new question_numerical_qtype());
if ( ! defined ("NUMERICALQUESTIONUNITTEXTINPUTDISPLAY")) {
define("NUMERICALQUESTIONUNITTEXTINPUTDISPLAY", 0);
}
diff --git a/question/type/randomsamatch/questiontype.php b/question/type/randomsamatch/questiontype.php
index 0102215a14b..39e884afe5d 100644
--- a/question/type/randomsamatch/questiontype.php
+++ b/question/type/randomsamatch/questiontype.php
@@ -360,11 +360,3 @@ class question_randomsamatch_qtype extends qtype_match {
return 1/$question->options->choose;
}
}
-
-//// END OF CLASS ////
-
-//////////////////////////////////////////////////////////////////////////
-//// INITIATION - Without this line the question type is not in use... ///
-//////////////////////////////////////////////////////////////////////////
-question_register_questiontype(new question_randomsamatch_qtype());
-