You are here

function biblio_marc_import in Bibliography Module 6

1 call to biblio_marc_import()
biblio_import in ./biblio.import.export.inc
Import data from a file and return the node ids created.

File

./biblio.import.export.inc, line 632
Functions that are used to import and export biblio data.

Code

function biblio_marc_import($file, $terms, $batch, $session_id) {
  $nids = array();
  module_load_include('php', 'biblio', 'marcParse/php-marc');
  $marcfile = new File($file->filepath);
  while ($record = $marcfile
    ->next()) {
    $node = array();
    $node['biblio_contributors'] = array();
    $node['biblio_keywords'] = array();
    $leader = $record
      ->leader();
    $pubtype = $leader[6];
    $pubtype .= $leader[7];
    $node['biblio_type'] = marc_type_map($pubtype);
    foreach ($record
      ->fields() as $fields) {
      foreach ($fields as $field) {
        $tagnum = $field->tagno;
        switch ($tagnum) {
          case '008':
            $data = $field
              ->data();
            $node['biblio_year'] = substr($data, 7, 4);
            $node['biblio_lang'] = substr($data, 35, 3);
            break;
          case '020':
            $node['biblio_isbn'] = $field
              ->subfield('a');
            break;
          case '022':
            $node['biblio_issn'] = $field
              ->subfield('a');
            break;
          case '024':
            $node['biblio_other_number'] = $field
              ->subfield('a');
            break;
          case '050':

          //LIBRARY OF CONGRESS CALL NUMBER
          case '055':

          //CLASSIFICATION NUMBERS ASSIGNED IN CANADA
          case '060':

            //NATIONAL LIBRARY OF MEDICINE CALL NUMBER
            $node['biblio_call_number'] = $field
              ->subfield('a') . ' ' . $field
              ->subfield('b');
            break;
          case '130':
            $node['title'] = str_replace(' /', '', $field
              ->subfield('a'));
            break;
          case '210':
            $node['biblio_short_title'] = str_replace(' /', '', $field
              ->subfield('a'));
            break;
          case '245':
            $node['title'] = str_replace(' /', '', $field
              ->subfield('a')) . ' ' . $field
              ->subfield('b');
            break;
          case '250':
            $node['biblio_edition'] = $field
              ->subfield('a');
            break;
          case '260':
            $node['biblio_place_published'] = str_replace(' :', '', $field
              ->subfield('a'));
            $node['biblio_publisher'] = $field
              ->subfield('b');
            $node['biblio_date'] = $field
              ->subfield('c');
            break;
          case '300':
            $node['biblio_pages'] = $field
              ->subfield('a');
            break;
          case '490':
            $node['biblio_volume'] = $field
              ->subfield('v');
            break;
          case $tagnum >= 500 && $tagnum <= 599:
            $value = $field
              ->subfield('a');
            if (!empty($value)) {
              $node['biblio_notes'] .= $value;
            }
            break;
          case '650':
            foreach ($field
              ->subfields() as $subject) {
              $node['biblio_keywords'][] = $subject[0];
            }
            break;
          case '100':
          case '700':
            $value = $field
              ->subfield('a');
            if (!empty($value)) {
              $node['biblio_contributors'][1][] = array(
                'name' => $value,
                'auth_type' => 1,
              );
            }
            break;
          case '110':
          case '710':
            $node['biblio_contributors'][5][] = array(
              'name' => $field
                ->subfield('a'),
              'auth_type' => 5,
            );
            break;
          case '856':
            $value = $field
              ->subfield('u');
            if (!empty($value)) {
              $node['biblio_url'] = $value;
            }
            break;
        }
      }
    }
    if (!empty($node)) {
      if (!empty($terms)) {
        if (!isset($node['taxonomy'])) {
          $node['taxonomy'] = array();
        }
        $node['taxonomy'] = array_merge($terms, $node['taxonomy']);
      }
      $nid = biblio_save_node($node, $batch, $session_id);
      if (isset($nid)) {
        $nids[] = $nid;
      }
    }
  }
  return $nids;
}