mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
Introduce question_attempts table, closing bug 5468
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
This commit is contained in:
parent
e81e5c1604
commit
36be25f6e5
@ -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.
|
||||
|
@ -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'));
|
||||
|
@ -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;
|
||||
|
@ -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');
|
||||
|
@ -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;
|
||||
|
@ -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'
|
||||
);
|
||||
|
||||
# --------------------------------------------------------
|
||||
|
||||
|
@ -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)?
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user