You are here

choice.install in Quiz 6.6

Sponsored by: Norwegian Centre for Telemedicine Code: falcon

Choice Install (a quiz question type)

File

question_types/choice/choice.install
View source
<?php

/**
 * Sponsored by: Norwegian Centre for Telemedicine
 * Code: falcon
 * 
 * @file
 * Choice Install (a quiz question type)
 */

/**
 * Implementation of hook_install()
 */
function choice_install() {
  drupal_install_schema('choice');
}

/**
 * Implementation of hook_schema().
 */
function choice_schema() {

  // Stores the users answers to a question.
  $schema['quiz_choice_user_answers'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'result_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'choice_order' => array(
        'type' => 'text',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );

  /*
   * Stores answer collection id.
   * Pos = 0 means the collection won't be available as a predefined collection set.
   * Pos > 0 is the collections position in the predefined collection list.
   */
  $schema['quiz_choice_user_answer_multi'] = array(
    'fields' => array(
      'user_answer_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'answer_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'user_answer_id',
      'answer_id',
    ),
  );
  $schema['quiz_choice_properties'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'choice_multi' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'choice_random' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'choice_boolean' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
      'vid',
    ),
  );

  /*
   * Holds each answer in the answer_collections.
   */
  $schema['quiz_choice_answer'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'answer' => array(
        'type' => 'text',
      ),
      'answer_format' => array(
        'type' => 'int',
      ),
      'feedback_if_chosen' => array(
        'type' => 'text',
      ),
      'feedback_if_chosen_format' => array(
        'type' => 'int',
      ),
      'feedback_if_not_chosen' => array(
        'type' => 'text',
      ),
      'feedback_if_not_chosen_format' => array(
        'type' => 'int',
      ),
      'score_if_chosen' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'score_if_not_chosen' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'question_nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'question_vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $schema['quiz_choice_user_settings'] = array(
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'last_nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'last_vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'uid',
    ),
  );
  return $schema;
}
function choice_update_6400() {
  drupal_rebuild_theme_registry();
  return array();
}
function choice_update_6401() {
  drupal_rebuild_theme_registry();
  return array();
}
function choice_update_6402() {
  $status = array();
  $definition = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_change_field($status, 'quiz_choice_properties', 'multi', 'choice_multi', $definition);
  return $status;
}
function choice_update_6403() {
  $status = array();
  $definition = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_field($status, 'quiz_choice_properties', 'choice_random', $definition);
  db_add_field($status, 'quiz_choice_properties', 'choice_boolean', $definition);
  db_add_field($status, 'quiz_choice_user_answers', 'choice_order', array(
    'type' => 'text',
  ));
  return $status;
}
function choice_update_6404() {
  $status = array();
  $table = array(
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'last_nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'last_vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'uid',
    ),
  );
  db_create_table($status, 'quiz_choice_user_settings', $table);
  return $status;
}

/**
 * Implementation of hook_uninstall()
 */
function choice_uninstall() {
  drupal_uninstall_schema('choice');
  cache_clear_all('variables', 'cache');
  drupal_set_message(t("The Choice module has been uninstalled. Choice nodes may still exist, but they will not function properly."));
}