Fixed incorrect check for whether to update state or insert new one in save_question_session()
Deal with manually graded states correctly during regrading
Increase state sequence number during manual grading
Supplied missing userid to quiz_save_best_grade() during manual grading
// It is important that this is done only after calling the questiontype functions
delete_records("question_states", "attempt", $attemptid);
delete_records("question_sessions", "attemptid", $attemptid);
+ delete_records("question_attempts", "id", $attemptid);
return;
}
$state->answer = isset($state->responses['']) ? $state->responses[''] : '';
// Save the state
- if (isset($state->update)) { // this forces the old state record to be overwritten
+ if (!empty($state->update)) { // this forces the old state record to be overwritten
update_record('question_states', $state);
} else {
if (!$state->id = insert_record('question_states', $state)) {
} else {
$action->event = $states[$j]->event;
}
- // Reprocess (regrade) responses
- if (!question_process_responses($question, $replaystate, $action, $cmoptions,
- $attempt)) {
- $verbose && notify("Couldn't regrade state #{$state->id}!");
+
+ if ($action->event = QUESTION_EVENTMANUALGRADE) {
+ question_process_comment($question, $replaystate, $attempt, $states[$j]->comment, $states[$j]->grade);
+ } else {
+
+ // Reprocess (regrade) responses
+ 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
}
$replaystate->id = $states[$j]->id;
+ $replaystate->changed = true;
$replaystate->update = true; // This will ensure that the existing database entry is updated rather than a new one created
save_question_session($question, $replaystate);
}
$state->grade = $grade;
$state->penalty = 0;
$state->timestamp = time();
+ $state->seq_number++;
// We need to indicate that the state has changed in order for it to be saved
$state->changed = 1;
// We want to update existing state (rather than creating new one) if it
* attempts. Hence a module, when creating a new attempt, calls this function and
* stores the return value in the 'uniqueid' field of its attempts table.
*/
-function question_new_attempt_uniqueid() {
+function question_new_attempt_uniqueid($modulename='quiz') {
global $CFG;
- set_config('attemptuniqueid', $CFG->attemptuniqueid + 1);
- return $CFG->attemptuniqueid;
+ $attempt->modulename = $modulename;
+ if (!$id = insert_record('question_attempts', $attempt)) {
+ error('Could not create new entry in question_attempts table');
+ }
+ return $id;
}
-/* Creates a stamp that uniquely identifies this version of the question
+/**
+ * Creates a stamp that uniquely identifies this version of the question
*
* In future we want this to use a hash of the question data to guarantee that
* identical versions have the same version stamp.
* This page prints a review of a particular question attempt
*
* @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
-* the Serving Mathematics project
-* {@link http://maths.york.ac.uk/serving_maths}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package quiz
*/
// If the state has changed save it and update the quiz grade
if ($state->changed) {
save_question_session($question, $state);
- quiz_save_best_grade($quiz);
+ quiz_save_best_grade($quiz, $attempt->userid);
}
notify(get_string('changessaved'));
}
}
- if ($oldversion < 2006043000) {
+ if ($oldversion < 2006051300) {
// The newgraded field must always point to a valid state
modify_database("","UPDATE prefix_question_sessions SET newgraded = newest where newgraded = '0'");
+
+ // The following table is discussed in bug 5468
+ modify_database ("", "CREATE TABLE prefix_question_attempts (
+ id int(10) unsigned NOT NULL auto_increment,
+ modulename varchar(20) NOT NULL default 'quiz',
+ PRIMARY KEY (id)
+ ) TYPE=MyISAM COMMENT='Student attempts. This table gets extended by the modules';");
+ // create one entry for all the existing quiz attempts
+ modify_database ("", "INSERT INTO prefix_question_attempts (id)
+ SELECT uniqueid
+ FROM prefix_quiz_attempts;");
}
return true;
-- --------------------------------------------------------
+--
+-- Table structure for table `prefix_question_attempts`
+--
+
+CREATE TABLE prefix_question_attempts (
+ id int(10) unsigned NOT NULL auto_increment,
+ modulename varchar(20) NOT NULL default 'quiz',
+ PRIMARY KEY (id)
+) TYPE=MyISAM COMMENT='Student attempts. This table gets extended by the modules';
+
+-- --------------------------------------------------------
+
INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'add', 'quiz', 'name');
INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'update', 'quiz', 'name');
}
}
- if ($oldversion < 2006043000) {
+ if ($oldversion < 2006051300) {
// The newgraded field must always point to a valid state
modify_database("","UPDATE prefix_question_sessions SET newgraded = newest where newgraded = '0'");
+
+ // The following table is discussed in bug 5468
+ modify_database ("", "CREATE TABLE prefix_question_attempts (
+ id SERIAL PRIMARY KEY,
+ modulename varchar(20) NOT NULL default 'quiz'
+ );");
+ // create one entry for all the existing quiz attempts
+ modify_database ("", "INSERT INTO prefix_question_attempts (id)
+ SELECT uniqueid
+ FROM prefix_quiz_attempts;");
}
return true;
CREATE INDEX prefix_question_category_idx ON prefix_question (category);
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_question_attempts
+#
+
+CREATE TABLE prefix_question_attempts (
+ id SERIAL PRIMARY KEY,
+ modulename varchar(20) NOT NULL default 'quiz'
+);
# --------------------------------------------------------
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2006042800; // The (date) version of this module
+$module->version = 2006051300; // The (date) version of this module
$module->requires = 2006022400; // Requires this Moodle version
$module->cron = 0; // How often should cron check this module (seconds)?