You are here

function biblio_marc_biblio_import in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/marcParse/biblio_marc.module \biblio_marc_biblio_import()
  2. 7.2 modules/marcParse/biblio_marc.module \biblio_marc_biblio_import()

File

modules/marcParse/biblio_marc.module, line 44

Code

function biblio_marc_biblio_import($file, $terms = array(), $batch = FALSE, $session_id = NULL, $save = TRUE, $string = FALSE) {
  $nids = array();
  $dups = array();
  module_load_include('php', 'biblio_marc', 'php-marc');
  $marcfile = new File($file->uri);
  while ($record = $marcfile
    ->next()) {
    $node = new stdClass();
    $node->biblio_contributors = array();
    $fields = $record
      ->fields();
    $leader = $record
      ->leader();
    $pubtype = $leader[6];
    $pubtype .= $leader[7];
    $node->biblio_type = _biblio_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;

          // LIBRARY OF CONGRESS CALL NUMBER.
          case '050':

          // CLASSIFICATION NUMBERS ASSIGNED IN CANADA.
          case '055':

          // NATIONAL LIBRARY OF MEDICINE CALL NUMBER.
          case '060':
            $node->biblio_call_number = $field
              ->subfield('a');
            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[] = array(
                'name' => $value,
                'auth_category' => 1,
                'auth_type' => 1,
              );
            }
            break;
          case '110':
          case '710':
            $node->biblio_contributors[] = array(
              'name' => $field
                ->subfield('a'),
              'auth_category' => 5,
              'auth_type' => 5,
            );
            break;
          case '856':
            $value = $field
              ->subfield('u');
            if (!empty($value)) {
              $node->biblio_url = $value;
            }
            break;
        }
      }
    }
    if (!empty($node)) {
      $node->biblio_marc_md5 = md5(serialize($node));
      if (!($dup = biblio_marc_check_md5($node->biblio_marc_md5))) {
        biblio_save_node($node, $terms, $batch, $session_id);
        if (!empty($node->nid)) {
          $nids[] = $node->nid;
        }
      }
      else {
        $dups[] = $dup;
      }
    }
  }
  return array(
    $nids,
    $dups,
  );
}