Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved constant definitions out of function, so they are not run repea…

…tedly giving lots of warnings.
  • Loading branch information...
commit 2605a5ba8f7f826d8f898b90c83d84314a313c31 1 parent 1aa43ea
tjhunt authored
Showing with 51 additions and 52 deletions.
  1. +51 −52 question/type/multianswer/questiontype.php
View
103 question/type/multianswer/questiontype.php
@@ -592,6 +592,57 @@ function restore_recode_answer($state, $restore) {
//// likely to be subject for overriding.
/////////////////////////////////////////////////////////////
+// ANSWER_ALTERNATIVE regexes
+define("ANSWER_ALTERNATIVE_FRACTION_REGEX",
+ '=|%(-?[0-9]+)%');
+// for the syntax '(?<!' see http://www.perl.com/doc/manual/html/pod/perlre.html#item_C
+define("ANSWER_ALTERNATIVE_ANSWER_REGEX",
+ '.+?(?<!\\\\|&)(?=[~#}]|$)');
+ //'[^~#}]+');
+define("ANSWER_ALTERNATIVE_FEEDBACK_REGEX",
+ '.*?(?<!\\\\)(?=[~}]|$)');
+ //'[//^~}]*');
+define("ANSWER_ALTERNATIVE_REGEX",
+ '(' . ANSWER_ALTERNATIVE_FRACTION_REGEX .')?'
+ . '(' . ANSWER_ALTERNATIVE_ANSWER_REGEX . ')'
+ . '(#(' . ANSWER_ALTERNATIVE_FEEDBACK_REGEX .'))?');
+
+// Parenthesis positions for ANSWER_ALTERNATIVE_REGEX
+define("ANSWER_ALTERNATIVE_REGEX_PERCENTILE_FRACTION", 2);
+define("ANSWER_ALTERNATIVE_REGEX_FRACTION", 1);
+define("ANSWER_ALTERNATIVE_REGEX_ANSWER", 3);
+define("ANSWER_ALTERNATIVE_REGEX_FEEDBACK", 5);
+
+// NUMBER_FORMATED_ALTERNATIVE_ANSWER_REGEX is used
+// for identifying numerical answers in ANSWER_ALTERNATIVE_REGEX_ANSWER
+define("NUMBER_REGEX",
+ '-?(([0-9]+[.,]?[0-9]*|[.,][0-9]+)([eE][-+]?[0-9]+)?)');
+define("NUMERICAL_ALTERNATIVE_REGEX",
+ '^(' . NUMBER_REGEX . ')(:' . NUMBER_REGEX . ')?$');
+
+// Parenthesis positions for NUMERICAL_FORMATED_ALTERNATIVE_ANSWER_REGEX
+define("NUMERICAL_CORRECT_ANSWER", 1);
+define("NUMERICAL_ABS_ERROR_MARGIN", 6);
+
+// Remaining ANSWER regexes
+define("ANSWER_TYPE_DEF_REGEX",
+ '(NUMERICAL|NM)|(MULTICHOICE|MC)|(SHORTANSWER|SA|MW)');
+define("ANSWER_START_REGEX",
+ '\{([0-9]*):(' . ANSWER_TYPE_DEF_REGEX . '):');
+
+define("ANSWER_REGEX",
+ ANSWER_START_REGEX
+ . '(' . ANSWER_ALTERNATIVE_REGEX
+ . '(~'
+ . ANSWER_ALTERNATIVE_REGEX
+ . ')*)\}' );
+
+// Parenthesis positions for singulars in ANSWER_REGEX
+define("ANSWER_REGEX_NORM", 1);
+define("ANSWER_REGEX_ANSWER_TYPE_NUMERICAL", 3);
+define("ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE", 4);
+define("ANSWER_REGEX_ANSWER_TYPE_SHORTANSWER", 5);
+define("ANSWER_REGEX_ALTERNATIVES", 6);
function qtype_multianswer_extract_question($text) {
@@ -626,58 +677,6 @@ function qtype_multianswer_extract_question($text) {
$text = preg_replace('/&amp;(.{2,9}?;)/', '&${1}', $text);
$text = stripslashes($text);
- // ANSWER_ALTERNATIVE regexes
- define("ANSWER_ALTERNATIVE_FRACTION_REGEX",
- '=|%(-?[0-9]+)%');
- // for the syntax '(?<!' see http://www.perl.com/doc/manual/html/pod/perlre.html#item_C
- define("ANSWER_ALTERNATIVE_ANSWER_REGEX",
- '.+?(?<!\\\\|&)(?=[~#}]|$)');
- //'[^~#}]+');
- define("ANSWER_ALTERNATIVE_FEEDBACK_REGEX",
- '.*?(?<!\\\\)(?=[~}]|$)');
- //'[//^~}]*');
- define("ANSWER_ALTERNATIVE_REGEX",
- '(' . ANSWER_ALTERNATIVE_FRACTION_REGEX .')?'
- . '(' . ANSWER_ALTERNATIVE_ANSWER_REGEX . ')'
- . '(#(' . ANSWER_ALTERNATIVE_FEEDBACK_REGEX .'))?');
-
- // Parenthesis positions for ANSWER_ALTERNATIVE_REGEX
- define("ANSWER_ALTERNATIVE_REGEX_PERCENTILE_FRACTION", 2);
- define("ANSWER_ALTERNATIVE_REGEX_FRACTION", 1);
- define("ANSWER_ALTERNATIVE_REGEX_ANSWER", 3);
- define("ANSWER_ALTERNATIVE_REGEX_FEEDBACK", 5);
-
- // NUMBER_FORMATED_ALTERNATIVE_ANSWER_REGEX is used
- // for identifying numerical answers in ANSWER_ALTERNATIVE_REGEX_ANSWER
- define("NUMBER_REGEX",
- '-?(([0-9]+[.,]?[0-9]*|[.,][0-9]+)([eE][-+]?[0-9]+)?)');
- define("NUMERICAL_ALTERNATIVE_REGEX",
- '^(' . NUMBER_REGEX . ')(:' . NUMBER_REGEX . ')?$');
-
- // Parenthesis positions for NUMERICAL_FORMATED_ALTERNATIVE_ANSWER_REGEX
- define("NUMERICAL_CORRECT_ANSWER", 1);
- define("NUMERICAL_ABS_ERROR_MARGIN", 6);
-
- // Remaining ANSWER regexes
- define("ANSWER_TYPE_DEF_REGEX",
- '(NUMERICAL|NM)|(MULTICHOICE|MC)|(SHORTANSWER|SA|MW)');
- define("ANSWER_START_REGEX",
- '\{([0-9]*):(' . ANSWER_TYPE_DEF_REGEX . '):');
-
- define("ANSWER_REGEX",
- ANSWER_START_REGEX
- . '(' . ANSWER_ALTERNATIVE_REGEX
- . '(~'
- . ANSWER_ALTERNATIVE_REGEX
- . ')*)\}' );
-
- // Parenthesis positions for singulars in ANSWER_REGEX
- define("ANSWER_REGEX_NORM", 1);
- define("ANSWER_REGEX_ANSWER_TYPE_NUMERICAL", 3);
- define("ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE", 4);
- define("ANSWER_REGEX_ANSWER_TYPE_SHORTANSWER", 5);
- define("ANSWER_REGEX_ALTERNATIVES", 6);
-
////////////////////////////////////////
//// Start of the actual function
////////////////////////////////////////
Please sign in to comment.
Something went wrong with that request. Please try again.