*
* Extends the state objects for a question by calling
* {@link restore_session_and_responses()}
-* @return boolean Represents success or failure
* @param object $question The question for which the state is needed
-* @param object $state The state as loaded from the database
+* @param object $state The state as loaded from the database
+* @return boolean Represents success or failure
*/
function restore_question_state(&$question, &$state) {
global $QTYPES;
// initialise response to the value in the answer field
- $state->answer = addslashes($state->answer);
- $state->responses = array('' => $state->answer);
+ $state->responses = array('' => addslashes($state->answer));
unset($state->answer);
$state->comment = isset($state->comment) ? addslashes($state->comment) : '';
// Load the question type specific data
return $QTYPES[$question->qtype]
- ->restore_session_and_responses($question, $state);
+ ->restore_session_and_responses($question, $state);
}
// create or update the session
if (!$session = get_record('question_sessions', 'attemptid',
- $state->attempt, 'questionid', $question->id)) {
+ $state->attempt, 'questionid', $question->id)) {
$session->attemptid = $state->attempt;
$session->questionid = $question->id;
$session->newest = $state->id;
// load all states for this question in this attempt, ordered in sequence
if ($states = get_records_select('question_states',
- "attempt = '{$attempt->uniqueid}' AND question = '{$question->id}'", 'seq_number ASC')) {
+ "attempt = '{$attempt->uniqueid}' AND question = '{$question->id}'",
+ 'seq_number ASC')) {
$states = array_values($states);
// Subtract the grade for the latest state from $attempt->sumgrades to get the
// Change event to submit so that it will be reprocessed
if (QUESTION_EVENTCLOSE == $states[$j]->event
- or QUESTION_EVENTGRADE == $states[$j]->event
- or QUESTION_EVENTCLOSEANDGRADE == $states[$j]->event) {
+ or QUESTION_EVENTGRADE == $states[$j]->event
+ or QUESTION_EVENTCLOSEANDGRADE == $states[$j]->event) {
$action->event = QUESTION_EVENTSUBMIT;
// By default take the event that was saved in the database
}
if ($action->event == QUESTION_EVENTMANUALGRADE) {
- question_process_comment($question, $replaystate, $attempt, $replaystate->comment, $states[$j]->grade);
+ question_process_comment($question, $replaystate, $attempt,
+ $replaystate->comment, $states[$j]->grade);
} else {
// Reprocess (regrade) responses
- if (!question_process_responses($question, $replaystate, $action, $cmoptions,
- $attempt)) {
+ if (!question_process_responses($question, $replaystate,
+ $action, $cmoptions, $attempt)) {
$verbose && notify("Couldn't regrade state #{$state->id}!");
}
}
// We need rounding here because grades in the DB get truncated
// e.g. 0.33333 != 0.3333333, but we want them to be equal here
if ((round((float)$replaystate->raw_grade, 5) != round((float)$states[$j]->raw_grade, 5))
- or (round((float)$replaystate->penalty, 5) != round((float)$states[$j]->penalty, 5))
- or (round((float)$replaystate->grade, 5) != round((float)$states[$j]->grade, 5))) {
+ or (round((float)$replaystate->penalty, 5) != round((float)$states[$j]->penalty, 5))
+ or (round((float)$replaystate->grade, 5) != round((float)$states[$j]->grade, 5))) {
$changed = true;
}
if (!set_field('question_sessions', 'comment', $comment, 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) {
error("Cannot save comment");
}
-
// If the teacher has changed the grade then update the attempt and the state
// The modified attempt is stored to the database, the state not yet but the
// $state->changed flag is set
<?php // $Id$
// This script regrades all attempts at this quiz
-
- require_once($CFG->libdir.'/tablelib.php');
+require_once($CFG->libdir.'/tablelib.php');
class quiz_report extends quiz_default_report {
- function display($quiz, $cm, $course) { /// This function just displays the report
+ function display($quiz, $cm, $course) {
global $CFG, $SESSION, $db, $QTYPES;
- /// Print header
+ // Print header
$this->print_header_and_tabs($cm, $course, $quiz, $reportmode="regrade");
- /// Fetch all attempts
+ // 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
+ // Fetch all questions
$sql = "SELECT q.*, i.grade AS maxgrade FROM {$CFG->prefix}question q,
{$CFG->prefix}quiz_question_instances i
WHERE i.quiz = $quiz->id
}
get_question_options($questions);
- /// Print heading
+ // Print heading
print_heading(get_string('regradingquiz', 'quiz', format_string($quiz->name)));
echo '<center>';
print_string('regradedisplayexplanation', 'quiz');
echo '<center>';
- /// Loop through all questions and all attempts and regrade while printing progress info
+ // 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) {
@flush();@ob_flush();
}
- /// Loop through all questions and recalculate $attempt->sumgrade
+ // Loop through all questions and recalculate $attempt->sumgrade
$attemptschanged = 0;
foreach ($attempts as $attempt) {
$sumgrades = 0;
}
}
- /// Update the overall quiz grades
+ // Update the overall quiz grades
if ($grades = get_records('quiz_grades', 'quiz', $quiz->id)) {
foreach($grades as $grade) {
quiz_save_best_grade($quiz, $grade->userid);