View source
<?php
function quiz_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {quiz} (\n nid INTEGER UNSIGNED NOT NULL,\n number_of_questions TINYINT UNSIGNED NOT NULL,\n pass_rate TINYINT UNSIGNED NOT NULL,\n summary_pass LONGTEXT,\n summary_default LONGTEXT,\n shuffle TINYINT UNSIGNED NOT NULL,\n backwards_navigation TINYINT UNSIGNED NOT NULL,\n feedback_time TINYINT UNSIGNED NOT NULL,\n quiz_open INTEGER UNSIGNED DEFAULT 0,\n quiz_close INTEGER UNSIGNED DEFAULT 0,\n takes TINYINT UNSIGNED NOT NULL,\n time_limit INTEGER UNSIGNED DEFAULT 0 NOT NULL,\n quiz_always TINYINT NOT NULL default 0,\n PRIMARY KEY(nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {quiz_questions} (\n quiz_nid INTEGER UNSIGNED NOT NULL,\n question_nid INTEGER UNSIGNED NOT NULL,\n question_status TINYINT UNSIGNED NOT NULL,\n PRIMARY KEY (quiz_nid, question_nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {quiz_question} (\n nid INTEGER UNSIGNED NOT NULL,\n properties VARCHAR(255) NOT NULL,\n PRIMARY KEY (nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {quiz_question_answer} (\n aid INTEGER UNSIGNED NOT NULL,\n question_nid INTEGER UNSIGNED NOT NULL,\n answer TEXT NOT NULL,\n feedback TEXT NULL,\n points TINYINT NOT NULL,\n PRIMARY KEY (aid),\n KEY question_nid (question_nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {quiz_result} (\n rid INTEGER UNSIGNED NOT NULL,\n quiz_nid INTEGER UNSIGNED NOT NULL,\n uid INTEGER UNSIGNED NOT NULL,\n time_start INTEGER UNSIGNED DEFAULT 0,\n time_end INTEGER UNSIGNED DEFAULT 0,\n released INTEGER UNSIGNED DEFAULT 0,\n score TINYINT NOT NULL DEFAULT 0,\n PRIMARY KEY (rid),\n KEY quiz_nid (quiz_nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {quiz_question_results} (\n result_rid INTEGER UNSIGNED NOT NULL,\n question_nid INTEGER UNSIGNED NOT NULL,\n answer TEXT NOT NULL,\n PRIMARY KEY (result_rid, question_nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {quiz} (\n nid INT_UNSIGNED NOT NULL,\n number_of_questions SMALLINT_UNSIGNED NOT NULL,\n pass_rate SMALLINT_UNSIGNED NOT NULL,\n summary_pass TEXT,\n summary_default LONGTEXT,\n shuffle SMALLINT_UNSIGNED NOT NULL,\n backwards_navigation TINYINT UNSIGNED NOT NULL,\n feedback_time TINYINT UNSIGNED NOT NULL,\n quiz_open INT_UNSIGNED DEFAULT 0,\n quiz_close INT_UNSIGNED DEFAULT 0,\n takes SMALLINT_UNSIGNED NOT NULL,\n time_limit INT_UNSIGNED DEFAULT 0 NOT NULL,\n quiz_always SMALLINT NOT NULL default 0,\n PRIMARY KEY(nid)\n );");
db_query("CREATE TABLE {quiz_questions} (\n quiz_nid INT_UNSIGNED NOT NULL,\n question_nid INT_UNSIGNED NOT NULL,\n question_status SMALLINT_UNSIGNED NOT NULL,\n PRIMARY KEY (quiz_nid, question_nid)\n );");
db_query("CREATE TABLE {quiz_question} (\n nid INT_UNSIGNED NOT NULL,\n properties VARCHAR(255) NOT NULL,\n PRIMARY KEY (nid)\n );");
db_query("CREATE TABLE {quiz_question_answer} (\n aid INT_UNSIGNED NOT NULL,\n question_nid INT_UNSIGNED NOT NULL,\n answer TEXT NOT NULL,\n feedback TEXT NULL,\n points SMALLINT NOT NULL,\n PRIMARY KEY (aid)\n );");
db_query("CREATE INDEX {quiz_question_answer}_question_nid_idx \n ON {quiz_question_answer} (question_nid)");
db_query("CREATE TABLE {quiz_result} (\n rid INT_UNSIGNED NOT NULL,\n quiz_nid INT_UNSIGNED NOT NULL,\n uid INT_UNSIGNED NOT NULL,\n time_start INT_UNSIGNED DEFAULT 0,\n time_end INT_UNSIGNED DEFAULT 0,\n released INT_UNSIGNED DEFAULT 0,\n score SMALLINT NOT NULL,\n PRIMARY KEY (rid)\n );");
db_query("CREATE INDEX {quiz_result}_quiz_nid_idx \n ON {quiz_result} (quiz_nid)");
db_query("CREATE TABLE {quiz_question_results} (\n result_rid INT_UNSIGNED NOT NULL,\n question_nid INT_UNSIGNED NOT NULL,\n answer TEXT NOT NULL,\n PRIMARY KEY (result_rid, question_nid)\n );");
break;
}
}
function quiz_uninstall() {
db_query('DROP TABLE {quiz_question_results}');
db_query('DROP TABLE {quiz_result}');
db_query('DROP TABLE {quiz_question_answer}');
db_query('DROP TABLE {quiz_question}');
db_query('DROP TABLE {quiz_questions}');
db_query('DROP TABLE {quiz}');
db_query('DELETE FROM node, node_revisions USING node LEFT JOIN node_revisions USING (nid) WHERE type IN ("quiz", "multichoice")');
variable_del('quiz_name');
variable_del('quiz_default_close');
variable_del('quiz_use_passfail');
variable_del('quiz_default_pass_rate');
}