Change to when newly created states get saved

Changes to what is printed during regrade
This commit is contained in:
gustav_delius
2005-06-05 11:49:32 +00:00
parent 5eab4b5c43
commit 52fa982eba
5 changed files with 65 additions and 47 deletions
+3 -3
View File
@@ -311,11 +311,11 @@ $string['reattemptquiz'] = 'Re-attempt quiz';
$string['recentlyaddedquestion'] = 'Recently added question!';
$string['recurse'] = 'Display questions from sub-categories too';
$string['regrade'] = 'Regrade all attempts';
$string['regradeattempt'] = 'Regrading attempt #{$a->attempt}, $a->statecount states are being regraded';
$string['regradecomplete'] = 'All attempts have been regraded';
$string['regradecount'] = '$a->changed out of $a->attempt grades were changed';
$string['regradedone'] = 'done. Changed grades for $a->changed states out of $a->statecount.';
$string['regradequiz'] = 'Regrading Quiz $a->name';
$string['regradedisplayexplanation'] = 'Attempts that change during regrading are displayed as hyperlinks to the question review window';
$string['regradingquestion'] = 'Regrading \"$a\".';
$string['regradingquiz'] = 'Regrading Quiz \"$a\"';
$string['relative'] = 'Relative';
$string['remove'] = 'Remove';
$string['rename'] = 'Rename';
+9 -10
View File
@@ -216,13 +216,13 @@
// list of questions needed by page
$pagelist = quiz_questions_on_page($attempt->layout, $page);
// add all questions that are on the submitted form
if ($newattempt) {
$questionlist = $attempt->layout;
$questionlist = quiz_questions_in_quiz($attempt->layout);
} else {
$questionlist = $pagelist;
}
// add all questions that are on the submitted form
if ($questionids) {
$questionlist .= ','.$questionids;
}
@@ -253,6 +253,13 @@
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]);
}
}
/// Process form data /////////////////////////////////////////////////
@@ -437,14 +444,6 @@
quiz_save_question_session($questions[$i], $states[$i]);
$number += $questions[$i]->length;
}
if ($newattempt) {
$questionlist = explode(',', $attempt->layout);
foreach ($questionlist as $i) {
if ($i != 0) {
quiz_save_question_session($questions[$i], $states[$i]);
}
}
}
/// Print the submit buttons
+36 -21
View File
@@ -1492,6 +1492,8 @@ function quiz_regrade_question_in_attempt($question, $attempt, $quiz=false, $ver
"AND question = '{$question->id}'",
'seq_number ASC')) {
$states = array_values($states);
// what is this for?
$attempt->sumgrades -= $states[count($states)-1]->grade;
// Initialise the replaystate
@@ -1499,14 +1501,8 @@ function quiz_regrade_question_in_attempt($question, $attempt, $quiz=false, $ver
$states[0]->sumpenalty = 0.0;
$replaystate = clone($states[0]);
$replaystate->last_graded = clone($states[0]);
if ($verbose) {
$a = new stdClass;
$a->attempt = $attempt->id;
$a->statecount = count($states);
print_string('regradeattempt', 'quiz', $a);
echo " . ";
}
$a->changed = 0;
$changed = 0;
$oldgrade = 0;
for($j = 1; $j < count($states); $j++) {
quiz_restore_state($question, $states[$j]);
@@ -1534,17 +1530,23 @@ function quiz_regrade_question_in_attempt($question, $attempt, $quiz=false, $ver
}
if ((float)$replaystate->raw_grade != (float)$states[$j]->raw_grade) {
$a->changed++;
}
$changed++;
$verbose && print(". "); // Progress indicator
}
$replaystate->id = $states[$j]->id;
update_record('quiz_states', $replaystate);
}
update_record('quiz_attempts', $attempt);
if ($verbose) {
if ($changed) {
link_to_popup_window ('/mod/quiz/reviewquestion.php?attempt='.$attempt->id.'&amp;question='.$question->id,
'reviewquestion', ' #'.$attempt->id, 450, 550, get_string('reviewresponse', 'quiz'));
} else {
echo ' #'.$attempt->id;
}
echo "\n"; flush(); ob_flush();
}
quiz_save_best_grade($quiz, $attempt->userid);
$verbose && print_string('regradedone', 'quiz', $a);
$verbose && print("<br />");
return true;
}
return true;
@@ -2235,7 +2237,7 @@ if (!$grade = get_record('quiz_grades', 'quiz', $quiz->id, 'userid', $userid)) {
}
/**
* TODO: document this
* Save the overall grade for a user at a quiz in the quiz_grades table
*
* @return boolean Indicates success or failure.
* @param object $quiz The quiz for which the best grade is to be calculated
@@ -2260,11 +2262,12 @@ function quiz_save_best_grade($quiz, $userid=null) {
// Calculate the best grade
$bestgrade = quiz_calculate_best_grade($quiz, $attempts);
$bestgrade = (($bestgrade / $quiz->sumgrades) * $quiz->grade);
$bestgrade = round($bestgrade, $quiz->decimalpoints);
// Save the best grade in the database
if ($grade = get_record('quiz_grades', 'quiz', $quiz->id, 'userid',
$userid)) {
$grade->grade = round($bestgrade, $quiz->decimalpoints);
$grade->grade = $bestgrade;
$grade->timemodified = time();
if (!update_record('quiz_grades', $grade)) {
notify('Could not update best grade');
@@ -2273,7 +2276,7 @@ function quiz_save_best_grade($quiz, $userid=null) {
} else {
$grade->quiz = $quiz->id;
$grade->userid = $userid;
$grade->grade = round($bestgrade, $quiz->decimalpoints);
$grade->grade = $bestgrade;
$grade->timemodified = time();
if (!insert_record('quiz_grades', $grade)) {
notify('Could not insert new best grade');
@@ -2283,9 +2286,14 @@ function quiz_save_best_grade($quiz, $userid=null) {
return true;
}
/**
* Calculate the overall grade for a quiz given a number of attempts by a particular user.
*
* @return float The overall grade
* @param object $quiz The quiz for which the best grade is to be calculated
* @param array $attempts An array of all the attempts of the user at the quiz
*/
function quiz_calculate_best_grade($quiz, $attempts) {
/// Calculate the best grade for a quiz given a number of attempts by a particular user.
switch ($quiz->grademethod) {
@@ -2322,9 +2330,16 @@ function quiz_calculate_best_grade($quiz, $attempts) {
}
}
/**
* Return the attempt with the best grade for a quiz
*
* Which attempt is the best depends on $quiz->grademethod. If the grade
* method is GRADEAVERAGE then this function simply returns the last attempt.
* @return object The attempt with the best grade
* @param object $quiz The quiz for which the best grade is to be calculated
* @param array $attempts An array of all the attempts of the user at the quiz
*/
function quiz_calculate_best_attempt($quiz, $attempts) {
/// Return the attempt with the best grade for a quiz
switch ($quiz->grademethod) {
+16 -11
View File
@@ -9,18 +9,16 @@ class quiz_report extends quiz_default_report {
function display($quiz, $cm, $course) { /// This function just displays the report
global $CFG, $SESSION, $db, $QUIZ_QTYPES;
$strheading = get_string('regradequiz', 'quiz', $quiz);
$strnoattempts = get_string('noattempts');
// 'There are no attempts for this quiz that could be regraded.';
/// Print header
$this->print_header_and_tabs($cm, $course, $quiz, $reportmode="regrade");
if (!$attempts = get_records('quiz_attempts', 'quiz', $quiz->id)) {
notify($strnoattempts);
/// Fetch all attempts
if (!$attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = 0")) {
print_heading(get_string('noattempts', 'quiz'));
return true;
}
/// Fetch all questions
$sql = "SELECT q.*, i.grade AS maxgrade FROM {$CFG->prefix}quiz_questions q,
{$CFG->prefix}quiz_question_instances i
WHERE i.quiz = $quiz->id
@@ -31,15 +29,22 @@ class quiz_report extends quiz_default_report {
}
quiz_get_question_options($questions);
/// Print heading
print_heading(get_string('regradingquiz', 'quiz', $quiz));
echo '<center>';
print_string('regradedisplayexplanation', 'quiz');
echo '<center>';
print_heading($strheading);
print_simple_box_start('center', '70%');
foreach ($attempts as $attempt) {
foreach ($questions as $question) {
/// Loop through all questions and all attempts and regrade while printing progress info
foreach ($questions as $question) {
echo '<b>'.get_string('regradingquestion', 'quiz', $question->name).'</b> '.get_string('attempts', 'quiz').": \n";
foreach ($attempts as $attempt) {
quiz_regrade_question_in_attempt($question, $attempt, $quiz, true);
}
echo '<br/ >';
// the following makes sure that the output is sent immediately.
flush();ob_flush();
}
print_simple_box_end();
return true;
}
+1 -2
View File
@@ -18,8 +18,7 @@
$stateid = optional_param('state', 0, PARAM_INT); // state id
$attemptid = optional_param('attempt', 0, PARAM_INT); // attempt id
$questionid = optional_param('question', 0, PARAM_INT); // attempt id
$number = required_param('number', PARAM_INT); // question number
$number = optional_param('number', 0, PARAM_INT); // question number
if ($stateid) {
if (! $state = get_record('quiz_states', 'id', $stateid)) {