Cleanup: don't use questiontype constants within questiontypes

This commit is contained in:
gustav_delius 2006-03-22 13:51:25 +00:00
parent 26d93549f5
commit dfa47f965c
15 changed files with 49 additions and 58 deletions

View File

@ -1,7 +1,7 @@
<?php // $Id$
// Get a handle to the question type we are dealing with here
$qtypeobj = $QTYPES[CALCULATED];
$qtypeobj = $QTYPES['calculated'];
if (empty($form)) {
/****************************************************************/

View File

@ -704,10 +704,9 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype
//////////////////////////////////////////////////////////////////////////
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("CALCULATED", "10"); // already defined in questionlib.php
$QTYPES[CALCULATED]= new question_calculated_qtype();
$QTYPES['calculated']= new question_calculated_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[CALCULATED] = get_string("calculated", "quiz");
$QTYPE_MENU['calculated'] = get_string("calculated", "quiz");
function quiz_qtype_calculated_calculate_answer($formula, $individualdata,
$tolerance, $tolerancetype, $answerlength, $answerformat='1', $unit='') {
@ -718,7 +717,7 @@ function quiz_qtype_calculated_calculate_answer($formula, $individualdata,
/// Exchange formula variables with the correct values...
global $QTYPES;
$answer = $QTYPES[CALCULATED]->substitute_variables($formula, $individualdata);
$answer = $QTYPES['calculated']->substitute_variables($formula, $individualdata);
if ('1' == $answerformat) { /* Answer is to have $answerlength decimals */
/*** Adjust to the correct number of decimals ***/

View File

@ -7,7 +7,7 @@
/// QUESTION TYPE CLASS //////////////////
//
// The question type DESCRIPTION is not really a question type
// The question type 'description' is not really a question type
// and it therefore often sticks to some kind of odd behaviour
//
@ -70,8 +70,8 @@ class quiz_description_qtype extends default_questiontype {
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("DESCRIPTION", "7"); // already defined in questionlib.php
$QTYPES[DESCRIPTION]= new quiz_description_qtype();
$QTYPES['description']= new quiz_description_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[DESCRIPTION] = get_string("description", "quiz");
$QTYPE_MENU['description'] = get_string("description", "quiz");
?>

View File

@ -274,7 +274,7 @@ class question_essay_qtype extends default_questiontype {
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$cmoptions->id' AND q.id = i.question".
" AND q.id IN ($questionlist)".
" AND q.qtype = '".ESSAY."'".
" AND q.qtype = '".'essay'."'".
" ORDER BY q.name";
if (empty($attemptid)) {
@ -412,9 +412,8 @@ class question_essay_qtype extends default_questiontype {
//////////////////////////////////////////////////////////////////////////
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("ESSAY", "12"); // already defined in questionlib.php
$QTYPES[ESSAY] = new question_essay_qtype();
$QTYPES['essay'] = new question_essay_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[ESSAY] = get_string("essay", "quiz");
$QTYPE_MENU['essay'] = get_string("essay", "quiz");
?>

View File

@ -532,9 +532,8 @@ class question_match_qtype extends default_questiontype {
//////////////////////////////////////////////////////////////////////////
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("MATCH", "5"); // already defined in questionlib.php
$QTYPES[MATCH]= new question_match_qtype();
$QTYPES['match']= new question_match_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[MATCH] = get_string("match", "quiz");
$QTYPE_MENU['match'] = get_string("match", "quiz");
?>

View File

@ -9,13 +9,13 @@
if (empty($wrapped->questiontext)) {
$parsableanswerdef = '{' . $wrapped->defaultgrade . ':';
switch ($wrapped->qtype) {
case MULTICHOICE:
case 'multichoice':
$parsableanswerdef .= 'MULTICHOICE:';
break;
case SHORTANSWER:
case 'shortanswer':
$parsableanswerdef .= 'SHORTANSWER:';
break;
case NUMERICAL:
case 'numerical':
$parsableanswerdef .= 'NUMERICAL:';
break;
default:

View File

@ -7,9 +7,9 @@
///
/// The multianswer question type is special in that it
/// depends on a few other question types, i.e.
/// MULTICHOICE, SHORTANSWER and NUMERICAL.
/// 'multichoice', 'shortanswer' and 'numerical'.
/// These question types have got a few special features that
/// makes them useable by the MULTIANSWER question type
/// makes them useable by the 'multianswer' question type
///
/// QUESTION TYPE CLASS //////////////////
@ -233,7 +233,7 @@ class quiz_embedded_cloze_qtype extends default_questiontype {
if ($options->feedback) {
$chosenanswer = null;
switch ($wrapped->qtype) {
case NUMERICAL:
case 'numerical':
$testedstate = clone($state);
$testedstate->responses[''] = $response;
$raw_grade = 0;
@ -247,7 +247,7 @@ class quiz_embedded_cloze_qtype extends default_questiontype {
}
}
break;
case SHORTANSWER:
case 'shortanswer':
$testedstate = clone($state);
$testedstate->responses[''] = $response;
$teststate = clone($state);
@ -263,7 +263,7 @@ class quiz_embedded_cloze_qtype extends default_questiontype {
}
}
break;
case MULTICHOICE:
case 'multichoice':
if (isset($answers[$response])) {
$chosenanswer = clone($answers[$response]);
}
@ -307,12 +307,12 @@ class quiz_embedded_cloze_qtype extends default_questiontype {
// Print the input control
switch ($wrapped->qtype) {
case SHORTANSWER:
case NUMERICAL:
case 'shortanswer':
case 'numerical':
echo " <input $style $readonly $popup name=\"$inputname\"
type=\"text\" value=\"$response\" size=\"12\" /> ";
break;
case MULTICHOICE:
case 'multichoice':
$outputoptions = '<option></option>'; // Default empty option
foreach ($answers as $mcanswer) {
$selected = $response == $mcanswer->id
@ -555,7 +555,7 @@ class quiz_embedded_cloze_qtype extends default_questiontype {
error("Can't find the subquestion $wrappedquestionid that is used as part $seqnum in cloze question $state->question");
}
// For multichoice question we need to recode the answer
if ($answer and $wrappedquestion->qtype == MULTICHOICE) {
if ($answer and $wrappedquestion->qtype == 'multichoice') {
//The answer is an answer_id, look for it in backup_ids
if (!$ans = backup_getid($restore->backup_unique_code,"question_answers",$answer)) {
echo 'Could not recode cloze multichoice answer '.$answer.'<br />';
@ -583,15 +583,14 @@ class quiz_embedded_cloze_qtype extends default_questiontype {
//////////////////////////////////////////////////////////////////////////
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("MULTIANSWER", "9"); // already defined in questionlib.php
$QTYPES[MULTIANSWER]= new quiz_embedded_cloze_qtype();
$QTYPES['multianswer']= new quiz_embedded_cloze_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[MULTIANSWER] = get_string("multianswer", "quiz");
$QTYPE_MENU['multianswer'] = get_string("multianswer", "quiz");
/////////////////////////////////////////////////////////////
//// ADDITIONAL FUNCTIONS
//// The functions below deal exclusivly with editing
//// of questions with question type MULTIANSWER.
//// of questions with question type 'multianswer'.
//// Therefore they are kept in this file.
//// They are not in the class as they are not
//// likely to be subject for overriding.
@ -688,7 +687,7 @@ function quiz_qtype_multianswer_extract_question($text) {
////////////////////////////////////////
$question = new stdClass;
$question->qtype = MULTIANSWER;
$question->qtype = 'multianswer';
$question->questiontext = $text;
$question->options->questions = array();
$question->defaultgrade = 0; // Will be increased for each answer norm
@ -700,14 +699,14 @@ function quiz_qtype_multianswer_extract_question($text) {
$wrapped->defaultgrade = $answerregs[ANSWER_REGEX_NORM]
or $wrapped->defaultgrade = '1';
if (!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_NUMERICAL])) {
$wrapped->qtype = NUMERICAL;
$wrapped->qtype = 'numerical';
$wrapped->multiplier = array();
$wrapped->units = array();
} else if(!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_SHORTANSWER])) {
$wrapped->qtype = SHORTANSWER;
$wrapped->qtype = 'shortanswer';
$wrapped->usecase = 0;
} else if(!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE])) {
$wrapped->qtype = MULTICHOICE;
$wrapped->qtype = 'multichoice';
$wrapped->single = 1;
} else {
error("Cannot identify qtype $answerregs[2]");

View File

@ -514,9 +514,8 @@ class question_multichoice_qtype extends default_questiontype {
//////////////////////////////////////////////////////////////////////////
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("MULTICHOICE", "3"); // already defined in questionlib.php
$QTYPES[MULTICHOICE]= new question_multichoice_qtype();
$QTYPES['multichoice']= new question_multichoice_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[MULTICHOICE] = get_string("multichoice", "quiz");
$QTYPE_MENU['multichoice'] = get_string("multichoice", "quiz");
?>

View File

@ -497,9 +497,8 @@ class question_numerical_qtype extends question_shortanswer_qtype {
//////////////////////////////////////////////////////////////////////////
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("NUMERICAL", "8"); // already defined in questionlib.php
$QTYPES[NUMERICAL]= new question_numerical_qtype();
$QTYPES['numerical']= new question_numerical_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[NUMERICAL] = get_string("numerical", "quiz");
$QTYPE_MENU['numerical'] = get_string("numerical", "quiz");
?>

View File

@ -195,7 +195,7 @@ class default_questiontype {
*
* This function returns the number of question numbers to be assigned
* to the question. Most question types will have length one; they will be
* assigned one number. The DESCRIPTION type, however does not use up a
* assigned one number. The 'description' type, however does not use up a
* number and so has a length of zero. Other question types may wish to
* handle a bundle of questions and hence return a number greater than one.
* @return integer The number of question numbers which should be

View File

@ -7,7 +7,7 @@
/// QUESTION TYPE CLASS //////////////////
class quiz_random_qtype extends default_questiontype {
var $excludedtypes = array(RANDOM, RANDOMSAMATCH, ESSAY, DESCRIPTION);
var $excludedtypes = array('random', 'randomsamatch', 'essay', 'description');
// Carries questions available as randoms sorted by category
// This array is used when needed only
@ -87,7 +87,7 @@ class quiz_random_qtype extends default_questiontype {
}
$question->questiontext = '<span class="notifyproblem">'.
get_string('toomanyrandom', 'quiz'). '</span>';
$question->qtype = DESCRIPTION;
$question->qtype = 'description';
$state->responses = array('' => '');
return true;
}
@ -115,7 +115,7 @@ class quiz_random_qtype extends default_questiontype {
// This is the case if there weren't enough questions available in the category.
$question->questiontext = '<span class="notifyproblem">'.
get_string('toomanyrandom', 'quiz'). '</span>';
$question->qtype = DESCRIPTION;
$question->qtype = 'description';
return true;
}
// this must be an old-style state which stores only the id for the wrapped question

View File

@ -5,7 +5,7 @@
$options->choose = "";
$options->shuffleanswers = 1;
}
$saquestions = $QTYPES[RANDOMSAMATCH]->get_sa_candidates($category->id);
$saquestions = $QTYPES['randomsamatch']->get_sa_candidates($category->id);
$numberavailable = count($saquestions);
unset($saquestions);

View File

@ -9,7 +9,7 @@
/// QUESTION TYPE CLASS //////////////////
class question_randomsamatch_qtype extends question_match_qtype {
/// Extends MATCH as there are quite a few simularities...
/// Extends 'match' as there are quite a few simularities...
function name() {
return 'randomsamatch';
@ -235,7 +235,7 @@ class question_randomsamatch_qtype extends question_match_qtype {
function get_sa_candidates($categorylist, $questionsinuse=0) {
return get_records_select('question',
"qtype = '".SHORTANSWER."' " .
"qtype = '".'shortanswer'."' " .
"AND category IN ($categorylist) " .
"AND parent = '0' " .
"AND hidden = '0'" .
@ -356,9 +356,8 @@ class question_randomsamatch_qtype extends question_match_qtype {
//////////////////////////////////////////////////////////////////////////
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("RANDOMSAMATCH", "6"); // already defined in questionlib.php
$QTYPES[RANDOMSAMATCH]= new question_randomsamatch_qtype();
$QTYPES['randomsamatch']= new question_randomsamatch_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[RANDOMSAMATCH] = get_string("randomsamatch", "quiz");
$QTYPE_MENU['randomsamatch'] = get_string("randomsamatch", "quiz");
?>

View File

@ -119,7 +119,7 @@ class question_shortanswer_qtype extends default_questiontype {
function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
global $CFG;
/// This implementation is also used by question type NUMERICAL
/// This implementation is also used by question type 'numerical'
$answers = &$question->options->answers;
$correctanswers = $this->get_correct_responses($question, $state);
$readonly = empty($options->readonly) ? '' : 'readonly="readonly"';
@ -345,9 +345,8 @@ class question_shortanswer_qtype extends default_questiontype {
//////////////////////////////////////////////////////////////////////////
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("SHORTANSWER", "1"); // already defined in questionlib.php
$QTYPES[SHORTANSWER]= new question_shortanswer_qtype();
$QTYPES['shortanswer']= new question_shortanswer_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[SHORTANSWER] = get_string("shortanswer", "quiz");
$QTYPE_MENU['shortanswer'] = get_string("shortanswer", "quiz");
?>

View File

@ -312,9 +312,8 @@ class question_truefalse_qtype extends default_questiontype {
//////////////////////////////////////////////////////////////////////////
//// INITIATION - Without this line the question type is not in use... ///
//////////////////////////////////////////////////////////////////////////
// define("TRUEFALSE", "2"); // already defined in questionlib.php
$QTYPES[TRUEFALSE]= new question_truefalse_qtype();
$QTYPES['truefalse']= new question_truefalse_qtype();
// The following adds the questiontype to the menu of types shown to teachers
$QTYPE_MENU[TRUEFALSE] = get_string("truefalse", "quiz");
$QTYPE_MENU['truefalse'] = get_string("truefalse", "quiz");
?>