Renaming constants QUIZ_ADAPTIVE and QUIZ_IGNORE_DUPRESP to QUESTION_..... and moved them to lib/questionlib.php because they are used for question-level options.
This commit is contained in:
+70
-49
@@ -1,27 +1,29 @@
|
||||
<?php // $Id$
|
||||
/**
|
||||
* Code for handling and processing questions
|
||||
*
|
||||
* This is code that is module independent, i.e., can be used by any module that
|
||||
* uses questions, like quiz, lesson, ..
|
||||
* This script also loads the questiontype classes
|
||||
* Code for handling the editing of questions is in {@link editlib.php}
|
||||
*
|
||||
* TODO: separate those functions which form part of the API
|
||||
* from the helper functions.
|
||||
*
|
||||
* @version $Id$
|
||||
* @author Martin Dougiamas and many others. This has recently been completely
|
||||
* rewritten by Alex Smith, Julian Sedding and Gustav Delius as part of
|
||||
* the Serving Mathematics project
|
||||
* {@link http://maths.york.ac.uk/serving_maths}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package question
|
||||
*/
|
||||
* Code for handling and processing questions
|
||||
*
|
||||
* This is code that is module independent, i.e., can be used by any module that
|
||||
* uses questions, like quiz, lesson, ..
|
||||
* This script also loads the questiontype classes
|
||||
* Code for handling the editing of questions is in {@link question/editlib.php}
|
||||
*
|
||||
* TODO: separate those functions which form part of the API
|
||||
* from the helper functions.
|
||||
*
|
||||
* @version $Id$
|
||||
* @author Martin Dougiamas and many others. This has recently been completely
|
||||
* rewritten by Alex Smith, Julian Sedding and Gustav Delius as part of
|
||||
* the Serving Mathematics project
|
||||
* {@link http://maths.york.ac.uk/serving_maths}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package question
|
||||
*/
|
||||
|
||||
/// CONSTANTS ///////////////////////////////////
|
||||
|
||||
/**#@+
|
||||
* The different types of events that can create question states
|
||||
*/
|
||||
* The different types of events that can create question states
|
||||
*/
|
||||
define('QUESTION_EVENTOPEN', '0'); // The state was created by Moodle
|
||||
define('QUESTION_EVENTNAVIGATE', '1'); // The responses were saved because the student navigated to another page (this is not currently used)
|
||||
define('QUESTION_EVENTSAVE', '2'); // The student has requested that the responses should be saved but not submitted or validated
|
||||
@@ -34,8 +36,8 @@ define('QUESTION_EVENTCLOSE', '8'); // The response has been submitted and t
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* The core question types
|
||||
*/
|
||||
* The core question types
|
||||
*/
|
||||
define("SHORTANSWER", "1");
|
||||
define("TRUEFALSE", "2");
|
||||
define("MULTICHOICE", "3");
|
||||
@@ -50,24 +52,50 @@ define("RQP", "11");
|
||||
define("ESSAY", "12");
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constant determines the number of answer boxes supplied in the editing
|
||||
* form for multiple choice and similar question types.
|
||||
*/
|
||||
define("QUESTION_NUMANS", "10");
|
||||
|
||||
|
||||
/**#@+
|
||||
* Option flags for ->optionflags
|
||||
* The options are read out via bitwise operation using these constants
|
||||
*/
|
||||
/**
|
||||
* Whether the questions is to be run in adaptive mode. If this is not set then
|
||||
* a question closes immediately after the first submission of responses. This
|
||||
* is how question is Moodle always worked before version 1.5
|
||||
*/
|
||||
define('QUESTION_ADAPTIVE', 1);
|
||||
|
||||
/** When processing responses the code checks that the new responses at
|
||||
* a question differ from those given on the previous submission. If
|
||||
* furthermore this flag is set to true
|
||||
* then the code goes through the whole history of responses and checks if
|
||||
* ANY of them are identical to the current response in which case the
|
||||
* current response is ignored.
|
||||
*/
|
||||
define('QUESTION_IGNORE_DUPRESP', 2);
|
||||
|
||||
/**#@-*/
|
||||
|
||||
/// QTYPES INITIATION //////////////////
|
||||
|
||||
/**
|
||||
* Array holding question type objects
|
||||
*/
|
||||
* Array holding question type objects
|
||||
*/
|
||||
global $QTYPES;
|
||||
$QTYPES = array(); // This array will be populated when the questiontype.php files are loaded
|
||||
$QTYPES = array(); // This array will be populated when the questiontype.php files are loaded below
|
||||
|
||||
/**
|
||||
* Array of question types names translated to the user's language
|
||||
*
|
||||
* The $QTYPE_MENU array holds 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.
|
||||
* The complete list of question types can be found in {@link $QTYPES}.
|
||||
*/
|
||||
* Array of question types names translated to the user's language
|
||||
*
|
||||
* The $QTYPE_MENU array holds 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.
|
||||
* The complete list of question types can be found in {@link $QTYPES}.
|
||||
*/
|
||||
$QTYPE_MENU = array(); // This array will be populated when the questiontype.php files are loaded
|
||||
|
||||
require_once("$CFG->dirroot/question/questiontypes/questiontype.php");
|
||||
@@ -91,8 +119,8 @@ foreach($qtypenames as $qtypename) {
|
||||
/// OTHER CLASSES /////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* This holds the options that are determined by the course module
|
||||
*/
|
||||
* This holds the options that are set by the course module
|
||||
*/
|
||||
class cmoptions {
|
||||
/**
|
||||
* Whether a new attempt should be based on the previous one. If true
|
||||
@@ -105,7 +133,7 @@ class cmoptions {
|
||||
* Various option flags. The flags are accessed via bitwise operations
|
||||
* using the constants defined in the CONSTANTS section above.
|
||||
*/
|
||||
var $optionflags = QUIZ_ADAPTIVE;
|
||||
var $optionflags = QUESTION_ADAPTIVE;
|
||||
|
||||
/**
|
||||
* Determines whether in the calculation of the score for a question
|
||||
@@ -142,13 +170,6 @@ class cmoptions {
|
||||
* The number of decimals to be shown when scores are printed
|
||||
*/
|
||||
var $decimalpoints = 2;
|
||||
|
||||
/**
|
||||
* Determines when a student is allowed to review. The information is read
|
||||
* out from the bits with the help of the constants defined earlier
|
||||
* We initialise this to allow the student to see everything (all bits set)
|
||||
*/
|
||||
var $review = 16777215;
|
||||
}
|
||||
|
||||
|
||||
@@ -157,12 +178,12 @@ class cmoptions {
|
||||
|
||||
|
||||
/**
|
||||
* Deletes question and all associated data from the database
|
||||
*
|
||||
* TODO: remove quiz dependence
|
||||
*
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
* Deletes question and all associated data from the database
|
||||
*
|
||||
* TODO: remove quiz dependence
|
||||
*
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
global $QTYPES;
|
||||
if (isset($QTYPES[$question->qtype])) {
|
||||
@@ -673,7 +694,7 @@ function question_process_responses(&$question, &$state, $action, $cmoptions, &$
|
||||
$question, $state, $state->last_graded)) {
|
||||
$state->event = QUESTION_EVENTDUPLICATE;
|
||||
} else {
|
||||
if ($cmoptions->optionflags & QUIZ_IGNORE_DUPRESP) {
|
||||
if ($cmoptions->optionflags & QUESTION_IGNORE_DUPRESP) {
|
||||
/* Walk back through the previous graded states looking for
|
||||
one where the responses are equivalent to the current
|
||||
responses. If such a state is found, set the current grading
|
||||
@@ -737,7 +758,7 @@ function question_isgradingevent($event) {
|
||||
* This is used by {@link question_process_responses()} to determine whether
|
||||
* to ignore the marking request for the current response. However this
|
||||
* check against all previous graded responses is only performed if
|
||||
* the QUIZ_IGNORE_DUPRESP bit in $cmoptions->optionflags is set
|
||||
* the QUESTION_IGNORE_DUPRESP bit in $cmoptions->optionflags is set
|
||||
* If the current response is a duplicate of a previously graded response then
|
||||
* $STATE->event is set to QUESTION_EVENTDUPLICATE.
|
||||
* @return boolean Indicates if a state with duplicate responses was
|
||||
|
||||
@@ -481,7 +481,7 @@
|
||||
echo "<center>\n";
|
||||
|
||||
echo "<input type=\"submit\" name=\"saveattempt\" value=\"".get_string("savenosubmit", "quiz")."\" />\n";
|
||||
if ($quiz->optionflags & QUIZ_ADAPTIVE) {
|
||||
if ($quiz->optionflags & QUESTION_ADAPTIVE) {
|
||||
echo "<input type=\"submit\" name=\"markall\" value=\"".get_string("markall", "quiz")."\" />\n";
|
||||
}
|
||||
echo "<input type=\"submit\" name=\"finishattempt\" value=\"".get_string("finishattempt", "quiz")."\" onclick=\"$onclick\" />\n";
|
||||
|
||||
@@ -235,7 +235,7 @@
|
||||
<td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
|
||||
<td>
|
||||
<?php
|
||||
choose_from_menu($yesnooptions, "adaptive", ($CFG->quiz_optionflags & QUIZ_ADAPTIVE) ? 1 : 0, "");
|
||||
choose_from_menu($yesnooptions, "adaptive", ($CFG->quiz_optionflags & QUESTION_ADAPTIVE) ? 1 : 0, "");
|
||||
helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
|
||||
@@ -14,28 +14,6 @@
|
||||
|
||||
/// CONSTANTS ///////////////////////////////////////////////////////////////////
|
||||
|
||||
/**#@+
|
||||
* Option flags for ->optionflags
|
||||
* The options are read out via bitwise operation using these constants
|
||||
*/
|
||||
/**
|
||||
* Whether the questions to be run in adaptive mode. If this is not set then
|
||||
* a question closes immediately after the first submission of responses. This
|
||||
* is how Moodle worked before version 1.5
|
||||
*/
|
||||
define('QUIZ_ADAPTIVE', 1);
|
||||
|
||||
/** When processing responses the code checks that the new responses at
|
||||
* a question differ from those given on the previous submission. If
|
||||
* furthermore $ignoredupresp (ignore duplicate responses) is set to true
|
||||
* then the code goes through the whole history of attempts and checks if
|
||||
* ANY of them are identical to the current response in which case the
|
||||
* current response is ignored.
|
||||
*/
|
||||
define('QUIZ_IGNORE_DUPRESP', 2);
|
||||
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* The different review options are stored in the bits of $quiz->review
|
||||
* These constants help to extract the options
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
'quiz_timelimit' => 0,
|
||||
'quiz_optionflags' => 1,
|
||||
'quiz_penaltyscheme' => 1,
|
||||
'quiz_adaptive' => QUIZ_ADAPTIVE,
|
||||
'QUESTION_ADAPTIVE' => QUESTION_ADAPTIVE,
|
||||
'quiz_delay1' => 0,
|
||||
'quiz_delay2' => 0,
|
||||
|
||||
|
||||
+1
-1
@@ -671,7 +671,7 @@ function quiz_process_options(&$form) {
|
||||
$review = 0;
|
||||
|
||||
if (!empty($form->adaptive)) {
|
||||
$optionflags |= QUIZ_ADAPTIVE;
|
||||
$optionflags |= QUESTION_ADAPTIVE;
|
||||
}
|
||||
|
||||
if (isset($form->responsesimmediately)) {
|
||||
|
||||
+2
-2
@@ -285,7 +285,7 @@
|
||||
<td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
|
||||
<td align="left">
|
||||
<?php
|
||||
choose_from_menu($yesnooptions, "adaptive", ($form->optionflags & QUIZ_ADAPTIVE) ? 1 : 0, "");
|
||||
choose_from_menu($yesnooptions, "adaptive", ($form->optionflags & QUESTION_ADAPTIVE) ? 1 : 0, "");
|
||||
helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
@@ -537,7 +537,7 @@
|
||||
<td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
|
||||
<td align="left">
|
||||
<?php
|
||||
choose_from_menu($yesnooptions, "adaptive", ($form->optionflags & QUIZ_ADAPTIVE) ? 1 : 0, "");
|
||||
choose_from_menu($yesnooptions, "adaptive", ($form->optionflags & QUESTION_ADAPTIVE) ? 1 : 0, "");
|
||||
helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
|
||||
@@ -457,7 +457,7 @@ class quiz_default_questiontype {
|
||||
|
||||
$grade = '';
|
||||
if ($question->maxgrade and $options->scores) {
|
||||
if ($cmoptions->optionflags & QUIZ_ADAPTIVE) {
|
||||
if ($cmoptions->optionflags & QUESTION_ADAPTIVE) {
|
||||
$grade = (!question_state_is_graded($state->last_graded)) ? '--/' : round($state->last_graded->grade, $cmoptions->decimalpoints).'/';
|
||||
}
|
||||
$grade .= $question->maxgrade;
|
||||
@@ -644,7 +644,7 @@ class quiz_default_questiontype {
|
||||
types. It prints a mark button in the case where individual marking is
|
||||
allowed. */
|
||||
|
||||
if (($cmoptions->optionflags & QUIZ_ADAPTIVE) and !$options->readonly) {
|
||||
if (($cmoptions->optionflags & QUESTION_ADAPTIVE) and !$options->readonly) {
|
||||
echo '<input type="submit" name="';
|
||||
echo $question->name_prefix;
|
||||
echo 'mark" value="';
|
||||
|
||||
@@ -345,7 +345,7 @@ class question_rqp_qtype extends quiz_default_questiontype {
|
||||
echo 'validate" value="';
|
||||
print_string('validate', 'quiz');
|
||||
echo '" /> ';
|
||||
if ($cmoptions->optionflags & QUIZ_ADAPTIVE) {
|
||||
if ($cmoptions->optionflags & QUESTION_ADAPTIVE) {
|
||||
echo '<input type="submit" name="';
|
||||
echo $question->name_prefix;
|
||||
echo 'mark" value="';
|
||||
|
||||
Reference in New Issue
Block a user