You are here

biblio_tagged.install in Bibliography Module 6.2

Database table creation for biblio_tagged module.

File

modules/endnote/biblio_tagged.install
View source
<?php

/**
 * @file
 * Database table creation for biblio_tagged module.
 */

/**
 * Implementation of hook_install().
 */
function biblio_tagged_install() {
  drupal_install_schema('biblio_tagged');
  _save_tagged_maps();
}
function biblio_tagged_uninstall() {
  drupal_uninstall_schema('biblio_tagged');
  if (db_table_exists('biblio_type_maps')) {
    db_query("DELETE FROM {biblio_type_maps} WHERE format = 'tagged'");
  }
}
function biblio_tagged_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'install') {
    if (!module_exists('biblio')) {
      $requirements['biblio_tagged'] = array(
        'title' => $t('Biblio'),
        'description' => $t('The Biblio module must be installed first'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    if (!db_table_exists('biblio_type_maps')) {
      $requirements['biblio_tagged_table'] = array(
        'title' => $t('Biblio table '),
        'description' => $t("Missing db table 'biblio_type_maps', you probably have to update your biblio module"),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}
function biblio_tagged_enable() {
  biblio_tagged_set_system_weight();
}
function biblio_tagged_set_system_weight() {
  return update_sql("UPDATE {system} SET weight = 22 WHERE name = 'biblio_tagged'");
}
function _get_tagged_type_map() {
  $map['type_map'] = serialize(array(
    "Journal Article" => 102,
    "Conference Paper" => 103,
    "Conference Proceedings" => 104,
    "Report" => 109,
    "Book" => 100,
    "Edited Book" => 100,
    "Book Section" => 101,
    "Thesis" => 108,
    "Patent" => 119,
    "Generic" => 129,
    "Newspaper Article" => 105,
    "Magazine Article" => 106,
    "Web Page" => 107,
    "Film or Broadcast" => 110,
    "Artwork" => 112,
    "Audiovisual Material" => 114,
    "Hearing" => 115,
    "Case" => 116,
    "Bill" => 117,
    "Statute" => 118,
    "Personal Communication" => 120,
    "Manuscript" => 121,
    "Map" => 122,
    "Chart or Table" => 123,
    "Unpublished Work" => 124,
    "Online Database" => 125,
    "Government Document" => 126,
    "Classical Work" => 127,
    "Legal Rule or Regulation" => 128,
  ));
  $map['format'] = 'tagged';
  return $map;
}
function _get_tagged_type_names() {
  $map['type_names'] = serialize(array(
    "Journal Article" => "Journal Article",
    "Conference Paper" => "Conference Paper",
    "Conference Proceedings" => "Conference Proceedings",
    "Report" => "Report",
    "Book" => "Book",
    "Edited Book" => "Edited Book",
    "Book Section" => "Book Section",
    "Thesis" => "Thesis",
    "Patent" => "Patent",
    "Generic" => "Generic",
    "Newspaper Article" => "Newspaper Article",
    "Magazine Article" => "Magazine Article",
    "Web Page" => "Web Page",
    "Film or Broadcast" => "Film or Broadcast",
    "Artwork" => "Artwork",
    "Audiovisual Material" => "Audiovisual Material",
    "Hearing" => "Hearing",
    "Case" => "Case",
    "Bill" => "Bill",
    "Statute" => "Statute",
    "Personal Communication" => "Personal Communication",
    "Manuscript" => "Manuscript",
    "Map" => "Map",
    "Chart or Table" => "Chart or Table",
    "Unpublished Work" => "Unpublished Work",
    "Online Database" => "Online Database",
    "Government Document" => "Government Document",
    "Classical Work" => "Classical Work",
    "Legal Rule or Regulation" => "Legal Rule or Regulation",
  ));
  $map['format'] = 'tagged';
  return $map;
}
function _get_tagged_field_map() {
  $map['field_map'] = serialize(array(
    '%B' => 'biblio_secondary_title',
    '%C' => 'biblio_place_published',
    '%D' => 'biblio_year',
    '%F' => 'biblio_label',
    '%G' => 'biblio_lang',
    '%I' => 'biblio_publisher',
    '%J' => 'biblio_secondary_title',
    '%K' => 'biblio_keywords',
    '%L' => 'biblio_call_number',
    '%M' => 'biblio_accession_number',
    '%N' => 'biblio_issue',
    '%P' => 'biblio_pages',
    '%R' => 'biblio_doi',
    '%S' => 'biblio_tertiary_title',
    '%U' => 'biblio_url',
    '%V' => 'biblio_volume',
    '%1' => 'biblio_custom1',
    '%2' => 'biblio_custom2',
    '%3' => 'biblio_custom3',
    '%4' => 'biblio_custom4',
    '%#' => 'biblio_custom5',
    '%$' => 'biblio_custom6',
    '%]' => 'biblio_custom7',
    '%6' => 'biblio_number_of_volumes',
    '%7' => 'biblio_edition',
    '%8' => 'biblio_date',
    '%9' => 'biblio_type_of_work',
    '%?' => '',
    '%@' => 'biblio_isbn',
    '%<' => 'biblio_research_notes',
    '%!' => 'biblio_short_title',
    '%&' => 'biblio_section',
    '%(' => 'biblio_original_publication',
    '%)' => 'biblio_reprint_edition',
    '%*' => '',
    '%+' => '',
  ));
  $map['format'] = 'tagged';
  return $map;
}
function _save_tagged_maps() {
  $typemap = _get_tagged_type_map();
  $typenames = _get_tagged_type_names();
  $fieldmap = _get_tagged_field_map();
  $maps = array_merge($typemap, $typenames, $fieldmap);
  db_query("INSERT INTO {biblio_type_maps} (format,type_map,type_names,field_map) VALUES ('%s','%s','%s','%s')", array(
    $maps['format'],
    $maps['type_map'],
    $maps['type_names'],
    $maps['field_map'],
  ));

  //drupal_write_record('biblio_type_maps', $maps);
}
function _reset_tagged_map($type) {
  $count = db_result(db_query("SELECT COUNT(*) FROM {biblio_type_maps} WHERE format='tagged'"));
  if ($count && $type) {

    //update
    $function = '_get_tagged_' . $type;
    if (!function_exists($function)) {
      return;
    }
    $map = $function();
    drupal_write_record('biblio_type_maps', $map, 'format');
  }
  else {

    // install
    db_query("DELETE FROM {biblio_type_maps} WHERE format='tagged'");
    _save_tagged_maps();
  }
}

/**
 * Implementation of hook_schema().
 *
 * Note:  Pro Drupal Development models use of t() to translate 'description'
 * for field definitions, but Drupal core does not use them.  We follow core.
 */
function biblio_tagged_schema() {
  $schema = array();
  $schema['biblio_tagged'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'biblio_tagged_md5' => array(
        'type' => 'char',
        'length' => 32,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}