X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FKoha.pm;h=06b2ec5289b6b55ce0b6466adb96c6542c2a597e;hb=c9441f48955360829ef7f8e97a54afa7aa31fc5b;hp=2f94aa07e5d31b2225626ec83a0e9eda335c898f;hpb=2ea6fdec156419fbbdd5f64da927d0b2b45e751c;p=koha_gimpoz diff --git a/C4/Koha.pm b/C4/Koha.pm index 2f94aa07e5..06b2ec5289 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -2,6 +2,7 @@ package C4::Koha; # Copyright 2000-2002 Katipo Communications # Parts Copyright 2010 Nelsonville Public Library +# Parts copyright 2010 BibLibre # # This file is part of Koha. # @@ -57,8 +58,8 @@ BEGIN { &GetKohaAuthorisedValues &GetKohaAuthorisedValuesFromField &GetKohaAuthorisedValueLib - &GetAuthorisedValueByCode - &GetKohaImageurlFromAuthorisedValues + &GetAuthorisedValueByCode + &GetKohaImageurlFromAuthorisedValues &GetAuthValCode &GetNormalizedUPC &GetNormalizedISBN @@ -957,9 +958,9 @@ sub GetKohaImageurlFromAuthorisedValues { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT imageurl FROM authorised_values WHERE category=? AND lib =?"); $sth->execute( $category, $lib ); - while ( my $data = $sth->fetchrow_hashref ) { - return $data->{'imageurl'}; - } + while ( my $data = $sth->fetchrow_hashref ) { + return $data->{'imageurl'}; + } } =head2 GetAuthValCode @@ -1050,7 +1051,7 @@ sub GetAuthorisedValueCategories { my $sth = $dbh->prepare("SELECT DISTINCT category FROM authorised_values ORDER BY category"); $sth->execute; my @results; - while (my $category = $sth->fetchrow_array) { + while (defined (my $category = $sth->fetchrow_array) ) { push @results, $category; } return \@results; @@ -1060,19 +1061,20 @@ sub GetAuthorisedValueCategories { $authhorised_value = GetAuthorisedValueByCode( $category, $authvalcode ); -Return an hashref of the authorised value represented by $authvalcode. +Return the lib attribute from authorised_values from the row identified +by the passed category and code =cut sub GetAuthorisedValueByCode { - my ( $category, $authvalcode ) = @_; - + my ( $category, $authvalcode ) = @_; + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT lib FROM authorised_values WHERE category=? AND authorised_value =?"); $sth->execute( $category, $authvalcode ); - while ( my $data = $sth->fetchrow_hashref ) { - return $data->{'lib'}; - } + while ( my $data = $sth->fetchrow_hashref ) { + return $data->{'lib'}; + } } =head2 GetKohaAuthorisedValues @@ -1201,21 +1203,22 @@ sub GetNormalizedUPC { my ($record,$marcflavour) = @_; my (@fields,$upc); - if ($marcflavour eq 'MARC21') { - @fields = $record->field('024'); + if ($marcflavour eq 'UNIMARC') { + @fields = $record->field('072'); foreach my $field (@fields) { - my $indicator = $field->indicator(1); my $upc = _normalize_match_point($field->subfield('a')); - if ($indicator == 1 and $upc ne '') { + if ($upc ne '') { return $upc; } } + } - else { # assume unimarc if not marc21 - @fields = $record->field('072'); + else { # assume marc21 if not unimarc + @fields = $record->field('024'); foreach my $field (@fields) { + my $indicator = $field->indicator(1); my $upc = _normalize_match_point($field->subfield('a')); - if ($upc ne '') { + if ($indicator == 1 and $upc ne '') { return $upc; } } @@ -1235,10 +1238,10 @@ sub GetNormalizedISBN { } return undef unless $record; - if ($marcflavour eq 'MARC21') { - @fields = $record->field('020'); + if ($marcflavour eq 'UNIMARC') { + @fields = $record->field('010'); foreach my $field (@fields) { - $isbn = $field->subfield('a'); + my $isbn = $field->subfield('a'); if ($isbn) { return _isbn_cleanup($isbn); } else { @@ -1246,10 +1249,10 @@ sub GetNormalizedISBN { } } } - else { # assume unimarc if not marc21 - @fields = $record->field('010'); + else { # assume marc21 if not unimarc + @fields = $record->field('020'); foreach my $field (@fields) { - my $isbn = $field->subfield('a'); + $isbn = $field->subfield('a'); if ($isbn) { return _isbn_cleanup($isbn); } else { @@ -1257,28 +1260,27 @@ sub GetNormalizedISBN { } } } - } sub GetNormalizedEAN { my ($record,$marcflavour) = @_; my (@fields,$ean); - if ($marcflavour eq 'MARC21') { - @fields = $record->field('024'); + if ($marcflavour eq 'UNIMARC') { + @fields = $record->field('073'); foreach my $field (@fields) { - my $indicator = $field->indicator(1); $ean = _normalize_match_point($field->subfield('a')); - if ($indicator == 3 and $ean ne '') { + if ($ean ne '') { return $ean; } } } - else { # assume unimarc if not marc21 - @fields = $record->field('073'); + else { # assume marc21 if not unimarc + @fields = $record->field('024'); foreach my $field (@fields) { + my $indicator = $field->indicator(1); $ean = _normalize_match_point($field->subfield('a')); - if ($ean ne '') { + if ($indicator == 3 and $ean ne '') { return $ean; } } @@ -1288,7 +1290,10 @@ sub GetNormalizedOCLCNumber { my ($record,$marcflavour) = @_; my (@fields,$oclc); - if ($marcflavour eq 'MARC21') { + if ($marcflavour eq 'UNIMARC') { + # TODO: add UNIMARC fields + } + else { # assume marc21 if not unimarc @fields = $record->field('035'); foreach my $field (@fields) { $oclc = $field->subfield('a'); @@ -1300,8 +1305,6 @@ sub GetNormalizedOCLCNumber { } } } - else { # TODO: add UNIMARC fields - } } sub _normalize_match_point {