Skip to content

Commit

Permalink
Change to when newly created states get saved
Browse files Browse the repository at this point in the history
Changes to what is printed during regrade
  • Loading branch information
gustav_delius committed Jun 5, 2005
1 parent 5eab4b5 commit 52fa982
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 47 deletions.
6 changes: 3 additions & 3 deletions lang/en/quiz.php
Expand Up @@ -311,11 +311,11 @@
$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';
Expand Down
19 changes: 9 additions & 10 deletions mod/quiz/attempt.php
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 /////////////////////////////////////////////////

Expand Down Expand Up @@ -437,14 +444,6 @@ function navigate(page) {
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

Expand Down
57 changes: 36 additions & 21 deletions mod/quiz/locallib.php
Expand Up @@ -1492,21 +1492,17 @@ 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
quiz_restore_state($question, $states[0]);
$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]);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2235,7 +2237,7 @@ function quiz_get_best_grade($quiz, $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
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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) {

Expand Down Expand Up @@ -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) {

Expand Down
27 changes: 16 additions & 11 deletions mod/quiz/report/regrade/report.php
Expand Up @@ -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
Expand All @@ -31,15 +29,22 @@ function display($quiz, $cm, $course) { /// This function just displays the
}
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;
}
Expand Down
3 changes: 1 addition & 2 deletions mod/quiz/reviewquestion.php
Expand Up @@ -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)) {
Expand Down

0 comments on commit 52fa982

Please sign in to comment.