Towards removing reference to quiz module from the question code

Renaming tables:
quiz_questions -> question
quiz_states -> question_states

Renaming functions:
quiz_delete_question -> delete_question
quiz_get_question_options -> get_question_options
quiz_get_states -> get_question_states
quiz_restore_state -> restore_question_state
quiz_save_question_session -> save_question_session
quiz_state_is_graded -> question_state_is_graded
quiz_extract_responses -> question_extract_responses
quiz_regrade_question_in_attempt -> regrade_question_in_attempt
quiz_process_responses -> question_process_responses
quiz_isgradingevent -> question_isgradingevent($event)
quiz_search_for_duplicate_responses -> question_search_for_duplicate_responses
quiz_apply_penalty_and_timelimit -> question_apply_penalty_and_timelimit
quiz_print_question_icon -> print_question_icon
quiz_get_image -> get_question_image
quiz_make_name_prefix -> question_make_name_prefix
quiz_get_id_from_name_prefix -> question_get_id_from_name_prefix
quiz_new_attempt_uniqueid -> question_new_attempt_uniqueid
quiz_get_renderoptions -> question_get_renderoptions
quiz_print_quiz_question -> print_question
quiz_get_question_responses -> get_question_responses
quiz_get_question_actual_response -> get_question_actual_response
quiz_get_question_fraction_grade -> get_question_fraction_grade
quiz_get_default_category -> get_default_question_category


Renaming constants:
QUIZ_EVENT.... -> QUESTION_EVENT....
QUIZ_MAX_NUMBER_ANSWERS -> QUESTION_NUMANS
This commit is contained in:
gustav_delius 2006-02-28 09:26:00 +00:00
parent 77230a8b5a
commit 4f48fb42af
46 changed files with 473 additions and 532 deletions

View File

@ -6,6 +6,10 @@
* 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
@ -18,14 +22,14 @@
/**#@+
* The different types of events that can create question states
*/
define('QUIZ_EVENTOPEN', '0');
define('QUIZ_EVENTNAVIGATE', '1');
define('QUIZ_EVENTSAVE', '2');
define('QUIZ_EVENTGRADE', '3');
define('QUIZ_EVENTDUPLICATEGRADE', '4');
define('QUIZ_EVENTVALIDATE', '5');
define('QUIZ_EVENTCLOSE', '6');
define('QUIZ_EVENTSUBMIT', '7');
define('QUESTION_EVENTOPEN', '0');
define('QUESTION_EVENTNAVIGATE', '1');
define('QUESTION_EVENTSAVE', '2');
define('QUESTION_EVENTGRADE', '3');
define('QUESTION_EVENTDUPLICATEGRADE', '4');
define('QUESTION_EVENTVALIDATE', '5');
define('QUESTION_EVENTCLOSE', '6');
define('QUESTION_EVENTSUBMIT', '7');
/**#@-*/
/**#@+
@ -47,9 +51,7 @@ define("RQP", "11");
define("ESSAY", "12");
/**#@-*/
define("QUIZ_MAX_NUMBER_ANSWERS", "10");
define("QUIZ_CATEGORIES_SORTORDER", "999");
define("QUESTION_NUMANS", "10");
/// QTYPES INITIATION //////////////////
@ -150,23 +152,23 @@ class cmoptions {
*
* @param object $question The question being deleted
*/
function quiz_delete_question($question) {
function delete_question($question) {
global $QTYPES;
$QTYPES[$question->qtype]->delete_question($question);
delete_records("quiz_answers", "question", $question->id);
delete_records("quiz_states", "question", $question->id);
delete_records("question_states", "question", $question->id);
delete_records("question_sessions", "questionid", $question->id);
if ($newversions = get_records('quiz_question_versions', 'oldquestion', $question->id)) {
foreach ($newversions as $newversion) {
$newquestion = get_record('quiz_questions', 'id', $newversion->newquestion);
quiz_delete_question($newquestion);
delete_question($newquestion);
}
delete_records("quiz_question_versions", "oldquestion", $question->id);
}
delete_records("quiz_question_versions", "newquestion", $question->id);
if ($children = get_records('quiz_questions', 'parent', $question->id)) {
foreach ($children as $child) {
quiz_delete_question($child);
delete_question($child);
}
}
return true;
@ -182,7 +184,7 @@ function quiz_delete_question($question) {
* @param mixed $questions Either an array of question objects to be updated
* or just a single question object
*/
function quiz_get_question_options(&$questions) {
function get_question_options(&$questions) {
global $QTYPES;
if (is_array($questions)) { // deal with an array of questions
@ -191,14 +193,14 @@ function quiz_get_question_options(&$questions) {
// update each question object
foreach ($keys as $i) {
// set name prefix
$questions[$i]->name_prefix = quiz_make_name_prefix($i);
$questions[$i]->name_prefix = question_make_name_prefix($i);
if (!$QTYPES[$questions[$i]->qtype]->get_question_options($questions[$i]))
return false;
}
return true;
} else { // deal with single question
$questions->name_prefix = quiz_make_name_prefix($questions->id);
$questions->name_prefix = question_make_name_prefix($questions->id);
return $QTYPES[$questions->qtype]->get_question_options($questions);
}
}
@ -208,8 +210,8 @@ function quiz_get_question_options(&$questions) {
* or create new one.
*
* For each question the most recent session state for the current attempt
* is loaded from the quiz_states table and the question type specific data and
* responses are added by calling {@link quiz_restore_state()} which in turn
* is loaded from the question_states table and the question type specific data and
* responses are added by calling {@link restore_question_state()} which in turn
* calls {@link restore_session_and_responses()} for each question.
* If no states exist for the question instance an empty state object is
* created representing the start of a session and empty question
@ -225,7 +227,7 @@ function quiz_get_question_options(&$questions) {
* @param object $attempt The attempt for which the question sessions are
* to be restored or created.
*/
function quiz_get_states(&$questions, $cmoptions, $attempt) {
function get_question_states(&$questions, $cmoptions, $attempt) {
global $CFG, $QTYPES;
// get the question ids
@ -237,7 +239,7 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
$statefields = 'n.questionid as question, s.*, n.sumpenalty';
// Load the newest states for the questions
$sql = "SELECT $statefields".
" FROM {$CFG->prefix}quiz_states s,".
" FROM {$CFG->prefix}question_states s,".
" {$CFG->prefix}question_sessions n".
" WHERE s.id = n.newest".
" AND n.attemptid = '$attempt->uniqueid'".
@ -246,7 +248,7 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
// Load the newest graded states for the questions
$sql = "SELECT $statefields".
" FROM {$CFG->prefix}quiz_states s,".
" FROM {$CFG->prefix}question_states s,".
" {$CFG->prefix}question_sessions n".
" WHERE s.id = n.newgraded".
" AND n.attemptid = '$attempt->uniqueid'".
@ -256,9 +258,9 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
// loop through all questions and set the last_graded states
foreach ($ids as $i) {
if (isset($states[$i])) {
quiz_restore_state($questions[$i], $states[$i]);
restore_question_state($questions[$i], $states[$i]);
if (isset($gradedstates[$i])) {
quiz_restore_state($questions[$i], $gradedstates[$i]);
restore_question_state($questions[$i], $gradedstates[$i]);
$states[$i]->last_graded = $gradedstates[$i];
} else {
$states[$i]->last_graded = clone($states[$i]);
@ -273,7 +275,7 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
}
// Load the last graded state for the question
$sql = "SELECT $statefields".
" FROM {$CFG->prefix}quiz_states s,".
" FROM {$CFG->prefix}question_states s,".
" {$CFG->prefix}question_sessions n".
" WHERE s.id = n.newgraded".
" AND n.attemptid = '$lastattemptid'".
@ -281,12 +283,12 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
if (!$states[$i] = get_record_sql($sql)) {
error('Could not find state for previous attempt to build on');
}
quiz_restore_state($questions[$i], $states[$i]);
restore_question_state($questions[$i], $states[$i]);
$states[$i]->attempt = $attempt->uniqueid;
$states[$i]->question = (int) $i;
$states[$i]->seq_number = 0;
$states[$i]->timestamp = $attempt->timestart;
$states[$i]->event = ($attempt->timefinish) ? QUIZ_EVENTCLOSE : QUIZ_EVENTOPEN;
$states[$i]->event = ($attempt->timefinish) ? QUESTION_EVENTCLOSE : QUESTION_EVENTOPEN;
$states[$i]->grade = 0;
$states[$i]->raw_grade = 0;
$states[$i]->penalty = 0;
@ -302,7 +304,7 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
$states[$i]->question = (int) $i;
$states[$i]->seq_number = 0;
$states[$i]->timestamp = $attempt->timestart;
$states[$i]->event = ($attempt->timefinish) ? QUIZ_EVENTCLOSE : QUIZ_EVENTOPEN;
$states[$i]->event = ($attempt->timefinish) ? QUESTION_EVENTCLOSE : QUESTION_EVENTOPEN;
$states[$i]->grade = 0;
$states[$i]->raw_grade = 0;
$states[$i]->penalty = 0;
@ -334,7 +336,7 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
* @param object $question The question for which the state is needed
* @param object $state The state as loaded from the database
*/
function quiz_restore_state(&$question, &$state) {
function restore_question_state(&$question, &$state) {
global $QTYPES;
// initialise response to the value in the answer field
@ -343,7 +345,7 @@ function quiz_restore_state(&$question, &$state) {
// Set the changed field to false; any code which changes the
// question session must set this to true and must increment
// ->seq_number. The quiz_save_question_session
// ->seq_number. The save_question_session
// function will save the new state object to the database if the field is
// set to true.
$state->changed = false;
@ -358,7 +360,7 @@ function quiz_restore_state(&$question, &$state) {
* Saves the current state of the question session to the database
*
* The state object representing the current state of the session for the
* question is saved to the quiz_states table with ->responses[''] saved
* question is saved to the question_states table with ->responses[''] saved
* to the answer field of the database table. The information in the
* question_sessions table is updated.
* The question type specific data is then saved.
@ -368,7 +370,7 @@ function quiz_restore_state(&$question, &$state) {
* most recent responses are in ->responses. The object
* is updated to hold the new ->id.
*/
function quiz_save_question_session(&$question, &$state) {
function save_question_session(&$question, &$state) {
global $QTYPES;
// Check if the state has changed
if (!$state->changed && isset($state->id)) {
@ -380,9 +382,9 @@ function quiz_save_question_session(&$question, &$state) {
// Save the state
if (isset($state->update)) { // this ->update field is only used by the
// regrading function to force the old state record to be overwritten
update_record('quiz_states', $state);
update_record('question_states', $state);
} else {
if (!$state->id = insert_record('quiz_states', $state)) {
if (!$state->id = insert_record('question_states', $state)) {
unset($state->id);
unset($state->answer);
return false;
@ -402,7 +404,7 @@ function quiz_save_question_session(&$question, &$state) {
set_field('question_sessions', 'newest', $state->id, 'attemptid',
$state->attempt, 'questionid', $question->id);
}
if (quiz_state_is_graded($state)) {
if (question_state_is_graded($state)) {
// this is also the most recent graded state
if ($newest = get_record('question_sessions', 'attemptid',
$state->attempt, 'questionid', $question->id)) {
@ -431,27 +433,8 @@ function quiz_save_question_session(&$question, &$state) {
* @return boolean true if the state has been graded
* @param object $state
*/
function quiz_state_is_graded($state) {
return ($state->event == QUIZ_EVENTGRADE or $state->event == QUIZ_EVENTCLOSE);
}
/**
* Updates a state object for the next new state to record the fact that the
* question session has changed
*
* If the question session is not already marked as having changed (via the
* ->changed field of the state object), then this is done, the sequence
* number in ->seq_number is incremented and the timestamp in ->timestamp is
* updated. This should be called before or after any code which changes the
* question session.
* @param object $state The state object representing the state of the session.
*/
function quiz_mark_session_change(&$state) {
if (!$state->changed) {
$state->changed = true;
$state->seq_number++;
$state->timestamp = time();
}
function question_state_is_graded($state) {
return ($state->event == QUESTION_EVENTGRADE or $state->event == QUESTION_EVENTCLOSE);
}
@ -464,12 +447,12 @@ function quiz_mark_session_change(&$state) {
* @param array $responses
* @param integer $defaultevent
*/
function quiz_extract_responses($questions, $responses, $defaultevent) {
function question_extract_responses($questions, $responses, $defaultevent) {
$actions = array();
foreach ($responses as $key => $response) {
// Get the question id from the response name
if (false !== ($quid = quiz_get_id_from_name_prefix($key))) {
if (false !== ($quid = question_get_id_from_name_prefix($key))) {
// check if this is a valid id
if (!isset($questions[$quid])) {
error('Form contained question that is not in questionids');
@ -483,9 +466,9 @@ function quiz_extract_responses($questions, $responses, $defaultevent) {
}
// Check for question validate and mark buttons & set events
if ($key === 'validate') {
$actions[$quid]->event = QUIZ_EVENTVALIDATE;
$actions[$quid]->event = QUESTION_EVENTVALIDATE;
} else if ($key === 'mark') {
$actions[$quid]->event = QUIZ_EVENTGRADE;
$actions[$quid]->event = QUESTION_EVENTGRADE;
} else {
$actions[$quid]->event = $defaultevent;
}
@ -506,17 +489,18 @@ function quiz_extract_responses($questions, $responses, $defaultevent) {
* This is used when a question is changed and old student
* responses need to be marked with the new version of a question.
*
* TODO: Finish documenting this
* TODO: Make sure this is not quiz-specific
*
* @return boolean Indicates success/failure
* @param object $question A question object
* @param object $attempt The attempt, in which the question needs to be regraded.
* @param object $cmoptions
* @param boolean $verbose Optional. Whether to print progress information or not.
*/
function quiz_regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=false) {
function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=false) {
// load all states for this question in this attempt, ordered in sequence
if ($states = get_records_select('quiz_states',
if ($states = get_records_select('question_states',
"attempt = '{$attempt->uniqueid}' AND question = '{$question->id}'", 'seq_number ASC')) {
$states = array_values($states);
@ -526,33 +510,33 @@ function quiz_regrade_question_in_attempt($question, $attempt, $cmoptions, $verb
// Initialise the replaystate
$state = clone($states[0]);
quiz_restore_state($question, $state);
restore_question_state($question, $state);
$state->sumpenalty = 0.0;
$replaystate = clone($state);
$replaystate->last_graded = $state;
$changed = 0;
for($j = 1; $j < count($states); $j++) {
quiz_restore_state($question, $states[$j]);
restore_question_state($question, $states[$j]);
$action = new stdClass;
$action->responses = $states[$j]->responses;
$action->timestamp = $states[$j]->timestamp;
// Close the last state of a finished attempt
if (((count($states) - 1) === $j) && ($attempt->timefinish > 0)) {
$action->event = QUIZ_EVENTCLOSE;
$action->event = QUESTION_EVENTCLOSE;
// Grade instead of closing, quiz_process_responses will then
// Grade instead of closing, question_process_responses will then
// work out whether to close it
} else if (QUIZ_EVENTCLOSE == $states[$j]->event) {
$action->event = QUIZ_EVENTGRADE;
} else if (QUESTION_EVENTCLOSE == $states[$j]->event) {
$action->event = QUESTION_EVENTGRADE;
// By default take the event that was saved in the database
} else {
$action->event = $states[$j]->event;
}
// Reprocess (regrade) responses
if (!quiz_process_responses($question, $replaystate, $action, $cmoptions,
if (!question_process_responses($question, $replaystate, $action, $cmoptions,
$attempt)) {
$verbose && notify("Couldn't regrade state #{$state->id}!");
}
@ -565,7 +549,7 @@ function quiz_regrade_question_in_attempt($question, $attempt, $cmoptions, $verb
$replaystate->id = $states[$j]->id;
$replaystate->update = true;
quiz_save_question_session($question, $replaystate);
save_question_session($question, $replaystate);
}
if ($verbose) {
if ($changed) {
@ -591,14 +575,14 @@ function quiz_regrade_question_in_attempt($question, $attempt, $cmoptions, $verb
* @param object $state Full state object, passed by reference
* @param object $action object with the fields ->responses which
* is an array holding the student responses,
* ->action which specifies the action, e.g., QUIZ_EVENTGRADE,
* ->action which specifies the action, e.g., QUESTION_EVENTGRADE,
* and ->timestamp which is a timestamp from when the responses
* were submitted by the student.
* @param object $cmoptions
* @param object $attempt The attempt is passed by reference so that
* during grading its ->sumgrades field can be updated
*/
function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$attempt) {
function question_process_responses(&$question, &$state, $action, $cmoptions, &$attempt) {
global $QTYPES;
// if no responses are set initialise to empty response
@ -610,16 +594,16 @@ function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$atte
unset($action->responses['mark'], $action->responses['validate']);
// Check the question session is still open
if (QUIZ_EVENTCLOSE == $state->event) {
if (QUESTION_EVENTCLOSE == $state->event) {
return true;
}
// If $action->event is not set that implies saving
if (! isset($action->event)) {
$action->event = QUIZ_EVENTSAVE;
$action->event = QUESTION_EVENTSAVE;
}
// Check if we are grading the question; compare against last graded
// responses, not last given responses in this case
if (quiz_isgradingevent($action->event)) {
if (question_isgradingevent($action->event)) {
$state->responses = $state->last_graded->responses;
}
// Check for unchanged responses (exactly unchanged, not equivalent).
@ -627,8 +611,8 @@ function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$atte
$sameresponses = (($state->responses == $action->responses) or
($state->responses == array(''=>'') && array_keys(array_count_values($action->responses))===array('')));
if ($sameresponses and QUIZ_EVENTCLOSE != $action->event
and QUIZ_EVENTVALIDATE != $action->event) {
if ($sameresponses and QUESTION_EVENTCLOSE != $action->event
and QUESTION_EVENTVALIDATE != $action->event) {
return true;
}
@ -643,11 +627,11 @@ function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$atte
$state = $newstate;
// Set the event to the action we will perform. The question type specific
// grading code may override this by setting it to QUIZ_EVENTCLOSE if the
// grading code may override this by setting it to QUESTION_EVENTCLOSE if the
// attempt at the question causes the session to close
$state->event = $action->event;
if (!quiz_isgradingevent($action->event)) {
if (!question_isgradingevent($action->event)) {
// Grade the response but don't update the overall grade
$QTYPES[$question->qtype]->grade_responses(
$question, $state, $cmoptions);
@ -655,7 +639,7 @@ function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$atte
// state to close)
$state->event = $action->event;
} else if (QUIZ_EVENTGRADE == $action->event) {
} else if (QUESTION_EVENTGRADE == $action->event) {
// Work out if the current responses (or equivalent responses) were
// already given in
@ -663,25 +647,25 @@ function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$atte
// b. any other graded attempt
if($QTYPES[$question->qtype]->compare_responses(
$question, $state, $state->last_graded)) {
$state->event = QUIZ_EVENTDUPLICATEGRADE;
$state->event = QUESTION_EVENTDUPLICATEGRADE;
} else {
if ($cmoptions->optionflags & QUIZ_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
details to those of that state and set the event to
QUIZ_EVENTDUPLICATEGRADE */
quiz_search_for_duplicate_responses($question, $state);
QUESTION_EVENTDUPLICATEGRADE */
question_search_for_duplicate_responses($question, $state);
}
// If we did not find a duplicate, perform grading
if (QUIZ_EVENTDUPLICATEGRADE != $state->event) {
if (QUESTION_EVENTDUPLICATEGRADE != $state->event) {
// Decrease sumgrades by previous grade and then later add new grade
$attempt->sumgrades -= (float)$state->last_graded->grade;
$QTYPES[$question->qtype]->grade_responses(
$question, $state, $cmoptions);
// Calculate overall grade using correct penalty method
quiz_apply_penalty_and_timelimit($question, $state, $attempt, $cmoptions);
question_apply_penalty_and_timelimit($question, $state, $attempt, $cmoptions);
// Update the last graded state (don't simplify!)
unset($state->last_graded);
$state->last_graded = clone($state);
@ -690,7 +674,7 @@ function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$atte
$attempt->sumgrades += (float)$state->last_graded->grade;
}
}
} else if (QUIZ_EVENTCLOSE == $action->event) {
} else if (QUESTION_EVENTCLOSE == $action->event) {
// decrease sumgrades by previous grade and then later add new grade
$attempt->sumgrades -= (float)$state->last_graded->grade;
@ -699,10 +683,10 @@ function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$atte
$QTYPES[$question->qtype]->grade_responses(
$question, $state, $cmoptions);
// Calculate overall grade using correct penalty method
quiz_apply_penalty_and_timelimit($question, $state, $attempt, $cmoptions);
question_apply_penalty_and_timelimit($question, $state, $attempt, $cmoptions);
}
// Force the state to close (as the attempt is closing)
$state->event = QUIZ_EVENTCLOSE;
$state->event = QUESTION_EVENTCLOSE;
// Update the last graded state (don't simplify!)
unset($state->last_graded);
@ -719,14 +703,14 @@ function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$atte
/**
* Determine if event requires grading
*/
function quiz_isgradingevent($event) {
return (QUIZ_EVENTGRADE == $event || QUIZ_EVENTCLOSE == $event);
function question_isgradingevent($event) {
return (QUESTION_EVENTGRADE == $event || QUESTION_EVENTCLOSE == $event);
}
/**
* Compare current responses to all previous graded responses
*
* This is used by {@link quiz_process_responses()} to determine whether
* 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
@ -735,11 +719,11 @@ function quiz_isgradingevent($event) {
* @param object $question
* @param object $state
*/
function quiz_search_for_duplicate_responses(&$question, &$state) {
function question_search_for_duplicate_responses(&$question, &$state) {
// get all previously graded question states
global $QTYPES;
if (!$oldstates = get_records('quiz_question_states', "event = '" .
QUIZ_EVENTGRADE . "' AND " . "question = '" . $question->id .
QUESTION_EVENTGRADE . "' AND " . "question = '" . $question->id .
"'", 'seq_number DESC')) {
return false;
}
@ -748,12 +732,12 @@ function quiz_search_for_duplicate_responses(&$question, &$state) {
$question, $oldstate)) {
if(!$QTYPES[$question->qtype]->compare_responses(
$question, $state, $oldstate)) {
$state->event = QUIZ_EVENTDUPLICATEGRADE;
$state->event = QUESTION_EVENTDUPLICATEGRADE;
break;
}
}
}
return (QUIZ_EVENTDUPLICATEGRADE == $state->event);
return (QUESTION_EVENTDUPLICATEGRADE == $state->event);
}
/**
@ -775,7 +759,7 @@ function quiz_search_for_duplicate_responses(&$question, &$state) {
* The ->penaltyscheme field determines whether penalties
* for incorrect earlier responses are subtracted.
*/
function quiz_apply_penalty_and_timelimit(&$question, &$state, $attempt, $cmoptions) {
function question_apply_penalty_and_timelimit(&$question, &$state, $attempt, $cmoptions) {
// deal with penaly
if ($cmoptions->penaltyscheme) {
$state->grade = $state->raw_grade - $state->sumpenalty;
@ -802,15 +786,6 @@ function quiz_apply_penalty_and_timelimit(&$question, &$state, $attempt, $cmopti
$state->grade = max($state->grade, $state->last_graded->grade);
}
function quiz_print_comment($text) {
echo "<span class=\"feedbacktext\">&nbsp;".format_text($text, true, false)."</span>";
}
function quiz_print_correctanswer($text) {
echo "<p align=\"right\"><span class=\"highlight\">$text</span></p>";
}
/**
* Print the icon for the question type
*
@ -819,7 +794,7 @@ function quiz_print_correctanswer($text) {
* edit page.
* @param boolean $return If true the functions returns the link as a string
*/
function quiz_print_question_icon($question, $editlink=true, $return = false) {
function print_question_icon($question, $editlink=true, $return = false) {
// returns a question icon
global $QUIZ_QUESTION_TYPE, $QTYPES, $CFG;
@ -840,14 +815,13 @@ function quiz_print_question_icon($question, $editlink=true, $return = false) {
}
}
/**
* Returns a html link to the question image if there is one
*
* @return string The html image tag or the empy string if there is no image.
* @param object $question The question object
*/
function quiz_get_image($question, $courseid) {
function get_question_image($question, $courseid) {
global $CFG;
$img = '';
@ -866,47 +840,20 @@ function quiz_get_image($question, $courseid) {
}
return $img;
}
/**
* Print the question image if there is one
*
* @param object $question The question object
*/
function quiz_print_possible_question_image($question, $courseid) {
global $CFG;
if ($question->image) {
echo '<img border="0" src="';
if (substr(strtolower($question->image), 0, 7) == 'http://') {
echo $question->image;
} else if ($CFG->slasharguments) { // Use this method if possible for better caching
echo "$CFG->wwwroot/file.php/$courseid/$question->image";
} else {
echo "$CFG->wwwroot/file.php?file=$courseid/$question->image";
}
echo '" alt="" />';
}
}
/**
* Construct name prefixes for question form element names
*
* Construct the name prefix that should be used for example in the
* names of form elements created by questions.
* This is called by {@link quiz_get_question_options()}
* This is called by {@link get_question_options()}
* to set $question->name_prefix.
* This name prefix includes the question id which can be
* extracted from it with {@link quiz_get_id_from_name_prefix()}.
* extracted from it with {@link question_get_id_from_name_prefix()}.
*
* @return string
* @param integer $id The question id
*/
function quiz_make_name_prefix($id) {
function question_make_name_prefix($id) {
return 'resp' . $id . '_';
}
@ -915,99 +862,41 @@ function quiz_make_name_prefix($id) {
*
* @return integer The question id
* @param string $name The name that contains a prefix that was
* constructed with {@link quiz_make_name_prefix()}
* constructed with {@link question_make_name_prefix()}
*/
function quiz_get_id_from_name_prefix($name) {
function question_get_id_from_name_prefix($name) {
if (!preg_match('/^resp([0-9]+)_/', $name, $matches))
return false;
return (integer) $matches[1];
}
function quiz_new_attempt_uniqueid() {
/**
* TODO: document this
*/
function question_new_attempt_uniqueid() {
global $CFG;
set_config('attemptuniqueid', $CFG->attemptuniqueid + 1);
return $CFG->attemptuniqueid;
}
/**
* Determine render options
* Array of names of course modules a question appears in
*
* TODO: Currently this works with quiz only
*
* @return array Array of quiz names
* @param integer $id Question id
*/
function quiz_get_renderoptions($cmoptions, $state) {
// Show the question in readonly (review) mode if the question is in
// the closed state
$options->readonly = QUIZ_EVENTCLOSE === $state->event;
function question_used($id) {
// Show feedback once the question has been graded (if allowed by the quiz)
$options->feedback = ($state->event == QUIZ_EVENTGRADE) && ($cmoptions->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
// Show validation only after a validation event
$options->validation = QUIZ_EVENTVALIDATE === $state->event;
// Show correct responses in readonly mode if the quiz allows it
$options->correct_responses = $options->readonly && ($cmoptions->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY);
// Always show responses and scores
$options->responses = true;
$options->scores = true;
return $options;
}
/**
* Determine review options
*/
function quiz_get_reviewoptions($cmoptions, $attempt, $isteacher=false) {
$options->readonly = true;
if ($isteacher and !$attempt->preview) {
// The teacher should be shown everything except during preview when the teachers
// wants to see just what the students see
$options->responses = true;
$options->scores = true;
$options->feedback = true;
$options->correct_responses = true;
$options->solutions = false;
return $options;
}
if ((time() - $attempt->timefinish) < 120) {
$options->responses = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_RESPONSES) ? 1 : 0;
$options->scores = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_SCORES) ? 1 : 0;
$options->feedback = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK) ? 1 : 0;
$options->correct_responses = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS) ? 1 : 0;
$options->solutions = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_SOLUTIONS) ? 1 : 0;
} else if (!$cmoptions->timeclose or time() < $cmoptions->timeclose) {
$options->responses = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_RESPONSES) ? 1 : 0;
$options->scores = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_SCORES) ? 1 : 0;
$options->feedback = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_FEEDBACK) ? 1 : 0;
$options->correct_responses = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_ANSWERS) ? 1 : 0;
$options->solutions = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_SOLUTIONS) ? 1 : 0;
} else {
$options->responses = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_RESPONSES) ? 1 : 0;
$options->scores = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_SCORES) ? 1 : 0;
$options->feedback = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_FEEDBACK) ? 1 : 0;
$options->correct_responses = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_ANSWERS) ? 1 : 0;
$options->solutions = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_SOLUTIONS) ? 1 : 0;
}
return $options;
}
/// FUNCTIONS THAT ARE USED BY SOME QUESTIONTYPES ///////////////////
function quiz_extract_correctanswers($answers, $nameprefix) {
/// Convenience function that is used by some single-response
/// question-types for determining correct answers.
$bestanswerfraction = 0.0;
$correctanswers = array();
foreach ($answers as $answer) {
if ($answer->fraction > $bestanswerfraction) {
$correctanswers = array($nameprefix.$answer->id => $answer);
$bestanswerfraction = $answer->fraction;
} else if ($answer->fraction == $bestanswerfraction) {
$correctanswers[$nameprefix.$answer->id] = $answer;
$quizlist = array();
if ($instances = get_records('quiz_question_instances', 'question', $id)) {
foreach($instances as $instance) {
$quizlist[$instance->quiz] = get_field('quiz', 'name', 'id', $instance->quiz);
}
}
return $correctanswers;
return $quizlist;
}
/// FUNCTIONS THAT SIMPLY WRAP QUESTIONTYPE METHODS //////////////////////////////////
@ -1017,7 +906,7 @@ function quiz_extract_correctanswers($answers, $nameprefix) {
*
* Simply calls the question type specific print_question() method.
*/
function quiz_print_quiz_question(&$question, &$state, $number, $cmoptions, $options=null) {
function print_question(&$question, &$state, $number, $cmoptions, $options=null) {
global $QTYPES;
$QTYPES[$question->qtype]->print_question($question, $state, $number,
@ -1030,7 +919,7 @@ function quiz_print_quiz_question(&$question, &$state, $number, $cmoptions, $opt
* Simply calls the question type specific get_all_responses() method.
*/
// ULPGC ecastro
function quiz_get_question_responses($question, $state) {
function get_question_responses($question, $state) {
global $QTYPES;
$r = $QTYPES[$question->qtype]->get_all_responses($question, $state);
return $r;
@ -1043,7 +932,7 @@ function quiz_get_question_responses($question, $state) {
* Simply calls the question type specific get_actual_response() method.
*/
// ULPGC ecastro
function quiz_get_question_actual_response($question, $state) {
function get_question_actual_response($question, $state) {
global $QTYPES;
$r = $QTYPES[$question->qtype]->get_actual_response($question, $state);
@ -1056,7 +945,7 @@ function quiz_get_question_actual_response($question, $state) {
* Simply calls the question type specific get_actual_response() method.
*/
// ULPGc ecastro
function quiz_get_question_fraction_grade($question, $state) {
function get_question_fraction_grade($question, $state) {
global $QTYPES;
$r = $QTYPES[$question->qtype]->get_fractional_grade($question, $state);
@ -1074,7 +963,7 @@ function quiz_get_question_fraction_grade($question, $state) {
* @return object The default category
* @param integer $courseid The id of the course whose default category is wanted
*/
function quiz_get_default_category($courseid) {
function get_default_question_category($courseid) {
/// Returns the current category
if ($categories = get_records_select("quiz_categories", "course = '$courseid' AND parent = '0'", "id")) {
@ -1088,7 +977,8 @@ function quiz_get_default_category($courseid) {
$category->info = get_string("defaultinfo", "quiz");
$category->course = $courseid;
$category->parent = 0;
$category->sortorder = QUIZ_CATEGORIES_SORTORDER;
// TODO: Figure out why we use 999 below
$category->sortorder = 999;
$category->publish = 0;
$category->stamp = make_unique_id_code();
@ -1268,26 +1158,6 @@ function get_questions_category( $category, $noparent=false ) {
return $qresults;
}
/**
* Array of names of course modules a question appears in
*
* TODO: Currently this works with quiz only
*
* @return array Array of quiz names
* @param integer $id Question id
*/
function question_used($id) {
$quizlist = array();
if ($instances = get_records('quiz_question_instances', 'question', $id)) {
foreach($instances as $instance) {
$quizlist[$instance->quiz] = get_field('quiz', 'name', 'id', $instance->quiz);
}
}
return $quizlist;
}
/**
* Get list of available import or export formats
* @param string $type 'import' if import list, otherwise export list assumed

View File

@ -204,7 +204,7 @@
// there should only be one but we loop just in case
// TODO: the following should become a function in questionlib.php which
// really deletes all records associated to this attempt.
delete_records('quiz_states', 'attempt', $oldattempt->uniqueid);
delete_records('question_states', 'attempt', $oldattempt->uniqueid);
delete_records('question_sessions', 'attemptid', $oldattempt->uniqueid);
}
}
@ -263,7 +263,7 @@
}
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
" FROM {$CFG->prefix}quiz_questions q,".
" FROM {$CFG->prefix}question q,".
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$quiz->id' AND q.id = i.question".
" AND q.id IN ($questionlist)";
@ -274,20 +274,20 @@
}
// Load the question type specific information
if (!quiz_get_question_options($questions)) {
if (!get_question_options($questions)) {
error('Could not load question options');
}
// Restore the question sessions to their most recent states
// creating new sessions where required
if (!$states = quiz_get_states($questions, $quiz, $attempt)) {
if (!$states = get_question_states($questions, $quiz, $attempt)) {
error('Could not restore question sessions');
}
// Save all the newly created states
if ($newattempt) {
foreach ($questions as $i => $question) {
quiz_save_question_session($questions[$i], $states[$i]);
save_question_session($questions[$i], $states[$i]);
}
}
@ -297,8 +297,8 @@
if ($responses = data_submitted() and empty($_POST['quizpassword'])) {
// set the default event. This can be overruled by individual buttons.
$event = (array_key_exists('markall', $responses)) ? QUIZ_EVENTGRADE :
($finishattempt ? QUIZ_EVENTCLOSE : QUIZ_EVENTSAVE);
$event = (array_key_exists('markall', $responses)) ? QUESTION_EVENTGRADE :
($finishattempt ? QUESTION_EVENTCLOSE : QUESTION_EVENTSAVE);
// Unset any variables we know are not responses
unset($responses->id);
@ -314,7 +314,7 @@
// extract responses
// $actions is an array indexed by the questions ids
$actions = quiz_extract_responses($questions, $responses, $event);
$actions = question_extract_responses($questions, $responses, $event);
// Process each question in turn
@ -324,8 +324,8 @@
$actions[$i]->responses = array('' => '');
}
$actions[$i]->timestamp = $timestamp;
quiz_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt);
quiz_save_question_session($questions[$i], $states[$i]);
question_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt);
save_question_session($questions[$i], $states[$i]);
}
$attempt->timemodified = $timestamp;
@ -348,7 +348,7 @@
// load all the questions
$closequestionlist = implode(',', array_keys($closequestions));
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
" FROM {$CFG->prefix}quiz_questions q,".
" FROM {$CFG->prefix}question q,".
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$quiz->id' AND q.id = i.question".
" AND q.id IN ($closequestionlist)";
@ -357,21 +357,21 @@
}
// Load the question type specific information
if (!quiz_get_question_options($closequestions)) {
if (!get_question_options($closequestions)) {
error('Could not load question options');
}
// Restore the question sessions
if (!$closestates = quiz_get_states($closequestions, $quiz, $attempt)) {
if (!$closestates = get_question_states($closequestions, $quiz, $attempt)) {
error('Could not restore question sessions');
}
foreach($closequestions as $key => $question) {
$action->event = QUIZ_EVENTCLOSE;
$action->event = QUESTION_EVENTCLOSE;
$action->responses = $closestates[$key]->responses;
$action->timestamp = $closestates[$key]->timestamp;
quiz_process_responses($question, $closestates[$key], $action, $quiz, $attempt);
quiz_save_question_session($question, $closestates[$key]);
question_process_responses($question, $closestates[$key], $action, $quiz, $attempt);
save_question_session($question, $closestates[$key]);
}
}
add_to_log($course->id, 'quiz', 'close attempt',
@ -469,8 +469,8 @@
if ($i > 0) {
echo "<br />\n";
}
quiz_print_quiz_question($questions[$i], $states[$i], $number, $quiz, $options);
quiz_save_question_session($questions[$i], $states[$i]);
print_question($questions[$i], $states[$i], $number, $quiz, $options);
save_question_session($questions[$i], $states[$i]);
$number += $questions[$i]->length;
}

View File

@ -21,7 +21,7 @@
// |---------(UL,pk->id,fk->attempt,question)-----| . | | | .
// | . | . | | quiz_dataset_definitions
// | . | . | | (CL,pk->id,fk->category)
// | quiz_states | quiz_questions |
// | question_states | question |
// ----------(UL,pk->id,fk->attempt,question)--------------------------(CL,pk->id,fk->category,files) |
// | | quiz_dataset_items
// | | (CL,pk->id,fk->definition)
@ -69,7 +69,7 @@
//This module is special, because we make the backup in two steps:
// 1.-We backup every category and their questions (complete structure). It includes this tables:
// - quiz_categories
// - quiz_questions
// - question
// - quiz_rqp
// - quiz_truefalse
// - quiz_shortanswer
@ -95,7 +95,7 @@
// - quiz_question_instances
// - quiz_attempts
// - quiz_grades
// - quiz_states
// - question_states
// - question_sessions
// This step is the standard mod backup. (course dependent).
@ -123,7 +123,7 @@
$status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids
(backup_code, table_name, old_id)
SELECT DISTINCT $backup_unique_code,'quiz_categories',t.category
FROM {$CFG->prefix}quiz_questions t,
FROM {$CFG->prefix}question t,
{$CFG->prefix}quiz_question_instances g
$from
WHERE $where g.question = t.id",false);
@ -162,7 +162,7 @@
// because we will have to add these subcategories
$sql = "SELECT t.id, t.category
FROM {$CFG->prefix}quiz_question_instances AS g,
{$CFG->prefix}quiz_questions AS t
{$CFG->prefix}question AS t
$from
WHERE $where t.id = g.question
AND t.qtype = '".RANDOM."'
@ -199,7 +199,7 @@
global $CFG;
$categories = get_records_sql("SELECT DISTINCT t.category, t.category
FROM {$CFG->prefix}quiz_questions t,
FROM {$CFG->prefix}question t,
{$CFG->prefix}quiz_question_instances g,
{$CFG->prefix}quiz q
WHERE q.course = '$course' AND
@ -221,7 +221,7 @@
unset ($db_cat);
if ($catid) {
//Reasign orphaned questions to their new category
set_field ('quiz_questions','category',$catid,'category',$key);
set_field ('question','category',$catid,'category',$key);
}
}
}
@ -287,7 +287,7 @@
// We'll fetch the questions sorted by parent so that questions with no parents
// (these are the ones which could be parents themselves) are backed up first. This
// is important for the recoding of the parent field during the restore process
$questions = get_records("quiz_questions","category",$category,"parent ASC, id");
$questions = get_records("question","category",$category,"parent ASC, id");
//If there are questions
if ($questions) {
//Write start tag
@ -946,7 +946,7 @@
fwrite ($bf,full_tag("LAYOUT",6,false,$attempt->layout));
fwrite ($bf,full_tag("PREVIEW",6,false,$attempt->preview));
//Now write to xml the states (in this attempt)
$status = backup_quiz_states ($bf,$preferences,$attempt->uniqueid);
$status = backup_question_states ($bf,$preferences,$attempt->uniqueid);
//Now write to xml the sessions (in this attempt)
$status = backup_question_sessions ($bf,$preferences,$attempt->uniqueid);
//End attempt
@ -958,20 +958,20 @@
return $status;
}
//Backup quiz_states contents (executed from backup_quiz_attempts)
function backup_quiz_states ($bf,$preferences,$attempt) {
//Backup question_states contents (executed from backup_quiz_attempts)
function backup_question_states ($bf,$preferences,$attempt) {
global $CFG;
$status = true;
$quiz_states = get_records("quiz_states","attempt",$attempt,"id");
$question_states = get_records("question_states","attempt",$attempt,"id");
//If there are states
if ($quiz_states) {
if ($question_states) {
//Write start tag
$status = fwrite ($bf,start_tag("STATES",6,true));
//Iterate over each state
foreach ($quiz_states as $state) {
foreach ($question_states as $state) {
//Start state
$status = fwrite ($bf,start_tag("STATE",7,true));
//Print state contents
@ -1059,7 +1059,7 @@
return $info;
}
//Backup quiz_rqp_state contents (executed from backup_quiz_states)
//Backup quiz_rqp_state contents (executed from backup_question_states)
function backup_quiz_rqp_state ($bf,$preferences,$state) {
global $CFG;
@ -1081,7 +1081,7 @@
return $status;
}
//Backup quiz_essay_state contents (executed from backup_quiz_states)
//Backup quiz_essay_state contents (executed from backup_question_states)
function backup_quiz_essay_state ($bf,$preferences,$state) {
global $CFG;
@ -1202,7 +1202,7 @@
return get_records_sql ("SELECT q.id, q.category
FROM {$CFG->prefix}backup_ids a,
{$CFG->prefix}quiz_questions q
{$CFG->prefix}question q
WHERE a.backup_code = '$backup_unique_code' AND
q.category = a.old_id AND
a.table_name = 'quiz_categories'");

View File

@ -1,5 +1,5 @@
<?
function migrate2utf8_quiz_questions_name($recordid){
function migrate2utf8_question_name($recordid){
global $CFG, $globallang;
/// Some trivial checks
@ -10,7 +10,7 @@ function migrate2utf8_quiz_questions_name($recordid){
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq
{$CFG->prefix}question qq
WHERE qc.id = qq.category
AND qq.id = $recordid";
@ -19,7 +19,7 @@ function migrate2utf8_quiz_questions_name($recordid){
return false;
}
if (!$quizquestions = get_record('quiz_questions','id',$recordid)) {
if (!$quizquestions = get_record('question','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
@ -42,13 +42,13 @@ function migrate2utf8_quiz_questions_name($recordid){
$newquizquestion = new object;
$newquizquestion->id = $recordid;
$newquizquestion->name = $result;
update_record('quiz_questions',$newquizquestion);
update_record('question',$newquizquestion);
}
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_quiz_questions_questiontext($recordid){
function migrate2utf8_question_questiontext($recordid){
global $CFG, $globallang;
/// Some trivial checks
@ -59,7 +59,7 @@ function migrate2utf8_quiz_questions_questiontext($recordid){
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq
{$CFG->prefix}question qq
WHERE qc.id = qq.category
AND qq.id = $recordid";
@ -68,7 +68,7 @@ function migrate2utf8_quiz_questions_questiontext($recordid){
return false;
}
if (!$quizquestions = get_record('quiz_questions','id',$recordid)) {
if (!$quizquestions = get_record('question','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
@ -92,7 +92,7 @@ function migrate2utf8_quiz_questions_questiontext($recordid){
$newquizquestion = new object;
$newquizquestion->id = $recordid;
$newquizquestion->questiontext = $result;
update_record('quiz_questions',$newquizquestion);
update_record('question',$newquizquestion);
}
/// And finally, just return the converted field
return $result;
@ -110,7 +110,7 @@ function migrate2utf8_quiz_numerical_units_unit($recordid){
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_numerical_units qnu
WHERE qc.id = qq.category
AND qq.id = qnu.question
@ -162,7 +162,7 @@ function migrate2utf8_quiz_match_sub_questiontext($recordid){
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_match_sub qms
WHERE qc.id = qq.category
AND qq.id = qms.question
@ -214,7 +214,7 @@ function migrate2utf8_quiz_match_sub_answertext($recordid){
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_match_sub qms
WHERE qc.id = qq.category
AND qq.id = qms.question
@ -266,7 +266,7 @@ function migrate2utf8_quiz_answers_answer($recordid){
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_answers qa
WHERE qc.id = qq.category
AND qq.id = qa.question
@ -318,7 +318,7 @@ function migrate2utf8_quiz_answers_feedback($recordid){
$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_answers qa
WHERE qc.id = qq.category
AND qq.id = qa.question

View File

@ -75,12 +75,12 @@
<FIELD name="layout" method="NO_CONV" type="text" length="0" />
</FIELDS>
</TABLE>
<TABLE name="quiz_states">
<TABLE name="question_states">
<FIELDS>
<FIELD name="answer" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT qa.userid
FROM {$CFG->prefix}quiz_states qs,
FROM {$CFG->prefix}question_states qs,
{$CFG->prefix}quiz_attempts qa
WHERE qa.id = qs.attempt
AND qs.id=RECORDID
@ -88,7 +88,7 @@
<SQL_DETECT_COURSE>
SELECT q.course
FROM {$CFG->prefix}quiz q,
{$CFG->prefix}quiz_states qs,
{$CFG->prefix}question_states qs,
{$CFG->prefix}quiz_attempts qa
WHERE q.id = qa.quiz
AND qa.id = qs.attempt
@ -97,16 +97,16 @@
</FIELD>
</FIELDS>
</TABLE>
<TABLE name="quiz_questions">
<TABLE name="question">
<FIELDS>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_quiz_questions_name(RECORDID)
migrate2utf8_question_name(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="questiontext" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_quiz_questions_questiontext(RECORDID)
migrate2utf8_question_questiontext(RECORDID)
</PHP_FUNCTION>
</FIELD>
<FIELD name="image" method="NO_CONV" type="varchar" length="255" />
@ -165,7 +165,7 @@
<FIELD name="response" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT qa.userid
FROM {$CFG->prefix}quiz_states qs,
FROM {$CFG->prefix}question_states qs,
{$CFG->prefix}quiz_attempts qa,
{$CFG->prefix}quiz_essay_states qes
WHERE qa.id = qs.attempt
@ -176,7 +176,7 @@
SELECT q.course
FROM {$CFG->prefix}quiz q,
{$CFG->prefix}quiz_attempts qa,
{$CFG->prefix}quiz_states qs,
{$CFG->prefix}question_states qs,
{$CFG->prefix}quiz_essay_states qes
WHERE q.id = qa.quiz
AND qa.id = qs.attempt

View File

@ -937,6 +937,14 @@ function quiz_upgrade($oldversion) {
table_column('question_sessions', 'sumpenalty', 'sumpenalty', 'float', '', '', '0', 'not null');
}
if ($oldversion < 2006022400) {
execute_sql("ALTER TABLE {$CFG->prefix}quiz_questions RENAME {$CFG->prefix}question", false);
}
if ($oldversion < 2006022402) {
execute_sql("ALTER TABLE {$CFG->prefix}quiz_states RENAME {$CFG->prefix}question_states", false);
}
return true;
}

View File

@ -379,10 +379,10 @@ CREATE TABLE prefix_quiz_question_versions (
-- --------------------------------------------------------
--
-- Table structure for table `prefix_quiz_questions`
-- Table structure for table `prefix_question`
--
CREATE TABLE prefix_quiz_questions (
CREATE TABLE prefix_question (
id int(10) NOT NULL auto_increment,
category int(10) NOT NULL default '0',
parent int(10) unsigned NOT NULL default '0',
@ -495,10 +495,10 @@ CREATE TABLE prefix_quiz_shortanswer (
-- --------------------------------------------------------
--
-- Table structure for table `prefix_quiz_states`
-- Table structure for table `prefix_question_states`
--
CREATE TABLE prefix_quiz_states (
CREATE TABLE prefix_question_states (
id int(10) unsigned NOT NULL auto_increment,
attempt int(10) unsigned NOT NULL default '0',
question int(10) unsigned NOT NULL default '0',

View File

@ -369,10 +369,10 @@ CREATE TABLE prefix_quiz_question_versions (
# --------------------------------------------------------
#
# Table structure for table prefix_quiz_questions
# Table structure for table prefix_question
#
CREATE TABLE prefix_quiz_questions (
CREATE TABLE prefix_question (
id SERIAL PRIMARY KEY,
category integer NOT NULL default '0',
parent integer NOT NULL default '0',
@ -389,7 +389,7 @@ CREATE TABLE prefix_quiz_questions (
hidden integer NOT NULL default '0'
);
CREATE INDEX prefix_quiz_questions_category_idx ON prefix_quiz_questions (category);
CREATE INDEX prefix_question_category_idx ON prefix_question (category);
# --------------------------------------------------------
@ -474,10 +474,10 @@ CREATE INDEX prefix_quiz_shortanswer_question_idx ON prefix_quiz_shortanswer (qu
# --------------------------------------------------------
#
# Table structure for table prefix_quiz_states
# Table structure for table prefix_question_states
#
CREATE TABLE prefix_quiz_states (
CREATE TABLE prefix_question_states (
id SERIAL PRIMARY KEY,
attempt integer NOT NULL default '0',
question integer NOT NULL default '0',
@ -491,8 +491,8 @@ CREATE TABLE prefix_quiz_states (
penalty real NOT NULL default '0'
);
CREATE INDEX prefix_quiz_states_attempt_idx ON prefix_quiz_states (attempt);
CREATE INDEX prefix_quiz_states_question_idx ON prefix_quiz_states (question);;
CREATE INDEX prefix_question_states_attempt_idx ON prefix_question_states (attempt);
CREATE INDEX prefix_question_states_question_idx ON prefix_question_states (question);;
# --------------------------------------------------------

View File

@ -181,7 +181,7 @@ if (self.name == 'editquestion') {
}
// find existing random questions in this category
$random = RANDOM;
if ($existingquestions = get_records_select('quiz_questions', "qtype = '$random' AND category = '$category->id'")) {
if ($existingquestions = get_records_select('question', "qtype = '$random' AND category = '$category->id'")) {
// now remove the ones that are already used in this quiz
if ($questionids = explode(',', $modform->questions)) {
foreach ($questionids as $questionid) {
@ -296,7 +296,7 @@ if (self.name == 'editquestion') {
/// all commands have been dealt with, now print the page
if (empty($modform->category) or !record_exists('quiz_categories', 'id', $modform->category)) {
$category = quiz_get_default_category($course->id);
$category = get_default_question_category($course->id);
$modform->category = $category->id;
}
if (!isset($SESSION->quiz_showbreaks)) {

View File

@ -89,7 +89,7 @@ function quiz_add_quiz_question($id, &$modform) {
}
// update question grades
$questionrecord = get_record("quiz_questions", "id", $id);
$questionrecord = get_record("question", "id", $id);
$modform->grades[$id] = $questionrecord->defaultgrade;
quiz_update_question_instance($modform->grades[$id], $id, $modform->instance);
@ -153,7 +153,7 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
}
if (!$questions = get_records_sql("SELECT q.*,c.course
FROM {$CFG->prefix}quiz_questions q,
FROM {$CFG->prefix}question q,
{$CFG->prefix}quiz_categories c
WHERE q.id in ($quiz->questions)
AND q.category = c.id")) {
@ -246,7 +246,7 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
echo "<td>$question->name</td>";
echo "<td align=\"center\">";
quiz_print_question_icon($question, $canedit);
print_question_icon($question, $canedit);
echo "</td>";
echo '<td align="left">';
if ($question->qtype == DESCRIPTION) {

View File

@ -26,7 +26,7 @@
if (!empty($questionid)) {
if (! $question = get_record('quiz_questions', 'id', $questionid)) {
if (! $question = get_record('question', 'id', $questionid)) {
error("Question with id $questionid not found");
}
///$number = optional_param('number', 0, PARAM_INT);
@ -121,7 +121,7 @@
// get the state
$statefields = 'n.questionid as question, s.*, n.sumpenalty';
$sql = "SELECT $statefields".
" FROM {$CFG->prefix}quiz_states s,".
" FROM {$CFG->prefix}question_states s,".
" {$CFG->prefix}question_sessions n".
" WHERE s.id = n.newest".
" AND n.attemptid = '$attempt->uniqueid'".
@ -129,7 +129,7 @@
$state = get_record_sql($sql);
// restore the state of the question
quiz_restore_state($question, $state);
restore_question_state($question, $state);
// this is the new response from the teacher
$state->responses = $response;
@ -139,19 +139,19 @@
// finalize the grade
$state->last_graded->grade = 0; // we dont want the next function to care about the last grade
quiz_apply_penalty_and_timelimit($question, $state, $attempt, $quiz);
question_apply_penalty_and_timelimit($question, $state, $attempt, $quiz);
// want to update session. Also set changed to 1 to trick quiz_save_question_session to save our session
// want to update session. Also set changed to 1 to trick save_question_session to save our session
$state->update = 1;
$state->changed = 1;
quiz_save_question_session($question, $state);
save_question_session($question, $state);
// method for changing sumgrades from report type regrade. Thanks!
$sumgrades = 0;
$questionids = explode(',', quiz_questions_in_quiz($attempt->layout));
foreach($questionids as $questionid) {
$lastgradedid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->uniqueid, 'questionid', $questionid);
$sumgrades += get_field('quiz_states', 'grade', 'id', $lastgradedid);
$sumgrades += get_field('question_states', 'grade', 'id', $lastgradedid);
}
if ($attempt->sumgrades != $sumgrades) {
@ -193,7 +193,7 @@
if (!$neweststate = get_record('question_sessions', 'attemptid', $attempt->uniqueid, 'questionid', $questionid)) {
error("Can not find newest states for attempt $attempt->uniqueid for question $questionid");
}
if (! $state = get_record('quiz_states', 'id', $neweststate->newest)) {
if (! $state = get_record('question_states', 'id', $neweststate->newest)) {
error('Invalid state id');
}
@ -204,11 +204,11 @@
$question->name_prefix = $attempt->attemptid.'_'.$state->id.'_';
$QTYPES[$question->qtype]->get_question_options($question);
quiz_restore_state($question, $state);
restore_question_state($question, $state);
$state->last_graded = $state;
$options = quiz_get_reviewoptions($quiz, $attempt, $isteacher);
$options->validation = ($state->event == QUIZ_EVENTVALIDATE); // not sure what this is
$options->validation = ($state->event == QUESTION_EVENTVALIDATE); // not sure what this is
//$options->history = 'all'; // had this on, but seemed confusing for this
// IF this code is expanded to manually regrade any question type, then
@ -223,7 +223,7 @@
get_string('attempt', 'quiz')." $attempt->attempt".
'</p>';
quiz_print_quiz_question($question, $state, '', $quiz, $options);
print_question($question, $state, '', $quiz, $options);
echo '<input type="hidden" name="attemptids[]" value="'.$attempt->attemptid.'">'.
'<input type="hidden" name="stateids[]" value="'.$state->id.'">';
echo '</div>';

View File

@ -215,7 +215,7 @@ function quiz_delete_instance($id) {
if ($attempts = get_records("quiz_attempts", "quiz", "$quiz->id")) {
foreach ($attempts as $attempt) {
// TODO: this should use function in questionlib.php
if (! delete_records("quiz_states", "attempt", "$attempt->uniqueid")) {
if (! delete_records("question_states", "attempt", "$attempt->uniqueid")) {
$result = false;
}
if (! delete_records("question_sessions", "attemptid", "$attempt->uniqueid")) {
@ -336,11 +336,11 @@ function quiz_delete_course($course, $feedback=true) {
//Category isn't being used so:
//Delete it completely (questions and category itself)
//deleting questions
if ($questions = get_records("quiz_questions", "category", $category->id)) {
if ($questions = get_records("question", "category", $category->id)) {
foreach ($questions as $question) {
quiz_delete_question($question);
delete_question($question);
}
delete_records("quiz_questions", "category", $category->id);
delete_records("question", "category", $category->id);
}
//delete the category
delete_records('quiz_categories', 'id', $category->id);

View File

@ -72,7 +72,7 @@ function quiz_create_attempt($quiz, $attemptnumber) {
$attempt->timestart = $timenow;
$attempt->timefinish = 0;
$attempt->timemodified = $timenow;
$attempt->uniqueid = quiz_new_attempt_uniqueid();
$attempt->uniqueid = question_new_attempt_uniqueid();
return $attempt;
}
@ -141,7 +141,7 @@ function quiz_first_questionnumber($quizlayout, $pagelayout) {
$start = strpos($quizlayout, ','.$pagelayout.',')-2;
if ($start > 0) {
$prevlist = substr($quizlayout, 0, $start);
return get_field_sql("SELECT sum(length)+1 FROM {$CFG->prefix}quiz_questions
return get_field_sql("SELECT sum(length)+1 FROM {$CFG->prefix}question
WHERE id IN ($prevlist)");
} else {
return 1;
@ -447,7 +447,7 @@ function quiz_upgrade_states($attempt) {
// only one state record per question for this attempt.
// We set the timestamp of all states to the timemodified field of the attempt.
execute_sql("UPDATE {$CFG->prefix}quiz_states SET timestamp = '$attempt->timemodified' WHERE attempt = '$attempt->uniqueid'", false);
execute_sql("UPDATE {$CFG->prefix}question_states SET timestamp = '$attempt->timemodified' WHERE attempt = '$attempt->uniqueid'", false);
// For each state we create an entry in the question_sessions table, with both newest and
// newgraded pointing to this state.
@ -456,7 +456,7 @@ function quiz_upgrade_states($attempt) {
// used by a RANDOM question
$newest->attemptid = $attempt->uniqueid;
$questionlist = quiz_questions_in_quiz($attempt->layout);
if ($questionlist and $states = get_records_select('quiz_states', "attempt = '$attempt->uniqueid' AND question IN ($questionlist)")) {
if ($questionlist and $states = get_records_select('question_states', "attempt = '$attempt->uniqueid' AND question IN ($questionlist)")) {
foreach ($states as $state) {
$session->newgraded = $state->id;
$session->newest = $state->id;
@ -478,6 +478,68 @@ function quiz_get_question_review($quiz, $question) {
}
/**
* Determine render options
*/
function quiz_get_renderoptions($cmoptions, $state) {
// Show the question in readonly (review) mode if the question is in
// the closed state
$options->readonly = QUESTION_EVENTCLOSE === $state->event;
// Show feedback once the question has been graded (if allowed by the quiz)
$options->feedback = ($state->event == QUESTION_EVENTGRADE) && ($cmoptions->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
// Show validation only after a validation event
$options->validation = QUESTION_EVENTVALIDATE === $state->event;
// Show correct responses in readonly mode if the quiz allows it
$options->correct_responses = $options->readonly && ($cmoptions->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY);
// Always show responses and scores
$options->responses = true;
$options->scores = true;
return $options;
}
/**
* Determine review options
*/
function quiz_get_reviewoptions($cmoptions, $attempt, $isteacher=false) {
$options->readonly = true;
if ($isteacher and !$attempt->preview) {
// The teacher should be shown everything except during preview when the teachers
// wants to see just what the students see
$options->responses = true;
$options->scores = true;
$options->feedback = true;
$options->correct_responses = true;
$options->solutions = false;
return $options;
}
if ((time() - $attempt->timefinish) < 120) {
$options->responses = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_RESPONSES) ? 1 : 0;
$options->scores = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_SCORES) ? 1 : 0;
$options->feedback = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK) ? 1 : 0;
$options->correct_responses = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS) ? 1 : 0;
$options->solutions = ($cmoptions->review & QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_SOLUTIONS) ? 1 : 0;
} else if (!$cmoptions->timeclose or time() < $cmoptions->timeclose) {
$options->responses = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_RESPONSES) ? 1 : 0;
$options->scores = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_SCORES) ? 1 : 0;
$options->feedback = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_FEEDBACK) ? 1 : 0;
$options->correct_responses = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_ANSWERS) ? 1 : 0;
$options->solutions = ($cmoptions->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_SOLUTIONS) ? 1 : 0;
} else {
$options->responses = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_RESPONSES) ? 1 : 0;
$options->scores = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_SCORES) ? 1 : 0;
$options->feedback = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_FEEDBACK) ? 1 : 0;
$options->correct_responses = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_ANSWERS) ? 1 : 0;
$options->solutions = ($cmoptions->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_SOLUTIONS) ? 1 : 0;
}
return $options;
}
/**
* Array of names of quizzes a category (and optionally its childs) appears in
@ -491,7 +553,7 @@ function quizzes_category_used($id, $recursive = false) {
$quizlist = array();
//Look for each question in the category
if ($questions = get_records('quiz_questions', 'category', $id)) {
if ($questions = get_records('question', 'category', $id)) {
foreach ($questions as $question) {
$qlist = question_used($question->id);
$quizlist = $quizlist + $qlist;

View File

@ -2,6 +2,7 @@
// This function fetches files from the data directory
// Syntax: quizfile.php/quiz id/question id/dir/.../dir/filename.ext
// It is supposed to be used by the quiz module only
// I believe this is obsolete, everything should be using moodle/file.php GWD
require_once('../../config.php');
require_once($CFG->libdir.'/filelib.php');
@ -29,7 +30,7 @@
$questionid = (int)array_shift($args);
$relativepath = implode ('/', $args);
if (!($question = get_record('quiz_questions', 'id', $questionid))) {
if (!($question = get_record('question', 'id', $questionid))) {
error('No valid arguments supplied');
}

View File

@ -49,7 +49,7 @@
// Upgrade any attempts that have not yet been upgraded to the
// Moodle 1.5 model (they will not yet have the timestamp set)
if ($attempts = get_records_sql("SELECT a.*".
" FROM {$CFG->prefix}quiz_attempts a, {$CFG->prefix}quiz_states s".
" FROM {$CFG->prefix}quiz_attempts a, {$CFG->prefix}question_states s".
" WHERE a.quiz = '$quiz->id' AND s.attempt = a.uniqueid AND s.timestamp = 0")) {
foreach ($attempts as $attempt) {
quiz_upgrade_states($attempt);

View File

@ -105,7 +105,7 @@ class quiz_report extends quiz_default_report {
$statstable = array();
$questionarray = array();
foreach ($attempts as $attempt) {
$questionarray[] = quiz_questions_in_quiz($attempt->layout);
$questionarray[] = question_in_quiz($attempt->layout);
}
$questionlist = quiz_questions_in_quiz(implode(",", $questionarray));
$questionarray = array_unique(explode(",",$questionlist));
@ -132,7 +132,7 @@ class quiz_report extends quiz_default_report {
if ($attemptselection == QUIZ_ALLATTEMPTS || $userscore == $usermax[$attempt->userid]) {
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
" FROM {$CFG->prefix}quiz_questions q,".
" FROM {$CFG->prefix}question q,".
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$quiz->id' AND q.id = i.question".
" AND q.id IN ($questionlist)";
@ -142,12 +142,12 @@ class quiz_report extends quiz_default_report {
}
// Load the question type specific information
if (!quiz_get_question_options($quizquestions)) {
if (!get_question_options($quizquestions)) {
error('Could not load question options');
}
// Restore the question sessions to their most recent states
// creating new sessions where required
if (!$states = quiz_get_states($quizquestions, $quiz, $attempt)) {
if (!$states = get_question_states($quizquestions, $quiz, $attempt)) {
error('Could not restore question sessions');
}
$numbers = explode(',', $questionlist);
@ -160,7 +160,7 @@ class quiz_report extends quiz_default_report {
if (!in_array ($qtype, $accepted_qtypes)){
continue;
}
$q = quiz_get_question_responses($quizquestions[$i], $states[$i]);
$q = get_question_responses($quizquestions[$i], $states[$i]);
$qid = $q->id;
if (!isset($questions[$qid])) {
$questions[$qid]['id'] = $qid;
@ -173,7 +173,7 @@ class quiz_report extends quiz_default_report {
$statsrow[$qid] = 0;
}
}
$responses = quiz_get_question_actual_response($quizquestions[$i], $states[$i]);
$responses = get_question_actual_response($quizquestions[$i], $states[$i]);
foreach ($responses as $resp){
if ($resp) {
if ($key = array_search($resp, $questions[$qid]['responses'])) {
@ -190,7 +190,7 @@ class quiz_report extends quiz_default_report {
}
}
}
$statsrow[$qid] = quiz_get_question_fraction_grade($quizquestions[$i], $states[$i]);
$statsrow[$qid] = get_question_fraction_grade($quizquestions[$i], $states[$i]);
}
$attemptscores[$attempt->id] = $attempt->sumgrades;
$statstable[$attempt->id] = $statsrow;
@ -308,10 +308,10 @@ class quiz_report extends quiz_default_report {
foreach($pagequestions as $qnum) {
$q = $questions[$qnum];
$qid = $q['id'];
$question = get_record('quiz_questions', 'id', $qid);
$question = get_record('question', 'id', $qid);
$qnumber = " (".link_to_popup_window('/question/question.php?id='.$qid,'editquestion', $qid, 450, 550, get_string('edit'), 'none', true ).") ";
$qname = '<div class="qname">'.format_text($question->name." : ", $question->questiontextformat, NULL, $quiz->course).'</div>';
$qicon = quiz_print_question_icon($question, false, true);
$qicon = print_question_icon($question, false, true);
$qreview = quiz_get_question_review($quiz, $question);
$qtext = format_text($question->questiontext, $question->questiontextformat, NULL, $quiz->course);
$qquestion = $qname."\n".$qtext."\n";
@ -628,7 +628,7 @@ class quiz_report extends quiz_default_report {
function print_row_stats_data(&$q) {
$qid = $q['id'];
$question = get_record('quiz_questions', 'id', $qid);
$question = get_record('question', 'id', $qid);
$options->para = false;
$options->newlines = false;

View File

@ -43,7 +43,7 @@ class quiz_report extends quiz_default_report {
if ($todelete = get_record('quiz_attempts', 'id', $attemptid)) {
// TODO: use function from questionlib.php to delete attempt
delete_records('quiz_attempts', 'id', $attemptid);
delete_records('quiz_states', 'attempt', $todelete->uniqueid);
delete_records('question_states', 'attempt', $todelete->uniqueid);
delete_records('question_sessions', 'attemptid', $todelete->uniqueid);
// Search quiz_attempts for other instances by this user.
@ -115,7 +115,7 @@ class quiz_report extends quiz_default_report {
$questionlist = quiz_questions_in_quiz($quiz->questions);
$questionids = explode(',', $questionlist);
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
" FROM {$CFG->prefix}quiz_questions q,".
" FROM {$CFG->prefix}question q,".
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$quiz->id' AND q.id = i.question".
" AND q.id IN ($questionlist)";
@ -290,7 +290,7 @@ class quiz_report extends quiz_default_report {
$qid = intval(substr($sortpart, 1));
$select .= ', grade ';
$from .= 'LEFT JOIN '.$CFG->prefix.'question_sessions qns ON qns.attemptid = qa.attemptuniqueid '.
'LEFT JOIN '.$CFG->prefix.'quiz_states qs ON qs.id = qns.newgraded ';
'LEFT JOIN '.$CFG->prefix.'question_states qs ON qs.id = qns.newgraded ';
$where .= ' AND ('.sql_isnull('qns.questionid').' OR qns.questionid = '.$qid.')';
$newsort[] = 'grade '.(strpos($sortpart, 'ASC')? 'ASC' : 'DESC');
$questionsort = true;
@ -387,10 +387,10 @@ class quiz_report extends quiz_default_report {
else {
foreach($questionids as $questionid) {
if ($gradedstateid = get_field('quiz_newest_states', 'newgraded', 'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) {
$grade = round(get_field('quiz_states', 'grade', 'id', $gradedstateid), $quiz->decimalpoints);
$grade = round(get_field('question_states', 'grade', 'id', $gradedstateid), $quiz->decimalpoints);
} else {
// This is an old-style attempt
$grade = round(get_field('quiz_states', 'grade', 'attempt', $attempt->attempt, 'question', $questionid), $quiz->decimalpoints);
$grade = round(get_field('question_states', 'grade', 'attempt', $attempt->attempt, 'question', $questionid), $quiz->decimalpoints);
}
if (!$download) {
$row[] = link_to_popup_window ('/mod/quiz/reviewquestion.php?state='.$gradedstateid.'&amp;number='.$questions[$questionid]->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true);

View File

@ -19,7 +19,7 @@ class quiz_report extends quiz_default_report {
}
/// Fetch all questions
$sql = "SELECT q.*, i.grade AS maxgrade FROM {$CFG->prefix}quiz_questions q,
$sql = "SELECT q.*, i.grade AS maxgrade FROM {$CFG->prefix}question q,
{$CFG->prefix}quiz_question_instances i
WHERE i.quiz = $quiz->id
AND i.question = q.id";
@ -27,7 +27,7 @@ class quiz_report extends quiz_default_report {
if (! $questions = get_records_sql($sql)) {
error("Failed to get questions for regrading!");
}
quiz_get_question_options($questions);
get_question_options($questions);
/// Print heading
print_heading(get_string('regradingquiz', 'quiz', $quiz->name));
@ -40,7 +40,7 @@ class quiz_report extends quiz_default_report {
echo '<b>'.get_string('regradingquestion', 'quiz', $question->name).'</b> '.get_string('attempts', 'quiz').": \n";
foreach ($attempts as $attempt) {
set_time_limit(30);
quiz_regrade_question_in_attempt($question, $attempt, $quiz, true);
regrade_question_in_attempt($question, $attempt, $quiz, true);
}
echo '<br/ >';
// the following makes sure that the output is sent immediately.
@ -54,7 +54,7 @@ class quiz_report extends quiz_default_report {
$questionids = explode(',', quiz_questions_in_quiz($attempt->layout));
foreach($questionids as $questionid) {
$lastgradedid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->uniqueid, 'questionid', $questionid);
$sumgrades += get_field('quiz_states', 'grade', 'id', $lastgradedid);
$sumgrades += get_field('question_states', 'grade', 'id', $lastgradedid);
}
if ($attempt->sumgrades != $sumgrades) {
$attemptschanged++;

View File

@ -93,7 +93,7 @@ class quiz_report extends quiz_default_report {
$questionlist = quiz_questions_in_quiz($quiz->questions);
$questionids = explode(',', $questionlist);
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
" FROM {$CFG->prefix}quiz_questions q,".
" FROM {$CFG->prefix}question q,".
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$quiz->id' AND q.id = i.question".
" AND q.id IN ($questionlist)";
@ -115,7 +115,7 @@ class quiz_report extends quiz_default_report {
}
}
// Load the question type specific information
if (!quiz_get_question_options($questions)) {
if (!get_question_options($questions)) {
error('Could not load question options');
}
@ -178,7 +178,7 @@ class quiz_report extends quiz_default_report {
$qid = intval(substr($sortpart, 1));
$select .= ', grade ';
$from .= 'LEFT JOIN '.$CFG->prefix.'question_sessions qns ON qns.attemptid = qa.id '.
'LEFT JOIN '.$CFG->prefix.'quiz_states qs ON qs.id = qns.newgraded ';
'LEFT JOIN '.$CFG->prefix.'question_states qs ON qs.id = qns.newgraded ';
$where .= ' AND ('.sql_isnull('qns.questionid').' OR qns.questionid = '.$qid.')';
$newsort[] = 'answer '.(strpos($sortpart, 'ASC')? 'ASC' : 'DESC');
$questionsort = true;
@ -311,13 +311,13 @@ class quiz_report extends quiz_default_report {
// Restore the question sessions to their most recent states
// creating new sessions where required
if (!$states = quiz_get_states($questions, $quiz, $attempt)) {
if (!$states = get_question_states($questions, $quiz, $attempt)) {
error('Could not restore question sessions');
}
foreach($questionids as $questionid) {
$gradedstateid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->id, 'questionid', $questionid);
$grade = round(get_field('quiz_states', 'grade', 'id', $gradedstateid), $quiz->decimalpoints);
$responses = quiz_get_question_actual_response($questions[$questionid], $states[$questionid]);
$grade = round(get_field('question_states', 'grade', 'id', $gradedstateid), $quiz->decimalpoints);
$responses = get_question_actual_response($questions[$questionid], $states[$questionid]);
$response = implode(', ',$responses);
if (!$download) {
$format_options->para = false;

View File

@ -29,7 +29,7 @@
// |---------(UL,pk->id,fk->attempt,question)-----| . | | | .
// | . | . | | quiz_dataset_definitions
// | . | . | | (CL,pk->id,fk->category)
// | quiz_states | quiz_questions |
// | question_states | question |
// ----------(UL,pk->id,fk->attempt,question)--------------------------(CL,pk->id,fk->category,files) |
// | | quiz_dataset_items
// | | (CL,pk->id,fk->definition)
@ -75,7 +75,7 @@
//This module is special, because we make the restore in two steps:
// 1.-We restore every category and their questions (complete structure). It includes this tables:
// - quiz_categories
// - quiz_questions
// - question
// - quiz_truefalse
// - quiz_shortanswer
// - quiz_multianswer
@ -100,7 +100,7 @@
// - quiz_question_instances
// - quiz_attempts
// - quiz_grades
// - quiz_states
// - question_states
// This step is the standard mod backup. (course dependent).
//STEP 1. Restore categories/questions and associated structures (course independent)
@ -163,7 +163,7 @@
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_categories",
$category->id, $newid);
//Now restore quiz_questions
//Now restore question
$status = quiz_restore_questions ($category->id, $newid,$info,$restore);
} else {
$status = false;
@ -196,7 +196,7 @@
//We'll need this later!!
$oldid = backup_todb($que_info['#']['ID']['0']['#']);
//Now, build the QUIZ_QUESTIONS record structure
//Now, build the question record structure
$question->category = $new_category_id;
$question->parent = backup_todb($que_info['#']['PARENT']['0']['#']);
$question->name = backup_todb($que_info['#']['NAME']['0']['#']);
@ -214,13 +214,13 @@
////We have to recode the parent field
// This should work alright because we ordered the questions appropriately during backup so that
// questions that can be parents are restored first
if ($question->parent and $parent = backup_getid($restore->backup_unique_code,"quiz_questions",$question->parent)) {
if ($question->parent and $parent = backup_getid($restore->backup_unique_code,"question",$question->parent)) {
$question->parent = $parent->new_id;
}
//Check if the question exists
//by category and stamp
$question_exists = get_record ("quiz_questions","category",$question->category,
$question_exists = get_record ("question","category",$question->category,
"stamp",$question->stamp,"version",$question->version);
//If the question exists, only record its id
@ -229,15 +229,15 @@
$creatingnewquestion = false;
//Else, create a new question
} else {
//The structure is equal to the db, so insert the quiz_questions
$newid = insert_record ("quiz_questions",$question);
//The structure is equal to the db, so insert the question
$newid = insert_record ("question",$question);
$creatingnewquestion = true;
}
//Save newid to backup tables
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_questions",$oldid,
backup_putid($restore->backup_unique_code,"question",$oldid,
$newid);
}
@ -1008,7 +1008,7 @@
$tok = strtok($multianswer->sequence,",");
while ($tok) {
//Get the answer from backup_ids
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$tok);
$question = backup_getid($restore->backup_unique_code,"question",$tok);
if ($question) {
if ($in_first) {
$sequence_field .= $question->new_id;
@ -1419,7 +1419,7 @@
$instance->grade = backup_todb($gra_info['#']['GRADE']['0']['#']);
//We have to recode the question field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$instance->question);
$question = backup_getid($restore->backup_unique_code,"question",$instance->question);
if ($question) {
$instance->question = $question->new_id;
}
@ -1479,19 +1479,19 @@
$version->timestamp = backup_todb($ver_info['#']['TIMESTAMP']['0']['#']);
//We have to recode the oldquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$version->oldquestion);
$question = backup_getid($restore->backup_unique_code,"question",$version->oldquestion);
if ($question) {
$version->oldquestion = $question->new_id;
}
//We have to recode the newquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$version->newquestion);
$question = backup_getid($restore->backup_unique_code,"question",$version->newquestion);
if ($question) {
$version->newquestion = $question->new_id;
}
//We have to recode the originalquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$version->originalquestion);
$question = backup_getid($restore->backup_unique_code,"question",$version->originalquestion);
if ($question) {
$version->newquestion = $question->new_id;
}
@ -1574,7 +1574,7 @@
}
//Set the uniqueid field
$attempt->uniqueid = quiz_new_attempt_uniqueid();
$attempt->uniqueid = question_new_attempt_uniqueid();
//We have to recode the layout field (a list of questions id and pagebreaks)
$attempt->layout = quiz_recode_layout($attempt->layout, $restore);
@ -1597,8 +1597,8 @@
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_attempts",$oldid,
$newid);
//Now process quiz_states
$status = quiz_states_restore_mods($newid,$att_info,$restore);
//Now process question_states
$status = question_states_restore_mods($newid,$att_info,$restore);
} else {
$status = false;
}
@ -1607,14 +1607,14 @@
return $status;
}
//This function restores the quiz_states
function quiz_states_restore_mods($attempt_id,$info,$restore) {
//This function restores the question_states
function question_states_restore_mods($attempt_id,$info,$restore) {
global $CFG;
$status = true;
//Get the quiz_states array
//Get the question_states array
$states = $info['#']['STATES']['0']['#']['STATE'];
//Iterate over states
for($i = 0; $i < sizeof($states); $i++) {
@ -1639,13 +1639,13 @@
$state->penalty = backup_todb($res_info['#']['PENALTY']['0']['#']);
//We have to recode the question field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$state->question);
$question = backup_getid($restore->backup_unique_code,"question",$state->question);
if ($question) {
$state->question = $question->new_id;
}
//We have to recode the originalquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$state->originalquestion);
$question = backup_getid($restore->backup_unique_code,"question",$state->originalquestion);
if ($question) {
$state->originalquestion = $question->new_id;
}
@ -1653,7 +1653,7 @@
//We have to recode the answer field
//It depends of the question type !!
//We get the question first
$question = get_record("quiz_questions","id",$state->question);
$question = get_record("question","id",$state->question);
//It exists
if ($question) {
//Depending of the qtype, we make different recodes
@ -1691,7 +1691,7 @@
break;
case 4: //RANDOM QTYPE
//The answer links to another question id, we must recode it
$answer_link = backup_getid($restore->backup_unique_code,"quiz_questions",$state->answer);
$answer_link = backup_getid($restore->backup_unique_code,"question",$state->answer);
if ($answer_link) {
$state->answer = $answer_link->new_id;
}
@ -1738,7 +1738,7 @@
$question_id = $exploded[0];
$answer_id = $exploded[1];
//Get the question from backup_ids
$que = backup_getid($restore->backup_unique_code,"quiz_questions",$question_id);
$que = backup_getid($restore->backup_unique_code,"question",$question_id);
//Get the answer from backup_ids
$ans = backup_getid($restore->backup_unique_code,"quiz_answers",$answer_id);
if ($que) {
@ -1819,8 +1819,8 @@
$status = false;
}
//The structure is equal to the db, so insert the quiz_states
$newid = insert_record ("quiz_states",$state);
//The structure is equal to the db, so insert the question_states
$newid = insert_record ("question_states",$state);
//Do some output
if (($i+1) % 10 == 0) {
@ -1835,7 +1835,7 @@
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_states",$oldid,
backup_putid($restore->backup_unique_code,"question_states",$oldid,
$newid);
//Now process question type specific state information
$status = quiz_rqp_states_restore_mods($newid,$res_info,$restore);
@ -1862,19 +1862,19 @@
$session->sumpenalty = backup_todb($res_info['#']['SUMPENALTY']['0']['#']);
//We have to recode the question field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$session->questionid);
$question = backup_getid($restore->backup_unique_code,"question",$session->questionid);
if ($question) {
$session->questionid = $question->new_id;
}
//We have to recode the newest field
$state = backup_getid($restore->backup_unique_code,"quiz_states",$session->newest);
$state = backup_getid($restore->backup_unique_code,"question_states",$session->newest);
if ($state) {
$session->newest = $state->new_id;
}
//We have to recode the newgraded field
$state = backup_getid($restore->backup_unique_code,"quiz_states",$session->newgraded);
$state = backup_getid($restore->backup_unique_code,"question_states",$session->newgraded);
if ($state) {
$session->newgraded = $state->new_id;
}
@ -1904,7 +1904,7 @@
$state->persistent_data = backup_todb($rqp_state['#']['PERSISTENT_DATA']['0']['#']);
$state->template_vars = backup_todb($rqp_state['#']['TEMPLATE_VARS']['0']['#']);
//The structure is equal to the db, so insert the quiz_states
//The structure is equal to the db, so insert the question_states
$newid = insert_record ("quiz_rqp_states",$state);
}
@ -1928,7 +1928,7 @@
$state->fraction = backup_todb($essay_state['#']['FRACTION']['0']['#']);
$state->response = backup_todb($essay_state['#']['RESPONSE']['0']['#']);
//The structure is equal to the db, so insert the quiz_states
//The structure is equal to the db, so insert the question_states
$newid = insert_record ("quiz_essay_states",$state);
}
@ -2110,12 +2110,12 @@
$status = true;
//Convert quiz_questions->questiontext
//Convert question->questiontext
if ($records = get_records_sql ("SELECT q.id, q.questiontext, q.questiontextformat
FROM {$CFG->prefix}quiz_questions q,
FROM {$CFG->prefix}question q,
{$CFG->prefix}backup_ids b
WHERE b.backup_code = $restore->backup_unique_code AND
b.table_name = 'quiz_questions' AND
b.table_name = 'question' AND
q.id = b.new_id AND
q.questiontextformat = ".FORMAT_WIKI)) {
foreach ($records as $record) {
@ -2125,7 +2125,7 @@
$wtm = new WikiToMarkdown();
$record->questiontext = $wtm->convert($record->questiontext, $restore->course_id);
$record->questiontextformat = FORMAT_MARKDOWN;
$status = update_record('quiz_questions', addslashes_object($record));
$status = update_record('question', addslashes_object($record));
//Do some output
$i++;
if (($i+1) % 1 == 0) {
@ -2280,7 +2280,7 @@
if ($questionids = explode(',', $layout)) {
foreach ($questionids as $id => $questionid) {
if ($questionid) { // If it iss zero then this is a pagebreak, don't translate
$newq = backup_getid($restore->backup_unique_code,"quiz_questions",$questionid);
$newq = backup_getid($restore->backup_unique_code,"question",$questionid);
$questionids[$id] = $newq->new_id;
}
}

View File

@ -19,7 +19,7 @@
// | | . | | | .
// | | . | | | .
// | | . | | | .
// quiz_responses | quiz_questions quiz_dataset_definitions
// quiz_responses | question quiz_dataset_definitions
// (UL,pk->id, fk->attempt)----------------------------------------------------(CL,pk->id,fk->category,files) (CL,pk->id,fk->category)
// | |
// | |
@ -63,7 +63,7 @@
//This module is special, because we make the restore in two steps:
// 1.-We restore every category and their questions (complete structure). It includes this tables:
// - quiz_categories
// - quiz_questions
// - question
// - quiz_truefalse
// - quiz_shortanswer
// - quiz_multianswer
@ -149,7 +149,7 @@
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_categories",
$category->id, $newid);
//Now restore quiz_questions
//Now restore question
$status = quiz_restore_pre15_questions ($category->id, $newid,$info,$restore);
} else {
$status = false;
@ -182,7 +182,7 @@
//We'll need this later!!
$oldid = backup_todb($que_info['#']['ID']['0']['#']);
//Now, build the QUIZ_QUESTIONS record structure
//Now, build the question record structure
$question->category = $new_category_id;
$question->parent = backup_todb($que_info['#']['PARENT']['0']['#']);
$question->name = backup_todb($que_info['#']['NAME']['0']['#']);
@ -207,7 +207,7 @@
//Although only a few backups can have questions with parent, we try to recode it
//if it contains something
if ($question->parent and $parent = backup_getid($restore->backup_unique_code,"quiz_questions",$question->parent)) {
if ($question->parent and $parent = backup_getid($restore->backup_unique_code,"question",$question->parent)) {
$question->parent = $parent->new_id;
}
@ -223,7 +223,7 @@
//Check if the question exists
//by category and stamp
$question_exists = get_record ("quiz_questions","category",$question->category,
$question_exists = get_record ("question","category",$question->category,
"stamp",$question->stamp);
//If the stamp doesn't exists, check if question exists
//by category, name and questiontext and calculate stamp
@ -231,7 +231,7 @@
if (!$question->stamp) {
$question->stamp = make_unique_id_code();
$question->version = 1;
$question_exists = get_record ("quiz_questions","category",$question->category,
$question_exists = get_record ("question","category",$question->category,
"name",$question->name,
"questiontext",$question->questiontext);
}
@ -242,11 +242,11 @@
$creatingnewquestion = false;
//Else, create a new question
} else {
//The structure is equal to the db, so insert the quiz_questions
$newid = insert_record ("quiz_questions",$question);
//The structure is equal to the db, so insert the question
$newid = insert_record ("question",$question);
//If it is a random question, parent = id
if ($newid && $question->qtype == RANDOM) {
set_field ('quiz_questions', 'parent', $newid, 'id', $newid);
set_field ('question', 'parent', $newid, 'id', $newid);
}
$creatingnewquestion = true;
}
@ -264,7 +264,7 @@
//Save newid to backup tables
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_questions",$oldid,
backup_putid($restore->backup_unique_code,"question",$oldid,
$newid);
}
//If it's a new question in the DB, restore it
@ -946,7 +946,7 @@
$status = true;
//We need some question fields here so we get the full record from DB
$parentquestion = get_record('quiz_questions','id',$new_question_id);
$parentquestion = get_record('question','id',$new_question_id);
//We need to store all the positions with their created questions
//to be able to calculate the sequence field
@ -1003,7 +1003,7 @@
$question->stamp = make_unique_id_code();
//Save the new question to DB
$newid = insert_record('quiz_questions', $question);
$newid = insert_record('question', $question);
if ($newid) {
$createdquestions[$multianswer->positionkey] = $newid;
@ -1029,7 +1029,7 @@
}
}
//If we have created the quiz_questions record, now, depending of the
//If we have created the question record, now, depending of the
//answertype, delegate the restore to every qtype function
if ($newid) {
if ($multianswer->answertype == "1") {
@ -1262,7 +1262,7 @@
$newquestions = array();
if ($questionsarr = explode (",",$quiz->questions)) {
foreach ($questionsarr as $key => $value) {
if ($question = backup_getid($restore->backup_unique_code,"quiz_questions",$value)) {
if ($question = backup_getid($restore->backup_unique_code,"question",$value)) {
$newquestions[] = $question->new_id;
}
}
@ -1350,7 +1350,7 @@
$grade->grade = backup_todb($gra_info['#']['GRADE']['0']['#']);
//We have to recode the question field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$grade->question);
$question = backup_getid($restore->backup_unique_code,"question",$grade->question);
if ($question) {
$grade->question = $question->new_id;
}
@ -1409,13 +1409,13 @@
$version->timestamp = backup_todb($ver_info['#']['TIMESTAMP']['0']['#']);
//We have to recode the oldquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$version->oldquestion);
$question = backup_getid($restore->backup_unique_code,"question",$version->oldquestion);
if ($question) {
$version->oldquestion = $question->new_id;
}
//We have to recode the newquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$version->newquestion);
$question = backup_getid($restore->backup_unique_code,"question",$version->newquestion);
if ($question) {
$version->newquestion = $question->new_id;
}
@ -1499,7 +1499,7 @@
}
//Set the uniqueid field
$attempt->uniqueid = quiz_new_attempt_uniqueid();
$attempt->uniqueid = question_new_attempt_uniqueid();
//The structure is equal to the db, so insert the quiz_attempts
$newid = insert_record ("quiz_attempts",$attempt);
@ -1519,8 +1519,8 @@
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_attempts",$oldid,
$newid);
//Now process quiz_states (old quiz_responses table)
$status = quiz_states_restore_pre15_mods($newid,$att_info,$restore);
//Now process question_states (old quiz_responses table)
$status = question_states_restore_pre15_mods($newid,$att_info,$restore);
} else {
$status = false;
}
@ -1529,8 +1529,8 @@
return $status;
}
//This function restores the quiz_states (old quiz_responses)
function quiz_states_restore_pre15_mods($attempt_id,$info,$restore) {
//This function restores the question_states (old quiz_responses)
function question_states_restore_pre15_mods($attempt_id,$info,$restore) {
global $CFG;
@ -1556,13 +1556,13 @@
$response->grade = backup_todb($res_info['#']['GRADE']['0']['#']);
//We have to recode the question field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$response->question);
$question = backup_getid($restore->backup_unique_code,"question",$response->question);
if ($question) {
$response->question = $question->new_id;
}
//We have to recode the originalquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$response->originalquestion);
$question = backup_getid($restore->backup_unique_code,"question",$response->originalquestion);
if ($question) {
$response->originalquestion = $question->new_id;
}
@ -1573,7 +1573,7 @@
//We have to recode the answer field
//It depends of the question type !!
//We get the question first
$question = get_record("quiz_questions","id",$response->question);
$question = get_record("question","id",$response->question);
//It exists
if ($question) {
//Depending of the qtype, we make different recodes
@ -1611,7 +1611,7 @@
break;
case 4: //RANDOM QTYPE
//The answer links to another question id, we must recode it
$answer_link = backup_getid($restore->backup_unique_code,"quiz_questions",$response->answer);
$answer_link = backup_getid($restore->backup_unique_code,"question",$response->answer);
if ($answer_link) {
$response->answer = $answer_link->new_id;
}
@ -1658,7 +1658,7 @@
$question_id = $exploded[0];
$answer_id = $exploded[1];
//Get the question from backup_ids
$que = backup_getid($restore->backup_unique_code,"quiz_questions",$question_id);
$que = backup_getid($restore->backup_unique_code,"question",$question_id);
//Get the answer from backup_ids
$ans = backup_getid($restore->backup_unique_code,"quiz_answers",$answer_id);
if ($que) {
@ -1709,7 +1709,7 @@
continue;
}
//Calculate question type
$questiondb = get_record('quiz_questions','id',$sequencearr[$counter-1]);
$questiondb = get_record('question','id',$sequencearr[$counter-1]);
$questiontype = $questiondb->qtype;
//Now, depending of the answertype field in quiz_multianswers
//we do diferent things
@ -1751,8 +1751,8 @@
$status = false;
}
//The structure is equal to the db, so insert the quiz_states
$newid = insert_record ("quiz_states",$response);
//The structure is equal to the db, so insert the question_states
$newid = insert_record ("question_states",$response);
//Do some output
if (($i+1) % 10 == 0) {
@ -1767,7 +1767,7 @@
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_states",$oldid,
backup_putid($restore->backup_unique_code,"question_states",$oldid,
$newid);
} else {
$status = false;
@ -1844,12 +1844,12 @@
$status = true;
//Convert quiz_questions->questiontext
//Convert question->questiontext
if ($records = get_records_sql ("SELECT q.id, q.questiontext, q.questiontextformat
FROM {$CFG->prefix}quiz_questions q,
FROM {$CFG->prefix}question q,
{$CFG->prefix}backup_ids b
WHERE b.backup_code = $restore->backup_unique_code AND
b.table_name = 'quiz_questions' AND
b.table_name = 'question' AND
q.id = b.new_id AND
q.questiontextformat = ".FORMAT_WIKI)) {
foreach ($records as $record) {
@ -1859,7 +1859,7 @@
$wtm = new WikiToMarkdown();
$record->questiontext = $wtm->convert($record->questiontext, $restore->course_id);
$record->questiontextformat = FORMAT_MARKDOWN;
$status = update_record('quiz_questions', addslashes_object($record));
$status = update_record('question', addslashes_object($record));
//Do some output
$i++;
if (($i+1) % 1 == 0) {

View File

@ -112,7 +112,7 @@
// load the questions needed by page
$pagelist = $showall ? quiz_questions_in_quiz($attempt->layout) : quiz_questions_on_page($attempt->layout, $page);
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
" FROM {$CFG->prefix}quiz_questions q,".
" FROM {$CFG->prefix}question q,".
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$quiz->id' AND q.id = i.question".
" AND q.id IN ($pagelist)";
@ -121,13 +121,13 @@
}
// Load the question type specific information
if (!quiz_get_question_options($questions)) {
if (!get_question_options($questions)) {
error('Could not load question options');
}
// Restore the question sessions to their most recent states
// creating new sessions where required
if (!$states = quiz_get_states($questions, $quiz, $attempt)) {
if (!$states = get_question_states($questions, $quiz, $attempt)) {
error('Could not restore question sessions');
}
@ -228,13 +228,13 @@
continue;
}
$options = quiz_get_reviewoptions($quiz, $attempt, $isteacher);
$options->validation = QUIZ_EVENTVALIDATE === $states[$i]->event;
$options->validation = QUESTION_EVENTVALIDATE === $states[$i]->event;
$options->history = ($isteacher and !$attempt->preview) ? 'all' : 'graded';
// Print the question
if ($i > 0) {
echo "<br />\n";
}
quiz_print_quiz_question($questions[$i], $states[$i], $number, $quiz, $options);
print_question($questions[$i], $states[$i], $number, $quiz, $options);
$number += $questions[$i]->length;
}

View File

@ -21,7 +21,7 @@
$number = optional_param('number', 0, PARAM_INT); // question number
if ($stateid) {
if (! $state = get_record('quiz_states', 'id', $stateid)) {
if (! $state = get_record('question_states', 'id', $stateid)) {
error('Invalid state id');
}
if (! $attempt = get_record('quiz_attempts', 'id', $state->attempt)) {
@ -33,18 +33,18 @@
}
if (! $neweststateid = get_field('question_sessions', 'newest', 'attemptid', $attempt->uniqueid, 'questionid', $questionid)) {
// newest_state not set, probably because this is an old attempt from the old quiz module code
if (! $state = get_record('quiz_states', 'question', $questionid, 'attempt', $attempt->uniqueid)) {
if (! $state = get_record('question_states', 'question', $questionid, 'attempt', $attempt->uniqueid)) {
error('Invalid question id');
}
} else {
if (! $state = get_record('quiz_states', 'id', $neweststateid)) {
if (! $state = get_record('question_states', 'id', $neweststateid)) {
error('Invalid state id');
}
}
} else {
error('Parameter missing');
}
if (! $question = get_record('quiz_questions', 'id', $state->question)) {
if (! $question = get_record('question', 'id', $state->question)) {
error('Question for this state is missing');
}
if (! $quiz = get_record('quiz', 'id', $attempt->quiz)) {
@ -102,11 +102,11 @@
$question->name_prefix = 'r';
$QTYPES[$question->qtype]->get_question_options($question);
quiz_restore_state($question, $state);
restore_question_state($question, $state);
$state->last_graded = $state;
$options = quiz_get_reviewoptions($quiz, $attempt, $isteacher);
$options->validation = ($state->event == QUIZ_EVENTVALIDATE);
$options->validation = ($state->event == QUESTION_EVENTVALIDATE);
$options->history = 'all';
/// Print infobox
@ -138,7 +138,7 @@
print_table($table);
}
quiz_print_quiz_question($question, $state, $number, $quiz, $options);
print_question($question, $state, $number, $quiz, $options);
print_footer();

View File

@ -5,7 +5,7 @@
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2006022200; // The (date) version of this module
$module->version = 2006022402; // The (date) version of this module
$module->requires = 2006022400; // Requires this Moodle version
$module->cron = 0; // How often should cron check this module (seconds)?

View File

@ -104,7 +104,7 @@ class quiz_category_object {
function initialize() {
/// Get the existing categories
if (!$this->defaultcategory = quiz_get_default_category($this->course->id)) {
if (!$this->defaultcategory = get_default_question_category($this->course->id)) {
error("Error: Could not find or make a category!");
}
@ -485,7 +485,7 @@ class quiz_category_object {
* @return array categorytree a hierarchical list of the categories
*/
function arrange_categories($records) {
//todo: get the question count for all records with one sql statement: select category, count(*) from quiz_questions group by category
//TODO: get the question count for all records with one sql statement: select category, count(*) from question group by category
$levels = array();
// build a levels array, which places each record according to it's depth from the top level
@ -512,7 +512,7 @@ class quiz_category_object {
for ($index = count($levels) - 1; $index >= 0; $index--) {
foreach($levels[$index] as $key) {
$parentkey = $records[$key]->parent;
if (!($records[$key]->questioncount = count_records('quiz_questions', 'category', $records[$key]->id, 'hidden', 0, 'parent', '0'))) {
if (!($records[$key]->questioncount = count_records('question', 'category', $records[$key]->id, 'hidden', 0, 'parent', '0'))) {
$records[$key]->questioncount = 0;
}
if ($parentkey == 0) {
@ -581,13 +581,13 @@ class quiz_category_object {
if (!$category2 = get_record("quiz_categories", "id", $destcategoryid)) { // security
error("No such category $destcategoryid!", "category.php?id={$this->course->id}");
}
if (! set_field('quiz_questions', 'category', $category2, 'category', $category1)) {
if (! set_field('question', 'category', $category2, 'category', $category1)) {
error("Error while moving questions from category '$category->name' to '$category2->name'", "category.php?id={$this->course->id}");
}
} else {
// todo: delete any hidden questions that are not actually in use any more
if ($count = count_records("quiz_questions", "category", $category->id)) {
if ($count = count_records("question", "category", $category->id)) {
$vars->name = $category->name;
$vars->count = $count;
print_simple_box(get_string("categorymove", "quiz", $vars), "center");

View File

@ -47,7 +47,7 @@ function question_category_form($course, $current, $recurse=1, $showhidden=false
/// Make sure the default category exists for this course
if (!$categories = get_records("quiz_categories", "course", $course->id, "id ASC")) {
if (!$category = quiz_get_default_category($course->id)) {
if (!$category = get_default_question_category($course->id)) {
notify("Error creating a default category!");
}
}
@ -196,17 +196,17 @@ function question_list($course, $categoryid, $quizid,
// hide-feature
$showhidden = $showhidden ? '' : " AND hidden = '0'";
if (!$totalnumber = count_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden")) {
if (!$totalnumber = count_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden")) {
echo "<p align=\"center\">";
print_string("noquestions", "quiz");
echo "</p>";
return;
}
if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', $page*$perpage, $perpage)) {
if (!$questions = get_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', $page*$perpage, $perpage)) {
// There are no questions on the requested page.
$page = 0;
if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', 0, $perpage)) {
if (!$questions = get_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', 0, $perpage)) {
// There are no questions at all
echo "<p align=\"center\">";
print_string("noquestions", "quiz");
@ -267,7 +267,7 @@ function question_list($course, $categoryid, $quizid,
echo "<td>".$question->name."</td>\n";
}
echo "<td align=\"center\">\n";
quiz_print_question_icon($question, $canedit);
print_question_icon($question, $canedit);
echo "</td>\n";
echo "</tr>\n";
}

View File

@ -64,7 +64,7 @@
}
// Load the question information
if (!$questions = get_records('quiz_questions', 'id', $id)) {
if (!$questions = get_records('question', 'id', $id)) {
error('Could not load question');
}
if ($maxgrade = get_field('quiz_question_instances', 'grade', 'quiz', $quiz->id, 'question', $id)) {
@ -86,7 +86,7 @@
$quiz->course = $category->course;
// Load the question type specific information
if (!quiz_get_question_options($questions)) {
if (!get_question_options($questions)) {
error(get_string('newattemptfail', 'quiz'));
}
@ -101,7 +101,7 @@
$attempt->timestart = $timenow;
$attempt->timefinish = 0;
$attempt->timemodified = $timenow;
$attempt->uniqueid = quiz_new_attempt_uniqueid();
$attempt->uniqueid = question_new_attempt_uniqueid();
$attempt->id = 0;
// Restore the history of question sessions from the moodle session or create
@ -122,7 +122,7 @@
$SESSION->quizpreview->questionid = $id;
// Create an empty session for the question
if (!$newstates =
quiz_get_states($questions, $quiz, $attempt)) {
get_question_states($questions, $quiz, $attempt)) {
error(get_string('newattemptfail', 'quiz'));
}
$SESSION->quizpreview->states = array($newstates);
@ -149,11 +149,11 @@
unset($form['back']);
unset($form['startagain']);
$event = $finishattempt ? QUIZ_EVENTCLOSE : ($markall ? QUIZ_EVENTGRADE : QUIZ_EVENTSAVE);
if ($actions = quiz_extract_responses($questions, $form, $event)) {
$event = $finishattempt ? QUESTION_EVENTCLOSE : ($markall ? QUESTION_EVENTGRADE : QUESTION_EVENTSAVE);
if ($actions = question_extract_responses($questions, $form, $event)) {
$actions[$id]->timestamp = 0; // We do not care about timelimits here
quiz_process_responses($questions[$id], $states[$historylength][$id], $actions[$id], $quiz, $attempt);
if (QUIZ_EVENTGRADE != $curstate->event && QUIZ_EVENTCLOSE != $curstate->event) {
question_process_responses($questions[$id], $states[$historylength][$id], $actions[$id], $quiz, $attempt);
if (QUESTION_EVENTGRADE != $curstate->event && QUESTION_EVENTCLOSE != $curstate->event) {
// Update the current state rather than creating a new one
$historylength--;
unset($states[$historylength]);
@ -193,7 +193,7 @@
echo "<input type=\"hidden\" name=\"quizid\" value=\"$quizid\" />\n";
echo "<input type=\"hidden\" name=\"continue\" value=\"1\" />\n";
quiz_print_quiz_question($questions[$id], $curstate, $number, $quiz, $options);
print_question($questions[$id], $curstate, $number, $quiz, $options);
echo '<br />';
echo '<center>';

View File

@ -38,7 +38,7 @@
}
if ($id) {
if (! $question = get_record("quiz_questions", "id", $id)) {
if (! $question = get_record("question", "id", $id)) {
error("This question doesn't exist");
}
if (!empty($category)) {
@ -77,7 +77,7 @@
}
if(!empty($id) && isset($_REQUEST['hide']) && confirm_sesskey()) {
if(!set_field('quiz_questions', 'hidden', $_REQUEST['hide'], 'id', $id)) {
if(!set_field('question', 'hidden', $_REQUEST['hide'], 'id', $id)) {
error("Faild to hide the question.");
}
redirect($editurl);
@ -111,15 +111,15 @@
if (isset($confirm) and confirm_sesskey()) {
if ($confirm == md5($delete)) {
if (record_exists('quiz_question_instances', 'question', $question->id) or
record_exists('quiz_states', 'originalquestion', $question->id)) {
if (!set_field('quiz_questions', 'hidden', 1, 'id', $delete)) {
record_exists('question_states', 'originalquestion', $question->id)) {
if (!set_field('question', 'hidden', 1, 'id', $delete)) {
error('Was not able to hide question');
}
} else {
if (!delete_records("quiz_questions", "id", $question->id)) {
if (!delete_records("question", "id", $question->id)) {
error("An error occurred trying to delete question (id $question->id)");
}
if (!delete_records("quiz_questions", "parent", $question->id)) {
if (!delete_records("question", "parent", $question->id)) {
error("An error occurred trying to delete question (id $question->id)");
}
}
@ -180,8 +180,8 @@
} else {
// this should be improved to exclude teacher preview responses and empty responses
// the current code leaves many unneeded questions in the database
$hasresponses = record_exists('quiz_states', 'question', $form->id) or
record_exists('quiz_states', 'originalquestion', $form->id);
$hasresponses = record_exists('question_states', 'question', $form->id) or
record_exists('question_states', 'originalquestion', $form->id);
$replaceinall = ($quizlist == $replaceinquiz); // question is being replaced in all quizzes
$replaceold = !$hasresponses && $replaceinall;
}
@ -189,7 +189,7 @@
if (!$replaceold) { // create a new question
$oldquestionid = $question->id;
if (!$makecopy) {
if (!set_field("quiz_questions", 'hidden', 1, 'id', $question->id)) {
if (!set_field("question", 'hidden', 1, 'id', $question->id)) {
error("Could not hide question!");
}
}
@ -251,10 +251,10 @@
}
// set originalquestion in states
set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->uniqueid, 'question', $question->id, 'originalquestion', '0');
set_field('question_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->uniqueid, 'question', $question->id, 'originalquestion', '0');
// replace question id in states
set_field('quiz_states', 'question', $question->id, 'attempt', $attempt->uniqueid, 'question', $oldquestionid);
set_field('question_states', 'question', $question->id, 'attempt', $attempt->uniqueid, 'question', $oldquestionid);
// replace question id in sessions
set_field('question_sessions', 'questionid', $question->id, 'attemptid', $attempt->uniqueid, 'questionid', $oldquestionid);

View File

@ -69,7 +69,7 @@ class quiz_dataset_dependent_questiontype extends quiz_default_questiontype {
$state->responses[''];
// Set the legacy answer field
if (!set_field('quiz_states', 'answer', $responses, 'id',
if (!set_field('question_states', 'answer', $responses, 'id',
$state->id)) {
return false;
}

View File

@ -178,7 +178,7 @@ class quiz_essay_qtype extends quiz_default_questiontype {
$state->options->graded = 1;
} else {
$state->raw_grade = 0;
$state->event = QUIZ_EVENTSUBMIT;
$state->event = QUESTION_EVENTSUBMIT;
}
// Make sure we don't assign negative or too high marks
@ -267,7 +267,7 @@ class quiz_essay_qtype extends quiz_default_questiontype {
// get the essay questions
$questionlist = quiz_questions_in_quiz($cmoptions->questions);
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
" FROM {$CFG->prefix}quiz_questions q,".
" FROM {$CFG->prefix}question q,".
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$cmoptions->id' AND q.id = i.question".
" AND q.id IN ($questionlist)".

View File

@ -20,7 +20,7 @@
}
$i = count($subquestions);
$limit = QUIZ_MAX_NUMBER_ANSWERS;
$limit = QUESTION_NUMANS;
$limit = $limit <= $i ? $i+1 : $limit;
for (; $i < $limit; $i++) {
$subquestions[] = ""; // Make question slots, default as blank

View File

@ -191,7 +191,7 @@ class quiz_match_qtype extends quiz_default_questiontype {
$responses = implode(',', $responses);
// Set the legacy answer field
if (!set_field('quiz_states', 'answer', $responses, 'id',
if (!set_field('question_states', 'answer', $responses, 'id',
$state->id)) {
return false;
}

View File

@ -40,7 +40,7 @@
}
$parsableanswerdef .= '}';
// Fix the questiontext fields of old questions
set_field('quiz_questions', 'questiontext', addslashes($parsableanswerdef), 'id', $wrapped->id);
set_field('question', 'questiontext', addslashes($parsableanswerdef), 'id', $wrapped->id);
} else {
$parsableanswerdef = str_replace('&#', '&\#', $wrapped->questiontext);
}

View File

@ -28,7 +28,7 @@ class quiz_embedded_cloze_qtype extends quiz_default_questiontype {
return false;
}
$wrappedquestions = get_records_list('quiz_questions', 'id', $sequence);
$wrappedquestions = get_records_list('question', 'id', $sequence);
// We want an array with question ids as index and the positions as values
$sequence = array_flip(explode(',', $sequence));
@ -59,7 +59,7 @@ class quiz_embedded_cloze_qtype extends quiz_default_questiontype {
// will also create difficulties if questiontype specific tables reference the id.
// First we get all the existing wrapped questions
if (!$oldwrappedids = get_records('quiz_questions', 'parent', $question->id, '', 'id, id')) {
if (!$oldwrappedids = get_records('question', 'parent', $question->id, '', 'id, id')) {
// We need to select 'id, id' because the first one is consumed by
// get_records.
$oldwrappedids = array();
@ -82,7 +82,7 @@ class quiz_embedded_cloze_qtype extends quiz_default_questiontype {
// Delete redundant wrapped questions
$oldwrappedids = implode(',', $oldwrappedids);
delete_records_select('quiz_questions', "id IN ($oldwrappedids)");
delete_records_select('question', "id IN ($oldwrappedids)");
if (!empty($sequence)) {
$multianswer = new stdClass;
@ -158,7 +158,7 @@ class quiz_embedded_cloze_qtype extends quiz_default_questiontype {
$responses = implode(',', $responses);
// Set the legacy answer field
if (!set_field('quiz_states', 'answer', $responses, 'id',
if (!set_field('question_states', 'answer', $responses, 'id',
$state->id)) {
return false;
}

View File

@ -19,7 +19,7 @@
}
$i = count($answers);
$limit = QUIZ_MAX_NUMBER_ANSWERS;
$limit = QUESTION_NUMANS;
$limit = $limit <= $i ? $i+1 : $limit;
for (; $i < $limit; $i++) {
$answers[] = ""; // Make answer slots, default as blank

View File

@ -227,7 +227,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
$responses .= implode(',', $state->responses);
// Set the legacy answer field
if (!set_field('quiz_states', 'answer', $responses, 'id',
if (!set_field('question_states', 'answer', $responses, 'id',
$state->id)) {
return false;
}
@ -267,7 +267,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
$questiontext = format_text($question->questiontext,
$question->questiontextformat,
NULL, $cmoptions->course);
$image = quiz_get_image($question, $cmoptions->course);
$image = get_question_image($question, $cmoptions->course);
$answerprompt = ($question->options->single) ? get_string('singleanswer', 'quiz') :
get_string('multipleanswers', 'quiz');

View File

@ -25,7 +25,7 @@ class quiz_numerical_qtype extends quiz_shortanswer_qtype {
function get_question_options(&$question) {
// Get the question answers and their respective tolerances
// Note: quiz_numerical is an extension of the answer table rather than
// the quiz_questions table as is usually the case for qtype
// the question table as is usually the case for qtype
// specific tables.
global $CFG;
if (!$question->options->answers = get_records_sql(

View File

@ -82,12 +82,12 @@ class quiz_default_questiontype {
if (!empty($question->id)) { // Question already exists
$question->version ++; // Update version number of question
if (!update_record("quiz_questions", $question)) {
if (!update_record("question", $question)) {
error("Could not update question!");
}
} else { // Question is a new one
$question->version = 1;
if (!$question->id = insert_record("quiz_questions", $question)) {
if (!$question->id = insert_record("question", $question)) {
error("Could not insert new question!");
}
}
@ -240,7 +240,7 @@ class quiz_default_questiontype {
// Most question types with only a single form field for the student's response
// will use the empty string '' as the index for that one response. This will
// automatically be stored in and restored from the answer field in the
// quiz_states table.
// question_states table.
$state->responses = array('' => '');
return true;
}
@ -255,7 +255,7 @@ class quiz_default_questiontype {
*
* Question types with only a single form field for the student's response
* will not need not restore the responses; the value of the answer
* field in the quiz_states table is restored to ->responses['']
* field in the question_states table is restored to ->responses['']
* before this function is called. Question types with more response fields
* should override this method and set the ->responses field to an
* associative array of responses.
@ -278,13 +278,13 @@ class quiz_default_questiontype {
* This function saves the question type specific session data from the
* state object to the database. In particular for most question types it saves the
* responses from the ->responses member of the state object. The question type
* non-specific data for the state has already been saved in the quiz_states
* non-specific data for the state has already been saved in the question_states
* table and the state object contains the corresponding id and
* sequence number which may be used to index a question type specific table.
*
* Question types with only a single form field for the student's response
* which is contained in ->responses[''] will not have to save this response,
* it will already have been saved to the answer field of the quiz_states table.
* it will already have been saved to the answer field of the question_states table.
* Question types with more response fields should override this method and save
* the responses in their own database tables.
* @return bool Indicates success or failure.
@ -465,7 +465,7 @@ class quiz_default_questiontype {
$grade = '';
if ($question->maxgrade and $options->scores) {
if ($cmoptions->optionflags & QUIZ_ADAPTIVE) {
$grade = (!$state->last_graded->event == QUIZ_EVENTGRADE) ? '--/' : round($state->last_graded->grade, $cmoptions->decimalpoints).'/';
$grade = (!$state->last_graded->event == QUESTION_EVENTGRADE) ? '--/' : round($state->last_graded->grade, $cmoptions->decimalpoints).'/';
}
$grade .= $question->maxgrade;
}
@ -474,10 +474,10 @@ class quiz_default_questiontype {
if(isset($options->history) and $options->history) {
if ($options->history == 'all') {
// show all states
$states = get_records_select('quiz_states', "attempt = '$state->attempt' AND question = '$question->id' AND event > '0'", 'seq_number DESC');
$states = get_records_select('question_states', "attempt = '$state->attempt' AND question = '$question->id' AND event > '0'", 'seq_number DESC');
} else {
// show only graded states
$states = get_records_select('quiz_states', "attempt = '$state->attempt' AND question = '$question->id' AND event = '".QUIZ_EVENTGRADE."'", 'seq_number DESC');
$states = get_records_select('question_states', "attempt = '$state->attempt' AND question = '$question->id' AND event = '".QUESTION_EVENTGRADE."'", 'seq_number DESC');
}
if (count($states) > 1) {
$strreviewquestion = get_string('reviewresponse', 'quiz');
@ -538,12 +538,12 @@ class quiz_default_questiontype {
attempt and displays the overall grade obtained counting all previous
responses (and penalties) */
if (QUIZ_EVENTDUPLICATEGRADE == $state->event) {
if (QUESTION_EVENTDUPLICATEGRADE == $state->event) {
echo ' ';
print_string('duplicateresponse', 'quiz');
}
if (!empty($question->maxgrade) && $options->scores) {
if ($state->last_graded->event == QUIZ_EVENTGRADE) {
if ($state->last_graded->event == QUESTION_EVENTGRADE) {
// Display the grading details from the last graded state
$grade->cur = round($state->last_graded->grade, $cmoptions->decimalpoints);
$grade->max = $question->maxgrade;
@ -573,7 +573,7 @@ class quiz_default_questiontype {
}
// print info about new penalty
// penalty is relevant only if the answer is not correct and further attempts are possible
if (($state->last_graded->raw_grade < $question->maxgrade) and (QUIZ_EVENTCLOSE !== $state->event)) {
if (($state->last_graded->raw_grade < $question->maxgrade) and (QUESTION_EVENTCLOSE !== $state->event)) {
if ('' !== $state->last_graded->penalty && ((float)$state->last_graded->penalty) > 0.0) {
// A penalty was applied so display it
print_string('gradingdetailspenalty', 'quiz', $state->last_graded->penalty);
@ -745,7 +745,7 @@ class quiz_default_questiontype {
* must be updated. The method is able to
* close the question session (preventing any further
* attempts at this question) by setting
* $state->event to QUIZ_EVENTCLOSE.
* $state->event to QUESTION_EVENTCLOSE.
* @param object $cmoptions
*/
function grade_responses(&$question, &$state, $cmoptions) {
@ -887,7 +887,7 @@ class quiz_default_questiontype {
$students = array();
if($attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'")) {
foreach($attempts as $attempt) {
if (record_exists('quiz_states', 'attempt', $attempt->uniqueid, 'question', $question->id, 'originalquestion', 0)) {
if (record_exists('question_states', 'attempt', $attempt->uniqueid, 'question', $question->id, 'originalquestion', 0)) {
$students[$attempt->userid] = 1;
}
}

View File

@ -27,7 +27,7 @@ class quiz_random_qtype extends quiz_default_questiontype {
function save_question_options($question) {
// No options, but we use the parent field to hide random questions.
// To avoid problems we set the parent field to the question id.
return (set_field('quiz_questions', 'parent', $question->id, 'id',
return (set_field('question', 'parent', $question->id, 'id',
$question->id) ? true : false);
}
@ -54,7 +54,7 @@ class quiz_random_qtype extends quiz_default_questiontype {
$categorylist = $question->category;
}
if ($catrandoms = get_records_sql
("SELECT id,id FROM {$CFG->prefix}quiz_questions
("SELECT id,id FROM {$CFG->prefix}question
WHERE category IN ($categorylist)
AND parent = '0'
AND id NOT IN ($cmoptions->questionsinuse)
@ -71,7 +71,7 @@ class quiz_random_qtype extends quiz_default_questiontype {
if (!ereg("(^|,)$wrappedquestion->id(,|$)", $cmoptions->questionsinuse)) {
/// $randomquestion is not in use and will therefore be used
/// as the randomquestion here...
$wrappedquestion = get_record('quiz_questions', 'id', $wrappedquestion->id);
$wrappedquestion = get_record('question', 'id', $wrappedquestion->id);
global $QTYPES;
$QTYPES[$wrappedquestion->qtype]
->get_question_options($wrappedquestion);
@ -119,16 +119,16 @@ class quiz_random_qtype extends quiz_default_questiontype {
return true;
}
// this must be an old-style state which stores only the id for the wrapped question
if (!$wrappedquestion = get_record('quiz_questions', 'id', $state->responses[''])) {
if (!$wrappedquestion = get_record('question', 'id', $state->responses[''])) {
notify("Can not find wrapped question {$state->responses['']}");
}
// In the old model the actual response was stored in a separate entry in
// the state table and fortunately there was only a single state per question
if (!$state->responses[''] = get_field('quiz_states', 'answer', 'attempt', $state->attempt, 'question', $wrappedquestion->id)) {
if (!$state->responses[''] = get_field('question_states', 'answer', 'attempt', $state->attempt, 'question', $wrappedquestion->id)) {
notify("Wrapped state missing");
}
} else {
if (!$wrappedquestion = get_record('quiz_questions', 'id', $answerregs[1])) {
if (!$wrappedquestion = get_record('question', 'id', $answerregs[1])) {
return false;
}
$state->responses[''] = (false === $answerregs[2]) ? '' : $answerregs[2];
@ -161,7 +161,7 @@ class quiz_random_qtype extends quiz_default_questiontype {
// Read what the wrapped question has just set the answer field to
// (if anything)
$response = get_field('quiz_states', 'answer', 'id', $state->id);
$response = get_field('question_states', 'answer', 'id', $state->id);
if(false === $response) {
return false;
}
@ -170,7 +170,7 @@ class quiz_random_qtype extends quiz_default_questiontype {
$response = "random$realqid-$response";
// ... and save it again.
if (!set_field('quiz_states', 'answer', addslashes($response), 'id', $state->id)) {
if (!set_field('question_states', 'answer', addslashes($response), 'id', $state->id)) {
return false;
}

View File

@ -181,7 +181,7 @@ class quiz_randomsamatch_qtype extends quiz_match_qtype {
$state->responses = array();
foreach ($responses as $response) {
$state->responses[$response[0]] = $response[1];
if (!$wrappedquestion = get_record('quiz_questions', 'id',
if (!$wrappedquestion = get_record('question', 'id',
$response[0])) {
notify("Couldn't get question (id=$response[0])!");
return false;
@ -234,7 +234,7 @@ class quiz_randomsamatch_qtype extends quiz_match_qtype {
}
function get_sa_candidates($categorylist, $questionsinuse=0) {
return get_records_select('quiz_questions',
return get_records_select('question',
"qtype = '".SHORTANSWER."' " .
"AND category IN ($categorylist) " .
"AND parent = '0' " .

View File

@ -84,7 +84,7 @@
} else if ($numberavailable < 6) {
$maxrandom = $numberavailable;
} else {
$maxrandom = QUIZ_MAX_NUMBER_ANSWERS;
$maxrandom = QUESTION_NUMANS;
}
for ($i=2;$i<=$maxrandom;$i++) {
$menu[$i] = $i;

View File

@ -370,13 +370,13 @@ class quiz_rqp_qtype extends quiz_default_questiontype {
* must be updated. The method is able to
* close the question session (preventing any further
* attempts at this question) by setting
* $state->event to QUIZ_EVENTCLOSE.
* $state->event to QUESTION_EVENTCLOSE.
* @param object $cmoptions
*/
function grade_responses(&$question, &$state, $cmoptions) {
// Perform the grading and rendering
$output = remote_render($question, $state, QUIZ_EVENTGRADE == $state->event
|| QUIZ_EVENTCLOSE == $state->event, 'normal');
$output = remote_render($question, $state, QUESTION_EVENTGRADE == $state->event
|| QUESTION_EVENTCLOSE == $state->event, 'normal');
if (false === $output || is_soap_fault($output)) {
unset($output);
return false;

View File

@ -16,7 +16,7 @@
}
$i = count($answers);
$limit = QUIZ_MAX_NUMBER_ANSWERS;
$limit = QUESTION_NUMANS;
$limit = $limit <= $i ? $i+1 : $limit;
for (; $i < $limit; $i++) {
$answers[] = ""; // Make answer slots, default as blank

View File

@ -131,7 +131,7 @@ class quiz_shortanswer_qtype extends quiz_default_questiontype {
$questiontext = format_text($question->questiontext,
$question->questiontextformat,
NULL, $cmoptions->course);
$image = quiz_get_image($question, $cmoptions->course);
$image = get_question_image($question, $cmoptions->course);
/// Print input controls

View File

@ -143,7 +143,7 @@ class quiz_truefalse_qtype extends quiz_default_questiontype {
$questiontext = format_text($question->questiontext,
$question->questiontextformat,
NULL, $cmoptions->course);
$image = quiz_get_image($question, $cmoptions->course);
$image = get_question_image($question, $cmoptions->course);
$answers = &$question->options->answers;
$trueanswer = &$answers[$question->options->trueanswer];

View File

@ -48,7 +48,7 @@
foreach ($_POST as $key => $value) { // Parse input for question ids
if (substr($key, 0, 1) == "q") {
$key = substr($key,1);
if (!set_field('quiz_questions', 'category', $tocategory->id, 'id', $key)) {
if (!set_field('question', 'category', $tocategory->id, 'id', $key)) {
error('Could not update category field');
}
}
@ -63,12 +63,12 @@
// for each question either hide it if it is in use or delete it
foreach ($questionlist as $questionid) {
if (record_exists('quiz_question_instances', 'question', $questionid) or
record_exists('quiz_states', 'originalquestion', $questionid)) {
if (!set_field('quiz_questions', 'hidden', 1, 'id', $questionid)) {
record_exists('question_states', 'originalquestion', $questionid)) {
if (!set_field('question', 'hidden', 1, 'id', $questionid)) {
error('Was not able to hide question');
}
} else {
delete_records("quiz_questions", "id", $questionid);
delete_records("question", "id", $questionid);
}
}
}
@ -89,11 +89,11 @@
$key = substr($key,1);
$questionlist .= $key.',';
if (record_exists('quiz_question_instances', 'question', $key) or
record_exists('quiz_states', 'originalquestion', $key)) {
record_exists('question_states', 'originalquestion', $key)) {
$questionnames .= '* ';
$inuse = true;
}
$questionnames .= get_field('quiz_questions', 'name', 'id', $key).'<br />';
$questionnames .= get_field('question', 'name', 'id', $key).'<br />';
}
}
if (!$questionlist) { // no questions were selected
@ -131,7 +131,7 @@
/// all commands have been dealt with, now print the page
if (empty($SESSION->questioncat) or !record_exists('quiz_categories', 'id', $SESSION->questioncat)) {
$category = quiz_get_default_category($course->id);
$category = get_default_question_category($course->id);
$SESSION->questioncat = $category->id;
}
if (!isset($SESSION->questionrecurse)) {