You are here

biblio_ris.install in Bibliography Module 7

Same filename and directory in other branches
  1. 6.2 modules/RIS/biblio_ris.install
  2. 7.2 modules/RIS/biblio_ris.install

Database table creation for biblio_ris module.

File

modules/RIS/biblio_ris.install
View source
<?php

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

/**
 * Implementation of hook_install().
 */
function biblio_ris_install() {
  _save_ris_maps();
}

/**
 *
 */
function biblio_ris_uninstall() {
  if (db_table_exists('biblio_type_maps')) {
    db_delete('biblio_type_maps')
      ->condition('format', 'ris')
      ->execute();
  }
}

/**
 *
 */
function biblio_ris_enable() {
  biblio_ris_set_system_weight();
}

/**
 *
 */
function biblio_ris_set_system_weight() {
  db_update('system')
    ->fields(array(
    'weight' => 27,
  ))
    ->condition('name', 'biblio_ris')
    ->execute();
}

/**
 *
 */
function _save_ris_maps() {
  $typemap = _get_ris_type_map();
  $typenames = _get_ris_type_names();
  $fieldmap = _get_ris_field_map();
  $maps = array_merge($typemap, $typenames, $fieldmap);
  biblio_save_map($maps);
}

/**
 *
 */
function _reset_ris_map($type) {
  $count = db_query("SELECT COUNT(*) FROM {biblio_type_maps} WHERE format='ris'")
    ->fetchField();

  // Update.
  if ($count && $type) {
    $function = '_get_ris_' . $type;
    if (!function_exists($function)) {
      return;
    }
    $map = $function();
    db_update('biblio_type_maps')
      ->fields($map)
      ->condition('format', 'ris')
      ->execute();
  }
  else {
    db_delete('biblio_type_maps')
      ->condition('format', 'ris')
      ->execute();
    _save_ris_maps();
  }
}

/**
 *
 */
function _get_ris_type_map() {
  $map['type_map'] = serialize(array(
    'ABST' => 129,
    'ADVS' => 114,
    'ART' => 112,
    'BILL' => 117,
    'BOOK' => 100,
    'CASE' => 116,
    'CHAP' => 101,
    'COMP' => 113,
    'CONF' => 103,
    'CTLG' => 129,
    'DATA' => 125,
    'ELEC' => 129,
    'GEN' => 129,
    'HEAR' => 115,
    'ICOMM' => 107,
    'INPR' => 129,
    'JFULL' => 129,
    'JOUR' => 102,
    'MAP' => 122,
    'MGZN' => 106,
    'MPCT' => 110,
    'MUSIC' => 129,
    'NEWS' => 105,
    'PAMP' => 129,
    'PAT' => 119,
    'PCOMM' => 120,
    'RPRT' => 109,
    'SER' => 100,
    'SLIDE' => 129,
    'SOUND' => 129,
    'STAT' => 125,
    'THES' => 108,
    'UNBILl' => 129,
    'UNPB' => 124,
    'VIDEO' => 129,
  ));
  $map['format'] = 'ris';
  return $map;
}

/**
 *
 */
function _get_ris_type_names() {
  $map['type_names'] = serialize(array(
    'ABST' => 'Abstract',
    'ADVS' => 'Audiovisual material',
    'ART' => 'Art Work',
    'BILL' => 'Bill/Resolution',
    'BOOK' => 'Book, Whole',
    'CASE' => 'Case',
    'CHAP' => 'Book chapter',
    'COMP' => 'Computer program',
    'CONF' => 'Conference proceeding',
    'CTLG' => 'Catalog',
    'DATA' => 'Data file',
    'ELEC' => 'Electronic Citation',
    'GEN' => 'Generic',
    'HEAR' => 'Hearing',
    'ICOMM' => 'Internet Communication',
    'INPR' => 'In Press',
    'JFULL' => 'Journal (full)',
    'JOUR' => 'Journal',
    'MAP' => 'Map',
    'MGZN' => 'Magazine article',
    'MPCT' => 'Motion picture',
    'MUSIC' => 'Music score',
    'NEWS' => 'Newspaper',
    'PAMP' => 'Pamphlet',
    'PAT' => 'Patent',
    'PCOMM' => 'Personal communication',
    'RPRT' => 'Report',
    'SER' => 'Serial (Book, Monograph)',
    'SLIDE' => 'Slide',
    'SOUND' => 'Sound recording',
    'STAT' => 'Statute',
    'THES' => 'Thesis/Dissertation',
    'UNBILl' => 'Unenacted bill/resolution',
    'UNPB' => 'Unpublished work',
    'VIDEO' => 'Video recording',
  ));
  $map['format'] = 'ris';
  return $map;
}

/**
 *
 */
function _get_ris_field_map() {
  $map['field_map'] = serialize(array(
    // - Reference ID (not imported to reference software)
    'ID' => '',
    // - Primary title.
    'T1' => 'title',
    // - Book title.
    'TI' => 'title',
    // - Book title.
    'BT' => 'title',
    // - Title of unpublished reference.
    'CT' => 'title',
    // - Primary author.
    'A1' => '',
    // - Secondary author (each name on separate line)
    'A2' => '',
    // - Author (syntax. Last name, First name, Suffix)
    'AU' => '',
    // - Primary date.
    'Y1' => 'biblio_year',
    // - Publication year (YYYY/MM/DD)
    'PY' => '',
    // - Notes.
    'N1' => 'biblio_notes',
    // - Keywords (each keyword must be on separate line preceded KW -)
    'KW' => '',
    // - Reprint status (IN FILE, NOT IN FILE, ON REQUEST (MM/DD/YY))
    'RP' => '',
    // - Start page number.
    'SP' => '',
    // - Ending page number.
    'EP' => '',
    // - Periodical full name.
    'JF' => 'biblio_secondary_title',
    // - Periodical standard abbreviation.
    'JO' => 'biblio_short_title',
    // - Periodical in which article was published.
    'JA' => 'biblio_secondary_title',
    // - Periodical name //- User abbreviation 1.
    'J1' => 'biblio_short_title',
    // - Periodical name - User abbreviation 2.
    'J2' => 'biblio_short_title',
    // - Volume number.
    'VL' => 'biblio_volume',
    // - Issue number.
    'IS' => 'biblio_issue',
    // - Issue number.
    'CP' => 'biblio_issue',
    // - Title secondary.
    'T2' => 'biblio_secondary_title',
    // - City of Publication.
    'CY' => 'biblio_place_published',
    // - Publisher.
    'PB' => 'biblio_publisher',
    // - User definable 1.
    'U1' => 'biblio_custom1',
    // - User definable 2.
    'U2' => 'biblio_custom2',
    // - User definable 3.
    'U3' => 'biblio_custom3',
    // - User definable 4.
    'U4' => 'biblio_custom4',
    // - User definable 5.
    'U5' => 'biblio_custom5',
    // - Title series.
    'T3' => 'biblio_tertiary_title',
    // - Abstract.
    'AB' => 'biblio_abst_e',
    // - Abstract.
    'N2' => 'biblio_abst_e',
    // - ISSN/ISBN (e.g. ISSN XXXX-XXXX)
    'SN' => 'biblio_isbn',
    // - Availability.
    'AV' => '',
    // - Misc. 1.
    'M1' => '',
    // - Misc. 3.
    'M3' => '',
    // - Address.
    'AD' => '',
    // - Web/URL.
    'UR' => 'biblio_url',
    // - Link to PDF.
    'L1' => '',
    // - Link to Full-text.
    'L2' => '',
    // - Related records.
    'L3' => '',
    // - Images.
    'L4' => '',
    // - End of Reference (must be the last tag)
    'ER' => '',
  ));
  $map['format'] = 'ris';
  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_ris_schema() {
  $schema = array();
  $schema['biblio_ris'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'biblio_ris_md5' => array(
        'type' => 'char',
        'length' => 32,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}