📄 mysql.php
字号:
$success = $success && modify_database ('', 'ALTER TABLE prefix_quiz_responses RENAME prefix_quiz_states;'); /// add columns to quiz_states table // The sequence number of the state. $success = $success && table_column('quiz_states', '', 'seq_number', 'integer', '6', 'unsigned', '0', 'not null', 'originalquestion'); // For existing states we leave this at 0 because in the old quiz code there was only one response allowed // The time the state was created. $success = $success && table_column('quiz_states', '', 'timestamp', 'integer', '10', 'unsigned', '0', 'not null', 'answer'); // For existing states we will below set this to the timemodified field of the attempt // The type of event that led to the creation of the state $success = $success && table_column('quiz_states', '', 'event', 'integer', '4', 'unsigned', '0', 'not null', 'timestamp'); // The raw grade $success = $success && table_column('quiz_states', '', 'raw_grade', 'varchar', '10', '', '', 'not null', 'grade'); // For existing states (no penalties) this is equal to the grade $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_states SET raw_grade = grade"); // The penalty that the response attracted $success = $success && table_column('quiz_states', '', 'penalty', 'varchar', '10', '', '0.0', 'not null', 'raw_grade'); // For existing states this can stay at 0 because penalties did not exist previously. /// New table for pointers to newest and newest graded states $success = $success && modify_database('', "CREATE TABLE `prefix_quiz_newest_states` ( `id` int(10) unsigned NOT NULL auto_increment, `attemptid` int(10) unsigned NOT NULL default '0', `questionid` int(10) unsigned NOT NULL default '0', `new` int(10) unsigned NOT NULL default '0', `newgraded` int(10) unsigned NOT NULL default '0', `sumpenalty` varchar(10) NOT NULL default '0.0', PRIMARY KEY (`id`), UNIQUE KEY `attemptid` (`attemptid`,`questionid`) ) TYPE=MyISAM COMMENT='Gives ids of the newest open and newest graded states';"); /// Now upgrade some fields in states and newest_states tables where necessary // to save time on large sites only do this for attempts that have not yet been finished. if ($attempts = get_records_select('quiz_attempts', 'timefinish = 0')) { echo 'Update the states for the '.count($attempts).' open attempts'; // turn reporting off temporarily to avoid one line output per set_field $olddebug = $db->debug; $db->debug = false; foreach ($attempts as $attempt) { quiz_upgrade_states($attempt); } $db->debug = $olddebug; } /// Entries for the log_display table $success = $success && modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'preview', 'quiz', 'name');"); $success = $success && modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'start attempt', 'quiz', 'name');"); $success = $success && modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'close attempt', 'quiz', 'name');"); /// update the default settings in $CFG $review = (QUIZ_REVIEW_IMMEDIATELY & (QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES)); if (!empty($CFG->quiz_feedback)) { $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK); } if (!empty($CFG->quiz_correctanswers)) { $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS); } if (isset($CFG->quiz_review) and ($CFG->quiz_review & 1)) { $review += QUIZ_REVIEW_CLOSED; } if (isset($CFG->quiz_review) and ($CFG->quiz_review & 2)) { $review += QUIZ_REVIEW_OPEN; } $success = $success && set_config('quiz_review', $review); /// Use tolerance instead of min and max in numerical question type $success = $success && table_column('quiz_numerical', '', 'tolerance', 'varchar', '255', '', '0.0', 'not null', 'answer'); $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_numerical SET tolerance = (max-min)/2"); $success = $success && modify_database('', 'ALTER TABLE `prefix_quiz_numerical` DROP `min`'); // Replaced by tolerance $success = $success && modify_database('', 'ALTER TABLE `prefix_quiz_numerical` DROP `max`'); // Replaced by tolerance /// Tables for Remote Questions $success = $success && modify_database ('', "CREATE TABLE `prefix_quiz_rqp` ( `id` int(10) unsigned NOT NULL auto_increment, `question` int(10) unsigned NOT NULL default '0', `type` int(10) unsigned NOT NULL default '0', `source` longblob NOT NULL default '', `format` varchar(255) NOT NULL default '', `flags` tinyint(3) unsigned NOT NULL default '0', `maxscore` int(10) unsigned NOT NULL default '1', PRIMARY KEY (`id`), KEY `question` (`question`) ) TYPE=MyISAM COMMENT='Options for RQP questions';"); $success = $success && modify_database ('', "CREATE TABLE `prefix_quiz_rqp_type` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(255) NOT NULL default '', `rendering_server` varchar(255) NOT NULL default '', `cloning_server` varchar(255) NOT NULL default '', `flags` tinyint(3) NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) TYPE=MyISAM COMMENT='RQP question types and the servers to be used to process them';"); $success = $success && modify_database ('', "CREATE TABLE `prefix_quiz_rqp_states` ( `id` int(10) unsigned NOT NULL auto_increment, `stateid` int(10) unsigned NOT NULL default '0', `responses` text NOT NULL default '', `persistent_data` text NOT NULL default '', `template_vars` text NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT='RQP question type specific state information';"); } if ($success && $oldversion < 2005050300) { // length of question determines question numbering. Currently all questions require one // question number except for DESCRIPTION questions. $success = $success && table_column('quiz_questions', '', 'length', 'integer', '10', 'unsigned', '1', 'not null', 'qtype'); $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_questions SET length = 0 WHERE qtype ='7'"); } if ($success && $oldversion < 2005050408) { $success = $success && table_column('quiz_questions', '', 'penalty', 'float', '', '', '0.1', 'not null', 'defaultgrade'); $success = $success && table_column('quiz_newest_states', 'new', 'newest', 'integer', '10', 'unsigned', '0', 'not null'); } if ($success && $oldversion < 2005051400) { $success = $success && modify_database('', 'ALTER TABLE prefix_quiz_rqp_type RENAME prefix_quiz_rqp_types;'); $success = $success && modify_database('', "CREATE TABLE `prefix_quiz_rqp_servers` ( id int(10) unsigned NOT NULL auto_increment, typeid int(10) unsigned NOT NULL default '0', url varchar(255) NOT NULL default '', can_render tinyint(2) unsigned NOT NULL default '0', can_author tinyint(2) unsigned NOT NULL default '0', PRIMARY KEY (id) ) TYPE=MyISAM COMMENT='Information about RQP servers';"); if ($types = get_records('quiz_rqp_types')) { foreach($types as $type) { $server = new stdClass; $server->typeid = $type->id; $server->url = $type->rendering_server; $server->can_render = 1; $success = $success && insert_record('quiz_rqp_servers', $server); } } $success = $success && modify_database('', 'ALTER TABLE prefix_quiz_rqp_types DROP rendering_server'); $success = $success && modify_database('', 'ALTER TABLE prefix_quiz_rqp_types DROP cloning_server'); $success = $success && modify_database('', 'ALTER TABLE prefix_quiz_rqp_types DROP flags'); } if ($success && $oldversion < 2005051401) { // Some earlier changes are undone here, so we need another condition if ($oldversion >= 2005042900) { // Restore the answer field $success = $success && table_column('quiz_numerical', '', 'answer', 'integer', '10', 'unsigned', '0', 'not null', 'answers'); $singleanswer = array(); if ($numericals = get_records('quiz_numerical')) { $numericals = array_values($numericals); $n = count($numericals); for ($i = 0; $i < $n; $i++) { $numerical =& $numericals[$i]; if (strpos($numerical->answers, ',')) { // comma separated list? // Back this up to delete the record after the new ones are created $id = $numerical->id; unset($numerical->id); // We need to create a record for each answer id $answers = explode(',', $numerical->answers); foreach ($answers as $answer) { $numerical->answer = $answer; $success = $success && insert_record('quiz_numerical', $numerical); } // ... and get rid of the old record $success = $success && delete_records('quiz_numerical', 'id', $id); } else { $singleanswer[] = $numerical->id; } } } // Do all of these at once if (!empty($singleanswer)) { $singleanswer = implode(',', $singleanswer); $success = $success && modify_database('', "UPDATE prefix_quiz_numerical SET answer = answers WHERE id IN ($singleanswer);"); } // All answer fields are set, so we can delete the answers field $success = $success && modify_database('', 'ALTER TABLE `prefix_quiz_numerical` DROP `answers`'); // If the earlier changes weren't made we can safely do only the // bits here. } else { // Comma separated questionids will be stored as sequence $success = $success && table_column('quiz_multianswers', '', 'sequence', 'varchar', '255', '', '', 'not null', 'question'); // Change the type of positionkey to int, so that the sorting works! $success = $success && table_column('quiz_multianswers', 'positionkey', 'positionkey', 'integer', '10', 'unsigned', '0', 'not null', ''); $success = $success && table_column('quiz_questions', '', 'parent', 'integer', '10', 'unsigned', '0', 'not null', 'category'); $success = $success && modify_database('', "UPDATE prefix_quiz_questions SET parent = id WHERE qtype ='".RANDOM."';"); // Each multianswer record is converted to a question object and then // inserted as a new question into the quiz_questions table. // After that the question fields in the quiz_answers table and the // qtype specific tables are updated to point to the new question id. // Note: The quiz_numerical table is different as it stores one record // per defined answer (to allow different tolerance values for // different possible answers. (Currently multiple answers are // not supported by the numerical editing interface, but // all processing code does support that possibility. if ($multianswers = get_records_sql("SELECT m.id, q.category, " . "q.id AS parent, " . // question id (of multianswer question) as parent "q.name, q.questiontextformat, " . "m.norm AS defaultgrade, " . // norm is snow stored as defaultgrade "m.answertype AS qtype, " . // just rename this "q.version, q.hidden, m.answers, " . "m.positionkey " . "FROM {$CFG->prefix}quiz_questions q, " . " {$CFG->prefix}quiz_multianswers m " . "WHERE q.qtype = '".MULTIANSWER."' " . "AND q.id = m.question " . "ORDER BY q.id ASC, m.positionkey ASC")) { // ordered by positionkey $multianswers = array_values($multianswers); $n = count($multianswers); $parent = $multianswers[0]->parent;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -