]> git.mjollnir.org Git - moodle.git/commitdiff
Introduce question_attempts table, closing bug 5468
authorgustav_delius <gustav_delius>
Sat, 13 May 2006 16:57:17 +0000 (16:57 +0000)
committergustav_delius <gustav_delius>
Sat, 13 May 2006 16:57:17 +0000 (16:57 +0000)
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

lib/questionlib.php
mod/quiz/comment.php
mod/quiz/db/mysql.php
mod/quiz/db/mysql.sql
mod/quiz/db/postgres7.php
mod/quiz/db/postgres7.sql
mod/quiz/version.php

index 185add73864752a3d118f3837d9b41465a86c180..86a16de4fe7237769e86ade4a7a0c59c25b872fe 100644 (file)
@@ -330,6 +330,7 @@ function delete_attempt($attemptid) {
     // 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;
 }
@@ -681,7 +682,7 @@ function save_question_session(&$question, &$state) {
     $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)) {
@@ -858,10 +859,16 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
             } 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
@@ -873,6 +880,7 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
             }
 
             $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);
         }
@@ -1144,6 +1152,7 @@ function question_process_comment($question, &$state, &$attempt, $comment, $grad
         $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
@@ -1197,13 +1206,17 @@ function question_get_id_from_name_prefix($name) {
  * 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.
index 49e993b1353fb5805ab9a6ab34f73c7f4321b9f3..34f0d1806f1bfd360e74872f9113be53add593ad 100644 (file)
@@ -3,10 +3,6 @@
 * 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
 */
@@ -69,7 +65,7 @@
         // 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'));
index 721771a9a712e007049af4355b8d1c0b9858899e..8f3d541f25af84d553592650f8ff4fea933e901b 100644 (file)
@@ -1035,9 +1035,20 @@ function quiz_upgrade($oldversion) {
         }
     }
 
-    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;
index 9f9d34c0f942a73a28555735874abe7242dcd9fd..daff1d028aa0c6330deccf94ddd1424d50bea2d7 100644 (file)
@@ -286,6 +286,18 @@ CREATE TABLE prefix_question_states (
 
 -- --------------------------------------------------------
 
+-- 
+-- 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');
index 2b217c8f1ebf431c82438b8ca3e4e7f5f62c537d..0338567c8cf1066637fa2bd00a5a1d2613923d61 100644 (file)
@@ -1206,9 +1206,19 @@ function quiz_upgrade($oldversion) {
         }
     }
 
-    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;
index 5c771567d867a79d4453dfb38805a17552642299..483d330faa37d9ce06b7cb544c7efc9f47035562 100644 (file)
@@ -255,6 +255,16 @@ CREATE TABLE prefix_question (
 
 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'
+);
 
 # --------------------------------------------------------
 
index abdfb06f0a98610f045ba6f18dad9fc0d611e2bc..37b52957598010edae61e5f4d74a65b94b92e44d 100644 (file)
@@ -5,7 +5,7 @@
 //  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)?