You are here

function quiz_install in Quiz 5

Same name and namespace in other branches
  1. 8.6 quiz.install \quiz_install()
  2. 8.4 quiz.install \quiz_install()
  3. 8.5 quiz.install \quiz_install()
  4. 5.2 quiz.install \quiz_install()
  5. 6.6 quiz.install \quiz_install()
  6. 6.2 quiz.install \quiz_install()
  7. 6.3 quiz.install \quiz_install()
  8. 6.4 quiz.install \quiz_install()
  9. 6.5 quiz.install \quiz_install()
  10. 7.6 quiz.install \quiz_install()
  11. 7 quiz.install \quiz_install()
  12. 7.4 quiz.install \quiz_install()
  13. 7.5 quiz.install \quiz_install()
  14. 6.x quiz.install \quiz_install()

Implementation of hook_install()

File

./quiz.install, line 6

Code

function quiz_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':

      // Create the quiz table
      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 */;");

      // Create the questions table
      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 */;");

      // Create the question table
      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 */;");

      // Create the question answer table
      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 */;");

      // Create the results table
      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 */;");

      // Create the question results table
      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':

      // Create the quiz table
      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      );");

      // Create the questions table
      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      );");

      // Create the question table
      db_query("CREATE TABLE {quiz_question} (\n        nid INT_UNSIGNED NOT NULL,\n        properties VARCHAR(255) NOT NULL,\n        PRIMARY KEY (nid)\n      );");

      // Create the question answer table
      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)");

      // Create the results table
      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)");

      // Create the question results table
      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;
  }
}