You are here

biblio_xml.install in Bibliography Module 7

Database table creation for biblio_xml module.

File

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

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

/**
 * Implementation of hook_install().
 */
function biblio_xml_install() {
  _save_xml_maps();
}

/**
 *
 */
function biblio_xml_uninstall() {
  if (db_table_exists('biblio_type_maps')) {
    db_delete('biblio_type_maps')
      ->condition('format', 'endnote8')
      ->execute();
    db_delete('biblio_type_maps')
      ->condition('format', 'endnote7')
      ->execute();
  }
}

/**
 *
 */
function biblio_xml_enable() {
  biblio_xml_set_system_weight();
}

/**
 *
 */
function biblio_xml_set_system_weight() {
  db_update('system')
    ->fields(array(
    'weight' => 26,
  ))
    ->condition('name', 'biblio_xml')
    ->execute();
}

/**
 *
 */
function _save_xml_maps() {
  _save_endnote7_maps();
  _save_endnote8_maps();
}

/**
 *
 */
function _save_endnote7_maps() {
  $format = 'endnote7';
  $typemap = _get_endnote7_type_map();
  $typenames = _get_endnote7_type_names();
  $fieldmap = _get_endnote7_field_map();
  $maps = array_merge($typemap, $typenames, $fieldmap);
  biblio_save_map($maps);
}

/**
 *
 */
function _save_endnote8_maps() {
  $typemap = _get_endnote8_type_map();
  $typenames = _get_endnote8_type_names();
  $fieldmap = _get_endnote8_field_map();
  $maps = array_merge($typemap, $typenames, $fieldmap);
  biblio_save_map($maps);
}

/**
 *
 */
function _reset_endnote_xml_map($version, $type) {
  $count = db_query("SELECT COUNT(*) FROM {biblio_type_maps} WHERE format=:format", array(
    ':format' => $version,
  ))
    ->fetchField();

  // Update.
  if ($count && $type) {
    $function = '_get_' . $version . '_' . $type;
    if (!function_exists($function)) {
      return;
    }
    $map = $function();
    drupal_write_record('biblio_type_maps', $map, 'format');
    db_update('biblio_type_maps')
      ->fields($map)
      ->condition('format', $version)
      ->execute();
  }
  else {
    db_delete('biblio_type_maps')
      ->condition('format', $version)
      ->execute();
    $save_maps = '_save_' . $version . '_maps';
    $save_maps();
  }
}

/**
 *
 */
function _get_endnote8_type_map() {
  $map['type_map'] = serialize(array(
    // Artwork.
    2 => 112,
    // Audio Visual.
    3 => 114,
    // bill.
    4 => 117,
    // Book Section.
    5 => 101,
    // Book.
    6 => 100,
    // Case.
    7 => 116,
    // software.
    9 => 113,
    // Journal Article.
    17 => 102,
    // Conference Proceeding.
    10 => 104,
    // Web page.
    12 => 107,
    // Generic.
    13 => 129,
    // Hearing.
    14 => 115,
    // magazine_article.
    19 => 106,
    // Map.
    20 => 122,
    // film.
    21 => 110,
    // Broadcast.
    21 => 111,
    // newspaper_article.
    23 => 105,
    // Patent.
    25 => 119,
    // Personal communication.
    26 => 120,
    // Report.
    27 => 109,
    // Edited Book.
    28 => 129,
    // Statute.
    31 => 118,
    // Thesis.
    32 => 108,
    // Unpublished.
    34 => 124,
    // manuscript.
    36 => 121,
    // Figure.
    37 => 129,
    // chart.
    38 => 123,
    // Equation.
    39 => 129,
    // Electronic article.
    43 => 129,
    // Electronic book.
    44 => 129,
    // Online database.
    45 => 125,
    // government_document.
    46 => 126,
    // conference_paper.
    47 => 103,
    // Online multimedia.
    48 => 129,
    // Classical Work.
    49 => 127,
    // legal_ruling.
    50 => 128,
    // Dictionary.
    52 => 129,
    // Encyclopedia.
    53 => 129,
    // Grant.
    54 => 129,
  ));
  $map['format'] = 'endnote8';
  return $map;
}

/**
 *
 */
function _get_endnote8_type_names() {
  $map['type_names'] = serialize(array(
    2 => 'Artwork',
    3 => 'Audio Visual',
    4 => 'Bill',
    5 => 'Book Section',
    6 => 'Book',
    7 => 'Case',
    9 => 'Software',
    17 => 'Journal Article',
    10 => 'Conference Proceeding',
    12 => 'Web page',
    13 => 'Generic',
    14 => 'Hearing',
    19 => 'Magazine Article',
    20 => 'Map',
    21 => 'Film',
    21 => 'Broadcast',
    23 => 'Newspaper Article',
    25 => 'Patent',
    26 => 'Personal Communication',
    27 => 'Report',
    28 => 'Edited Book',
    31 => 'Statute',
    32 => 'Thesis',
    34 => 'Unpublished',
    36 => 'Manuscript',
    37 => 'Figure',
    38 => 'Chart',
    39 => 'Equation',
    43 => 'Electronic Article',
    44 => 'Electronic Book',
    45 => 'Online Database',
    46 => 'Government Document',
    47 => 'Conference Paper',
    48 => 'Online Multimedia',
    49 => 'Classical Work',
    50 => 'Legal Ruling',
    52 => 'Dictionary',
    53 => 'Encyclopedia',
    54 => 'Grant',
  ));
  $map['format'] = 'endnote8';
  return $map;
}

/**
 *
 */
function _get_endnote8_field_map() {
  $map['field_map'] = serialize(array(
    'source-app' => '',
    'rec-number' => '',
    'ref-type' => 'biblio_type',
    'auth-address' => 'biblio_auth_address',
    'auth-affiliaton' => '',
    'secondary-title' => 'biblio_secondary_title',
    'tertiary-title' => 'biblio_tertiary_title',
    'alt-title' => 'biblio_alternate_title',
    'short-title' => 'biblio_short_title',
    'translated-title' => 'biblio_translated_title',
    'full-title' => 'biblio_secondary_title',
    'abbr-1' => 'biblio_short_title',
    'abbr-2' => '',
    'abbr-3' => '',
    'pages' => 'biblio_pages',
    'volume' => 'biblio_volume',
    'number' => 'biblio_number',
    'issue' => 'biblio_issue',
    'secondary-volume' => '',
    'secondary-issue' => '',
    'num-vols' => 'biblio_number_of_volumes',
    'edition' => 'biblio_edition',
    'section' => 'biblio_section',
    'reprint-edition' => 'biblio_reprint_edition',
    'reprint-status' => '',
    'year' => 'biblio_year',
    'pub-dates' => 'biblio_date',
    'copyright-dates' => '',
    'pub-location' => 'biblio_place_published',
    'publisher' => 'biblio_publisher',
    'orig-pub' => 'biblio_original_publication',
    'isbn' => 'biblio_isbn',
    'accession-num' => 'biblio_accession_number',
    'call-num' => 'biblio_call_number',
    'report-id' => '',
    'coden' => '',
    'electronic-resource-num' => '',
    'abstract' => 'biblio_abst_e',
    'label' => 'biblio_label',
    'image' => '',
    'caption' => '',
    'notes' => 'biblio_notes',
    'research-notes' => 'biblio_research_notes',
    'work-type' => 'biblio_type_of_work',
    'reviewed-item' => '',
    'availability' => '',
    'remote-source' => '',
    'meeting-place' => '',
    'work-location' => '',
    'work-extent' => '',
    'pack-method' => '',
    'size' => '',
    'repro-ratio' => '',
    'remote-database-name' => 'biblio_remote_db_name',
    'remote-database-provider' => 'biblio_remote_db_provider',
    'language' => 'biblio_lang',
    'web-urls' => '',
    'pdf-urls' => '',
    'text-urls' => '',
    'image-urls' => '',
    'related-urls' => 'biblio_url',
    'access-date' => 'biblio_access_date',
    'modified-date' => '',
    'custom1' => 'biblio_custom1',
    'custom2' => 'biblio_custom2',
    'custom3' => 'biblio_custom3',
    'custom4' => 'biblio_custom4',
    'custom5' => 'biblio_custom5',
    'custom6' => 'biblio_custom6',
    'custom7' => 'biblio_custom7',
    'misc1' => '',
    'misc2' => '',
    'misc3' => '',
  ));
  $map['format'] = 'endnote8';
  return $map;
}

/**
 *
 */
function _get_endnote7_type_map() {
  $map['type_map'] = serialize(array(
    // Journal Article.
    0 => 102,
    // Book.
    1 => 100,
    // Thesis.
    2 => 108,
    // Conference Proceedings.
    3 => 103,
    // Personal Communication.
    4 => 120,
    // NewsPaper Article.
    5 => 105,
    // Computer Program.
    6 => 113,
    // Book Section.
    7 => 101,
    // Magazine Article.
    8 => 106,
    // Edited Book.
    9 => 100,
    // Report.
    10 => 109,
    // Map.
    11 => 122,
    // Audiovisual Material.
    12 => 114,
    // Artwork.
    13 => 112,
    // Patent.
    15 => 119,
    // Electronic Source.
    16 => 107,
    // Bill.
    17 => 117,
    // Case.
    18 => 116,
    // Hearing.
    19 => 115,
    // Manuscript.
    20 => 121,
    // Film or Broadcast.
    21 => 110,
    // Statute.
    22 => 118,
    // Chart or Table.
    26 => 123,
    // Generic.
    31 => 129,
  ));
  $map['format'] = 'endnote7';
  return $map;
}

/**
 *
 */
function _get_endnote7_type_names() {
  $map['type_names'] = serialize(array(
    0 => 'Journal Article',
    1 => 'Book',
    2 => 'Thesis',
    3 => 'Conference Proceedings',
    4 => 'Personal Communication',
    5 => 'NewsPaper Article',
    6 => 'Computer Program',
    7 => 'Book Section',
    8 => 'Magazine Article',
    9 => 'Edited Book',
    10 => 'Report',
    11 => 'Map',
    12 => 'Audiovisual Material',
    13 => 'Artwork',
    15 => 'Patent',
    16 => 'Electronic Source',
    17 => 'Bill',
    18 => 'Case',
    19 => 'Hearing',
    20 => 'Manuscript',
    21 => 'Film or Broadcast',
    22 => 'Statute',
    26 => 'Chart or Table',
    31 => 'Generic',
  ));
  $map['format'] = 'endnote7';
  return $map;
}

/**
 *
 */
function _get_endnote7_field_map() {
  $map['field_map'] = serialize(array(
    'REFERENCE_TYPE' => 'biblio_type',
    'REFNUM' => '',
    'YEAR' => 'biblio_year',
    'SECONDARY_TITLE' => 'biblio_secondary_title',
    'PLACE_PUBLISHED' => 'biblio_place_published',
    'PUBLISHER' => 'biblio_publisher',
    'VOLUME' => 'biblio_volume',
    'ISSUE' => 'biblio_issue',
    'NUMBER_OF_VOLUMES' => 'biblio_number_of_volumes',
    'NUMBER' => 'biblio_number',
    'PAGES' => 'biblio_pages',
    'SECTION' => 'biblio_section',
    'TERTIARY_TITLE' => 'biblio_tertiary_title',
    'EDITION' => 'biblio_edition',
    'DATE' => 'biblio_date',
    'TYPE_OF_WORK' => 'biblio_type_of_work',
    'SHORT_TITLE' => 'biblio_short_title',
    'ALTERNATE_TITLE' => 'biblio_alternate_title',
    'ISBN' => 'biblio_isbn',
    'ORIGINAL_PUB' => 'biblio_original_publication',
    'REPRINT_EDITION' => 'biblio_reprint_edition',
    'REVIEWED_ITEM' => '',
    'CUSTOM1' => 'biblio_custom1',
    'CUSTOM2' => 'biblio_custom2',
    'CUSTOM3' => 'biblio_custom3',
    'CUSTOM4' => 'biblio_custom4',
    'CUSTOM5' => 'biblio_custom5',
    'CUSTOM6' => 'biblio_custom6',
    'ACCESSION_NUMBER' => 'biblio_accession_number',
    'CALL_NUMBER' => 'biblio_call_number',
    'LABEL' => 'biblio_label',
    'KEYWORD' => 'biblio_keywords',
    'ABSTRACT' => 'biblio_abst_e',
    'NOTES' => 'biblio_notes',
    'URL' => 'biblio_url',
    'AUTHOR_ADDRESS' => '',
    'IMAGE' => '',
    'CAPTION' => '',
  ));
  $map['format'] = 'endnote7';
  return $map;
}

/**
 * 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_xml_schema() {
  $schema = array();
  $schema['biblio_xml'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'biblio_xml_md5' => array(
        'type' => 'char',
        'length' => 32,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}