Renamed table quiz_newest_states to question_sessions

This commit is contained in:
gustav_delius
2006-02-15 08:38:41 +00:00
parent 832d40420c
commit 03d1753c1c
21 changed files with 72 additions and 70 deletions
+4 -2
View File
@@ -202,8 +202,10 @@
delete_records('quiz_grades', 'quiz', $quiz->id, 'userid', $USER->id);
foreach ($oldattempts as $oldattempt) {
// there should only be one but we loop just in case
// TODO: the following should become a function in questionlib.php which
// really deletes all records associated to this attempt.
delete_records('quiz_states', 'attempt', $oldattempt->uniqueid);
delete_records('quiz_newest_states', 'attemptid', $oldattempt->uniqueid);
delete_records('question_sessions', 'attemptid', $oldattempt->uniqueid);
}
}
}
@@ -340,7 +342,7 @@
// Find all the questions for this attempt for which the newest
// state is not also the newest graded state
if ($closequestions = get_records_select('quiz_newest_states',
if ($closequestions = get_records_select('question_sessions',
"attemptid = $attempt->uniqueid AND newest != newgraded", '', 'questionid, questionid')) {
// load all the questions
+5 -5
View File
@@ -17,7 +17,7 @@
// quiz_attempts quiz_question_instances . | | (CL,pk->id,fk->question, | .
// (UL,pk->id,fk->quiz) (CL,pk->id,fk->quiz,question) . | | fk->dataset_definition) | .
// | | . | | | .
// | quiz_newest_states | . | | | .
// | question_sessions | . | | | .
// |---------(UL,pk->id,fk->attempt,question)-----| . | | | .
// | . | . | | quiz_dataset_definitions
// | . | . | | (CL,pk->id,fk->category)
@@ -96,7 +96,7 @@
// - quiz_attempts
// - quiz_grades
// - quiz_states
// - quiz_newest_states
// - question_sessions
// This step is the standard mod backup. (course dependent).
//STEP 1. Backup categories/questions and associated structures
@@ -961,13 +961,13 @@
//Write end tag
$status =fwrite ($bf,end_tag("STATES",6,true));
}
$quiz_newest_states = get_records("quiz_newest_states","attemptid",$attempt,"id");
$question_sessions = get_records("question_sessions","attemptid",$attempt,"id");
//If there are newest_states
if ($quiz_newest_states) {
if ($question_sessions) {
//Write start tag
$status =fwrite ($bf,start_tag("NEWEST_STATES",6,true));
//Iterate over each newest_state
foreach ($quiz_newest_states as $newest_state) {
foreach ($question_sessions as $newest_state) {
//Start newest_state
$status =fwrite ($bf,start_tag("NEWEST_STATE",7,true));
//Print newest_state contents
+1 -1
View File
@@ -39,7 +39,7 @@
<FIELD name="tolerance" method="NO_CONV" type="varchar" length="255" default="0.0" />
</FIELDS>
</TABLE>
<TABLE name="quiz_newest_states">
<TABLE name="question_sessions">
<FIELDS>
<FIELD name="sumpenalty" method="NO_CONV" type="varchar" length="10" default="0.0" />
</FIELDS>
+1 -1
View File
@@ -908,7 +908,7 @@ function quiz_upgrade($oldversion) {
table_column('quiz_multianswers', 'sequence', 'sequence', 'text', '', '', '', 'not null', 'question');
}
if ($oldversion < 200602100) {
if ($oldversion < 2006021501) {
execute_sql("ALTER TABLE {$CFG->prefix}quiz_newest_states RENAME {$CFG->prefix}question_sessions", false);
}
+2 -2
View File
@@ -284,10 +284,10 @@ CREATE TABLE prefix_quiz_multichoice (
-- --------------------------------------------------------
--
-- Table structure for table `prefix_quiz_newest_states`
-- Table structure for table `prefix_question_sessions`
--
CREATE TABLE prefix_quiz_newest_states (
CREATE TABLE prefix_question_sessions (
id int(10) unsigned NOT NULL auto_increment,
attemptid int(10) unsigned NOT NULL default '0',
questionid int(10) unsigned NOT NULL default '0',
+1 -1
View File
@@ -1005,7 +1005,7 @@ function quiz_upgrade($oldversion) {
modify_database('','CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);');
}
if ($oldversion < 200602100) {
if ($oldversion < 2006021501) {
execute_sql("ALTER TABLE {$CFG->prefix}quiz_newest_states RENAME TO {$CFG->prefix}question_sessions", false);
}
+3 -3
View File
@@ -251,11 +251,11 @@ CREATE INDEX prefix_quiz_multichoice_question_idx ON prefix_quiz_multichoice (qu
# --------------------------------------------------------
#
# Table structure for table prefix_quiz_newest_states
# Table structure for table prefix_question_sessions
#
CREATE TABLE prefix_quiz_newest_states (
CREATE TABLE prefix_question_sessions (
id SERIAL PRIMARY KEY,
attemptid integer NOT NULL default '0',
questionid integer NOT NULL default '0',
@@ -264,7 +264,7 @@ CREATE TABLE prefix_quiz_newest_states (
sumpenalty varchar(10) NOT NULL default '0.0'
);
CREATE UNIQUE INDEX prefix_quiz_newest_states_attempt_idx ON prefix_quiz_newest_states (attemptid,questionid);
CREATE UNIQUE INDEX prefix_question_sessions_attempt_idx ON prefix_question_sessions (attemptid,questionid);
# --------------------------------------------------------
+5 -5
View File
@@ -122,7 +122,7 @@
$statefields = 'n.questionid as question, s.*, n.sumpenalty';
$sql = "SELECT $statefields".
" FROM {$CFG->prefix}quiz_states s,".
" {$CFG->prefix}quiz_newest_states n".
" {$CFG->prefix}question_sessions n".
" WHERE s.id = n.newest".
" AND n.attemptid = '$attempt->uniqueid'".
" AND n.questionid = $question->id";
@@ -150,7 +150,7 @@
$sumgrades = 0;
$questionids = explode(',', quiz_questions_in_quiz($attempt->layout));
foreach($questionids as $questionid) {
$lastgradedid = get_field('quiz_newest_states', 'newgraded', 'attemptid', $attempt->uniqueid, 'questionid', $questionid);
$lastgradedid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->uniqueid, 'questionid', $questionid);
$sumgrades += get_field('quiz_states', 'grade', 'id', $lastgradedid);
}
@@ -190,7 +190,7 @@
foreach ($attempts as $attempt) {
// retrieve the state
if (!$neweststate = get_record('quiz_newest_states', 'attemptid', $attempt->uniqueid, 'questionid', $questionid)) {
if (!$neweststate = get_record('question_sessions', 'attemptid', $attempt->uniqueid, 'questionid', $questionid)) {
error("Can not find newest states for attempt $attempt->uniqueid for question $questionid");
}
if (! $state = get_record('quiz_states', 'id', $neweststate->newest)) {
@@ -276,7 +276,7 @@
$ungraded = 0;
foreach ($attempts as $attempt) {
// grab the state then check if it is graded
if (!$neweststate = get_record('quiz_newest_states', 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) {
if (!$neweststate = get_record('question_sessions', 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) {
error("Can not find newest states for attempt $attempt->uniqueid for question $question->id");
}
if (!$questionstate = get_record('quiz_essay_states', 'stateid', $neweststate->newest)) {
@@ -365,7 +365,7 @@
$attempt->firstname.' '.$attempt->lastname.'</a>';
// nab the state of the attempt to see if it is graded or not
if (!$neweststate = get_record('quiz_newest_states', 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) {
if (!$neweststate = get_record('question_sessions', 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) {
error("Can not find newest states for attempt $attempt->uniqueid for question $questionid");
}
+2 -1
View File
@@ -214,10 +214,11 @@ function quiz_delete_instance($id) {
if ($attempts = get_records("quiz_attempts", "quiz", "$quiz->id")) {
foreach ($attempts as $attempt) {
// TODO: this should use function in questionlib.php
if (! delete_records("quiz_states", "attempt", "$attempt->uniqueid")) {
$result = false;
}
if (! delete_records("quiz_newest_states", "attemptid", "$attempt->uniqueid")) {
if (! delete_records("question_sessions", "attemptid", "$attempt->uniqueid")) {
$result = false;
}
}
+6 -6
View File
@@ -456,7 +456,7 @@ function quiz_parse_fieldname($name, $nameprefix='question') {
* Any state that does not yet have its timestamp set to nonzero has not yet been upgraded from Moodle 1.4
* The reason these are still around is that for large sites it would have taken too long to
* upgrade all states at once. This function sets the timestamp field and creates an entry in the
* quiz_newest_states table.
* question_sessions table.
* @param object $attempt The attempt whose states need upgrading
*/
function quiz_upgrade_states($attempt) {
@@ -467,7 +467,7 @@ function quiz_upgrade_states($attempt) {
// We set the timestamp of all states to the timemodified field of the attempt.
execute_sql("UPDATE {$CFG->prefix}quiz_states SET timestamp = '$attempt->timemodified' WHERE attempt = '$attempt->uniqueid'", false);
// For each state we create an entry in the quiz_newest_states table, with both newest and
// For each state we create an entry in the question_sessions table, with both newest and
// newgraded pointing to this state.
// Actually we only do this for states whose question is actually listed in $attempt->layout.
// We do not do it for states associated to wrapped questions like for example the questions
@@ -476,10 +476,10 @@ function quiz_upgrade_states($attempt) {
$questionlist = quiz_questions_in_quiz($attempt->layout);
if ($states = get_records_select('quiz_states', "attempt = '$attempt->uniqueid' AND question IN ($questionlist)")) {
foreach ($states as $state) {
$newest->newgraded = $state->id;
$newest->newest = $state->id;
$newest->questionid = $state->question;
insert_record('quiz_newest_states', $newest, false);
$session->newgraded = $state->id;
$session->newest = $state->id;
$session->questionid = $state->question;
insert_record('question_sessions', $session, false);
}
}
}
+2 -2
View File
@@ -252,8 +252,8 @@
// replace question id in states
set_field('quiz_states', 'question', $question->id, 'attempt', $attempt->uniqueid, 'question', $oldquestionid);
// replace question id in newest_states
set_field('quiz_newest_states', 'questionid', $question->id, 'attemptid', $attempt->uniqueid, 'questionid', $oldquestionid);
// replace question id in sessions
set_field('question_sessions', 'questionid', $question->id, 'attemptid', $attempt->uniqueid, 'questionid', $oldquestionid);
}
+11 -11
View File
@@ -127,7 +127,7 @@ function quiz_delete_question($question) {
$QUIZ_QTYPES[$question->qtype]->delete_question($question);
delete_records("quiz_answers", "question", $question->id);
delete_records("quiz_states", "question", $question->id);
delete_records("quiz_newest_states", "questionid", $question->id);
delete_records("question_sessions", "questionid", $question->id);
if ($newversions = get_records('quiz_question_versions', 'oldquestion', $question->id)) {
foreach ($newversions as $newversion) {
$newquestion = get_record('quiz_questions', 'id', $newversion->newquestion);
@@ -210,7 +210,7 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
// Load the newest states for the questions
$sql = "SELECT $statefields".
" FROM {$CFG->prefix}quiz_states s,".
" {$CFG->prefix}quiz_newest_states n".
" {$CFG->prefix}question_sessions n".
" WHERE s.id = n.newest".
" AND n.attemptid = '$attempt->uniqueid'".
" AND n.questionid IN ($questionlist)";
@@ -219,7 +219,7 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
// Load the newest graded states for the questions
$sql = "SELECT $statefields".
" FROM {$CFG->prefix}quiz_states s,".
" {$CFG->prefix}quiz_newest_states n".
" {$CFG->prefix}question_sessions n".
" WHERE s.id = n.newgraded".
" AND n.attemptid = '$attempt->uniqueid'".
" AND n.questionid IN ($questionlist)";
@@ -246,7 +246,7 @@ function quiz_get_states(&$questions, $cmoptions, $attempt) {
// Load the last graded state for the question
$sql = "SELECT $statefields".
" FROM {$CFG->prefix}quiz_states s,".
" {$CFG->prefix}quiz_newest_states n".
" {$CFG->prefix}question_sessions n".
" WHERE s.id = n.newgraded".
" AND n.attemptid = '$lastattemptid'".
" AND n.questionid = '$i'";
@@ -332,7 +332,7 @@ function quiz_restore_state(&$question, &$state) {
* The state object representing the current state of the session for the
* question is saved to the quiz_states table with ->responses[''] saved
* to the answer field of the database table. The information in the
* quiz_newest_states table is updated.
* question_sessions table is updated.
* The question type specific data is then saved.
* @return boolean Indicates success or failure.
* @param object $question The question for which session is to be saved.
@@ -371,26 +371,26 @@ function quiz_save_question_session(&$question, &$state) {
}
// this is the most recent state
if (!record_exists('quiz_newest_states', 'attemptid',
if (!record_exists('question_sessions', 'attemptid',
$state->attempt, 'questionid', $question->id)) {
$new->attemptid = $state->attempt;
$new->questionid = $question->id;
$new->newest = $state->id;
$new->sumpenalty = $state->sumpenalty;
if (!insert_record('quiz_newest_states', $new)) {
error('Could not insert entry in quiz_newest_states');
if (!insert_record('question_sessions', $new)) {
error('Could not insert entry in question_sessions');
}
} else {
set_field('quiz_newest_states', 'newest', $state->id, 'attemptid',
set_field('question_sessions', 'newest', $state->id, 'attemptid',
$state->attempt, 'questionid', $question->id);
}
if (quiz_state_is_graded($state)) {
// this is also the most recent graded state
if ($newest = get_record('quiz_newest_states', 'attemptid',
if ($newest = get_record('question_sessions', 'attemptid',
$state->attempt, 'questionid', $question->id)) {
$newest->newgraded = $state->id;
$newest->sumpenalty = $state->sumpenalty;
update_record('quiz_newest_states', $newest);
update_record('question_sessions', $newest);
}
}
}
@@ -285,7 +285,7 @@ class quiz_essay_qtype extends quiz_default_questiontype {
// determine the number of ungraded attempts essays
foreach ($attempts as $attempt) {
// grab the state then check if it is graded
if (!$neweststate = get_record('quiz_newest_states', 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) {
if (!$neweststate = get_record('question_sessions', 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) {
error("Can not find newest states for attempt $attempt->uniqueid for question $question->id");
}
if (!$questionstate = get_record('quiz_essay_states', 'stateid', $neweststate->newest)) {
+3 -3
View File
@@ -41,10 +41,10 @@ class quiz_report extends quiz_default_report {
foreach($attemptids as $attemptid) {
if ($todelete = get_record('quiz_attempts', 'id', $attemptid)) {
// TODO: use function from questionlib.php to delete attempt
delete_records('quiz_attempts', 'id', $attemptid);
delete_records('quiz_states', 'attempt', $todelete->uniqueid);
delete_records('quiz_newest_states', 'attemptid', $todelete->uniqueid);
delete_records('question_sessions', 'attemptid', $todelete->uniqueid);
// Search quiz_attempts for other instances by this user.
// If none, then delete record for this quiz, this user from quiz_grades
@@ -289,7 +289,7 @@ class quiz_report extends quiz_default_report {
if(!$questionsort) {
$qid = intval(substr($sortpart, 1));
$select .= ', grade ';
$from .= 'LEFT JOIN '.$CFG->prefix.'quiz_newest_states qns ON qns.attemptid = qa.attemptuniqueid '.
$from .= 'LEFT JOIN '.$CFG->prefix.'question_sessions qns ON qns.attemptid = qa.attemptuniqueid '.
'LEFT JOIN '.$CFG->prefix.'quiz_states qs ON qs.id = qns.newgraded ';
$where .= ' AND ('.sql_isnull('qns.questionid').' OR qns.questionid = '.$qid.')';
$newsort[] = 'grade '.(strpos($sortpart, 'ASC')? 'ASC' : 'DESC');
+1 -1
View File
@@ -53,7 +53,7 @@ class quiz_report extends quiz_default_report {
$sumgrades = 0;
$questionids = explode(',', quiz_questions_in_quiz($attempt->layout));
foreach($questionids as $questionid) {
$lastgradedid = get_field('quiz_newest_states', 'newgraded', 'attemptid', $attempt->uniqueid, 'questionid', $questionid);
$lastgradedid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->uniqueid, 'questionid', $questionid);
$sumgrades += get_field('quiz_states', 'grade', 'id', $lastgradedid);
}
if ($attempt->sumgrades != $sumgrades) {
+2 -2
View File
@@ -177,7 +177,7 @@ class quiz_report extends quiz_default_report {
if(!$questionsort) {
$qid = intval(substr($sortpart, 1));
$select .= ', grade ';
$from .= 'LEFT JOIN '.$CFG->prefix.'quiz_newest_states qns ON qns.attemptid = qa.id '.
$from .= 'LEFT JOIN '.$CFG->prefix.'question_sessions qns ON qns.attemptid = qa.id '.
'LEFT JOIN '.$CFG->prefix.'quiz_states qs ON qs.id = qns.newgraded ';
$where .= ' AND ('.sql_isnull('qns.questionid').' OR qns.questionid = '.$qid.')';
$newsort[] = 'answer '.(strpos($sortpart, 'ASC')? 'ASC' : 'DESC');
@@ -315,7 +315,7 @@ class quiz_report extends quiz_default_report {
error('Could not restore question sessions');
}
foreach($questionids as $questionid) {
$gradedstateid = get_field('quiz_newest_states', 'newgraded', 'attemptid', $attempt->id, 'questionid', $questionid);
$gradedstateid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->id, 'questionid', $questionid);
$grade = round(get_field('quiz_states', 'grade', 'id', $gradedstateid), $quiz->decimalpoints);
$responses = quiz_get_question_actual_response($questions[$questionid], $states[$questionid]);
$response = implode(', ',$responses);
+19 -19
View File
@@ -25,7 +25,7 @@
// quiz_attempts quiz_question_instances . | | (CL,pk->id,fk->question, | .
// (UL,pk->id,fk->quiz) (CL,pk->id,fk->quiz,question) . | | fk->dataset_definition) | .
// | | . | | | .
// | quiz_newest_states | . | | | .
// | question_sessions | . | | | .
// |---------(UL,pk->id,fk->attempt,question)-----| . | | | .
// | . | . | | quiz_dataset_definitions
// | . | . | | (CL,pk->id,fk->category)
@@ -1838,42 +1838,42 @@
}
}
//Get the quiz_newest_states array
$newest_states = $info['#']['NEWEST_STATES']['0']['#']['NEWEST_STATE'];
//Iterate over newest_states
for($i = 0; $i < sizeof($newest_states); $i++) {
$res_info = $newest_states[$i];
//Get the question_sessions array
$sessions = $info['#']['NEWEST_STATES']['0']['#']['NEWEST_STATE'];
//Iterate over question_sessions
for($i = 0; $i < sizeof($sessions); $i++) {
$res_info = $sessions[$i];
//traverse_xmlize($res_info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, build the NEWEST_STATES record structure
$newest_state->attemptid = $attempt_id;
$newest_state->questionid = backup_todb($res_info['#']['QUESTIONID']['0']['#']);
$newest_state->newest = backup_todb($res_info['#']['NEWEST']['0']['#']);
$newest_state->newgraded = backup_todb($res_info['#']['NEWGRADED']['0']['#']);
$newest_state->sumpenalty = backup_todb($res_info['#']['SUMPENALTY']['0']['#']);
$session->attemptid = $attempt_id;
$session->questionid = backup_todb($res_info['#']['QUESTIONID']['0']['#']);
$session->newest = backup_todb($res_info['#']['NEWEST']['0']['#']);
$session->newgraded = backup_todb($res_info['#']['NEWGRADED']['0']['#']);
$session->sumpenalty = backup_todb($res_info['#']['SUMPENALTY']['0']['#']);
//We have to recode the question field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$newest_state->questionid);
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$session->questionid);
if ($question) {
$newest_state->questionid = $question->new_id;
$session->questionid = $question->new_id;
}
//We have to recode the newest field
$state = backup_getid($restore->backup_unique_code,"quiz_states",$newest_state->newest);
$state = backup_getid($restore->backup_unique_code,"quiz_states",$session->newest);
if ($state) {
$newest_state->newest = $state->new_id;
$session->newest = $state->new_id;
}
//We have to recode the newgraded field
$state = backup_getid($restore->backup_unique_code,"quiz_states",$newest_state->newgraded);
$state = backup_getid($restore->backup_unique_code,"quiz_states",$session->newgraded);
if ($state) {
$newest_state->newgraded = $state->new_id;
$session->newgraded = $state->new_id;
}
//The structure is equal to the db, so insert the quiz_newest_states
$newid = insert_record ("quiz_newest_states",$newest_state);
//The structure is equal to the db, so insert the question_sessions
$newid = insert_record ("question_sessions",$session);
}
+1 -1
View File
@@ -31,7 +31,7 @@
error("The course module for the quiz with id $quiz->id is missing");
}
if (!count_records('quiz_newest_states', 'attemptid', $attempt->uniqueid)) {
if (!count_records('question_sessions', 'attemptid', $attempt->uniqueid)) {
// this question has not yet been upgraded to the new model
quiz_upgrade_states($attempt);
}
+1 -1
View File
@@ -31,7 +31,7 @@
if (! $attempt = get_record('quiz_attempts', 'id', $attemptid)) {
error('No such attempt ID exists');
}
if (! $neweststateid = get_field('quiz_newest_states', 'newest', 'attemptid', $attempt->uniqueid, 'questionid', $questionid)) {
if (! $neweststateid = get_field('question_sessions', 'newest', 'attemptid', $attempt->uniqueid, 'questionid', $questionid)) {
// newest_state not set, probably because this is an old attempt from the old quiz module code
if (! $state = get_record('quiz_states', 'question', $questionid, 'attempt', $attempt->uniqueid)) {
error('Invalid question id');
+1 -1
View File
@@ -5,7 +5,7 @@
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2006021500; // The (date) version of this module
$module->version = 2006021501; // The (date) version of this module
$module->requires = 2005021600; // Requires this Moodle version
$module->cron = 0; // How often should cron check this module (seconds)?
-1
View File
@@ -217,7 +217,6 @@
$datecompleted = userdate($attempt->timefinish);
} else if ($available) { // The student can continue this attempt, so put appropriate link
$timetaken = format_time(time() - $attempt->timestart);
$strconfirmstartattempt = addslashes(get_string("confirmstartattempt","quiz"));
$datecompleted = "\n".'<script language="javascript" type="text/javascript">';
$datecompleted .= "\n<!--\n"; // -->
if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) {