You are here

multichoice.install in Quiz 5.2

Same filename and directory in other branches
  1. 6.2 multichoice.install

File

multichoice.install
View source
<?php

/**
 * Implementation of hook_install()
 */
function multichoice_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':

      /**
       * Stores correct answers for multichoice quiz.
       */

      // Create the quiz node user answers multichoice table.
      db_query("CREATE TABLE {quiz_multichoice_user_answers} (\n          question_nid INTEGER UNSIGNED NOT NULL,\n          question_vid INTEGER UNSIGNED NOT NULL,\n          result_id INTEGER UNSIGNED NOT NULL,\n          answer_id INTEGER UNSIGNED NOT NULL,\n          PRIMARY KEY(result_id, question_nid, question_vid, answer_id)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");

      /**
       * Stores user answers for multichoice quiz.
       */

      // Create the quiz node answers multichoice table.
      db_query("CREATE TABLE {quiz_multichoice_answers} (\n          answer_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,\n          nid INTEGER UNSIGNED NOT NULL,\n          vid INTEGER UNSIGNED NOT NULL,\n          answer varchar(255) NOT NULL,\n          feedback LONGTEXT,\n          result_option INTEGER UNSIGNED DEFAULT 0,\n          is_correct TINYINT UNSIGNED DEFAULT 0,\n          PRIMARY KEY(answer_id)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':

      /**
       * Stores correct answers for multichoice quiz.
       */

      // Create the quiz node user answers multichoice table.
      db_query("CREATE TABLE {quiz_multichoice_user_answers} (\n          question_nid int_unsigned NOT NULL,\n          question_vid int_unsigned NOT NULL,\n          result_id int_unsigned NOT NULL,\n          answer_id int_unsigned NOT NULL,\n          PRIMARY KEY(result_id, question_nid, question_vid, answer_id)\n        );");

      /**
       * Stores user answers for multichoice quiz.
       */

      // Create the quiz node answers multichoice table.
      db_query("CREATE TABLE {quiz_multichoice_answers} (\n          answer_id SERIAL,\n          nid int_unsigned NOT NULL,\n          vid int_unsigned NOT NULL,\n          answer varchar(255) NOT NULL,\n          feedback text,\n          result_option int_unsigned DEFAULT 0,\n          is_correct smallint_unsigned DEFAULT 0,\n          PRIMARY KEY(answer_id)\n        );");
      break;
  }

  // Default the "Show Author and Date" for this question type to OFF.
  $temp_array = variable_get('theme_settings', $default);
  $temp_array['toggle_node_info_multichoice'] = 0;
  variable_set('theme_settings', $temp_array);
}

/**
 * Implementation of hook_uninstall()
 */
function multichoice_uninstall() {

  // Remove the two tables we created for this module.
  if (db_table_exists('quiz_multichoice_answers')) {
    db_query('DROP TABLE {quiz_multichoice_answers}');
  }
  if (db_table_exists('quiz_multichoice_user_answers')) {
    db_query('DROP TABLE {quiz_multichoice_user_answers}');
  }

  // Erase any saved variable settings from the database.
  db_query("DELETE FROM {variable} WHERE name LIKE '%s%%'", 'multichoice_');

  // Delete from nodes and node_revisions.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query('DELETE FROM {node}, {node_revisions}, {quiz_node_question_properties} USING node LEFT JOIN {node_revisions} USING (nid) LEFT JOIN {quiz_node_question_properties} USING (nid) WHERE type IN ("multichoice")');
      break;
    case 'pgsql':
      db_query("DELETE FROM {quiz_node_question_properties} WHERE nid IN (SELECT nid FROM {node} WHERE type IN ('multichoice'))");
      db_query("DELETE FROM {node_revisions} WHERE nid IN (SELECT nid FROM {node} WHERE type IN ('multichoice'))");
      db_query("DELETE FROM {node} WHERE type IN ('multichoice')");
      break;
  }

  // Truncate the cache so users don't run into any unexpected errors.
  cache_clear_all('variables', 'cache');

  // Inform the user that uninstall was sucessful.
  drupal_set_message(t("The Multichoice module, it's settings, and all saved questions were successfully removed."));
}

Functions

Namesort descending Description
multichoice_install Implementation of hook_install()
multichoice_uninstall Implementation of hook_uninstall()