You are here

advpoll_ranking.install in Advanced Poll 7

Install file for Advanced Ranking Poll

File

advpoll_ranking/advpoll_ranking.install
View source
<?php

/**
 * @file
 * Install file for Advanced Ranking Poll
 * 
 * */

/**
 * Implements hook_uninstall().
 *
 */
function advpoll_ranking_uninstall() {

  /*
   * Get rid of polls that are either borda or ranking polls.
   */
  $nid = array();
  $result = db_query("SELECT entity_id FROM {field_data_advpoll_behavior} f \n                      WHERE f.advpoll_behavior_value = 'borda' \n                      OR f.advpoll_behavior_value = 'runoff'");
  foreach ($result as $row) {
    $nid[] = $row->entity_id;
  }
  if ($nid) {
    db_delete('votingapi_vote')
      ->condition('entity_id', $nid, 'IN')
      ->execute();

    // Delete all the nodes at once
    // http://api.drupal.org/api/function/node_delete_multiple/7
    node_delete_multiple($nid);
  }

  // fetch the t function for use in uninstall
  $t = get_t();

  // set field back to its default settings.
  $field = array(
    'field_name' => 'advpoll_behavior',
    'settings' => array(
      'allowed_values' => array(
        'approval' => $t('Approval voting'),
        'pool' => $t('Pool votes and choices'),
      ),
      'allowed_values_function' => '',
    ),
  );
  field_update_field($field);
}
function advpoll_ranking_install() {

  // fetch the t function for use in install
  $t = get_t();

  // Add borda and run-off to allow ranking-style display and voting.
  $field = array(
    'field_name' => 'advpoll_behavior',
    'settings' => array(
      'allowed_values' => array(
        'approval' => $t('Approval voting'),
        'pool' => $t('Pool votes and choices'),
        'borda' => $t('Borda count (Ranking Poll)'),
        'runoff' => $t('Instant-runoff (Ranking Poll)'),
      ),
      'allowed_values_function' => '',
    ),
  );
  field_update_field($field);
}