quiz_upgrade_states() now creates entries in the quiz_newest_states table only for states that are associated to those questions that are listed in $attempt->layout.

This commit is contained in:
gustav_delius
2005-05-16 19:21:34 +00:00
parent e55b73fdb7
commit 1f48479ebf
2 changed files with 51 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
<!DOCTYPE HTML PUBLIC> <HTML>
<HEAD>
<TITLE>Database tables</TITLE>
<META http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<!--LINK rel="Stylesheet" type="text/css" href="doc.css"-->
</HEAD>
<BODY>
<h1>Database tables</h1>
<h2>quiz_newest_states</h2>
This table exists only for efficiency reasons:
<ol>
<li>Via its 'newest' and 'newgraded' fields it gives attempt.php
a way to quickly find the newest state
and the newest graded state for an attempt. It allows the
construction of SQL to select all the states that need to be loaded
on attempt.php or review.php.</li>
<li>Via its 'sumpenalty' field it gives quiz_apply_penalty() a quick
way for getting at the accummulated penalty that needs to be applied.
Without this field the penalties from all previous graded states
would have to be added up each time. Not a big deal actually because
this could be achieved with a single SQL query (using SUM) but this
field was introduced when we still had the multiplicative penalty
scheme around which would have been more difficult to recompute.</li>
</ol>
This table was introduced in Moodle 1.5 and is not populated for all
states during the upgrade because on sites with a lot of existing
states that could take too long. Rather it is done whenever needed
by quiz_upgrade_states().
</BODY> </HTML>
+16 -1
View File
@@ -2525,13 +2525,28 @@ function quiz_get_reviewoptions($quiz, $attempt, $isteacher=false) {
/**
* Upgrade states for an attempt to Moodle 1.5 model
*
* Any state that does not yet have its timestamp set to nonzero has not yet been upgraded from Moodle 1.4
* The reason these are still around is that for large sites it would have taken too long to
* upgrade all states at once. This function sets the timestamp field and creates an entry in the
* quiz_newest_states table.
* @param object $attempt The attempt whose states need upgrading
*/
function quiz_upgrade_states($attempt) {
global $CFG;
// The old quiz model only allowed a single response per quiz attempt so that there will be
// 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->id'", false);
// For each state we create an entry in the quiz_newest_states table, with both newest and
// newgraded pointing to this state.
// Actually we only do this for states whose question is actually listed in $attempt->layout.
// We do not do it for states associated to wrapped questions like for example the questions
// used by a RANDOM question
$newest->attemptid = $attempt->id;
if ($states = get_records('quiz_states', 'attempt', $attempt->id)) {
$questionlist = quiz_questions_in_quiz($attempt->layout);
if ($states = get_records_select('quiz_states', "attempt = '$attempt->id' AND question IN ($questionlist)")) {
foreach ($states as $state) {
$newest->newgraded = $state->id;
$newest->newest = $state->id;