You are here

multichoice.install in Quiz 7.6

Sponsored by: Norwegian Centre for Telemedicine Code: falcon

multichoice Install (a quiz question type)

File

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

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

/**
 * Implements hook_install().
 */
function multichoice_install() {

  // Add body field to multichoice node
  quiz_question_add_body_field('multichoice');
  variable_set('node_options_multichoice', array(
    'status',
  ));
}

/**
 * Implements hook_schema().
 */
function multichoice_schema() {

  // Stores the users answers to a question.
  $schema['quiz_multichoice_user_answers'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'result_id' => 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,
      ),
      'choice_order' => array(
        'type' => 'text',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'indexes' => array(
      'answer_id' => array(
        'result_id',
        'question_nid',
        'question_vid',
      ),
    ),
  );
  $schema['quiz_multichoice_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',
    ),
    'indexes' => array(
      'answer_id' => array(
        'user_answer_id',
      ),
    ),
  );
  $schema['quiz_multichoice_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_multichoice_answers'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'answer' => array(
        'type' => 'text',
      ),
      'answer_format' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'feedback_if_chosen' => array(
        'type' => 'text',
      ),
      'feedback_if_chosen_format' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'feedback_if_not_chosen' => array(
        'type' => 'text',
      ),
      'feedback_if_not_chosen_format' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'score_if_chosen' => array(
        'type' => 'int',
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'score_if_not_chosen' => array(
        'type' => 'int',
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'question_nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'question_vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'weight' => array(
        'type' => 'int',
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'indexes' => array(
      'quiz_id' => array(
        'question_nid',
        'question_vid',
      ),
    ),
  );
  $schema['quiz_multichoice_user_settings'] = array(
    'fields' => array(
      'uid' => 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(
      'uid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function multichoice_uninstall() {
  $var = array(
    'multichoice_def_scoring',
    'multichoice_def_num_of_alts',
  );
  foreach ($var as $v) {
    variable_del($v);
  }
}

/**
 * Add weights for multichoice alternatives.
 */
function multichoice_update_7501() {
  db_add_field('quiz_multichoice_answers', 'weight', array(
    'type' => 'int',
    'unsigned' => FALSE,
    'not null' => TRUE,
    'default' => 0,
  ));

  // Lol.
  db_query('UPDATE {quiz_multichoice_answers} SET weight = id');
  return t('Added weights for multichoice alternatives.');
}

Functions

Namesort descending Description
multichoice_install Implements hook_install().
multichoice_schema Implements hook_schema().
multichoice_uninstall Implements hook_uninstall().
multichoice_update_7501 Add weights for multichoice alternatives.