X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FKoha.pm;h=0192989ecb83b04d30cac1cfcdb5deea4af0b439;hb=443cd120f382607d57dd399cb37c1a9fccdeeba7;hp=2bdcc284b8f40e2efc6ff263f47c60e6628d76d9;hpb=aaa0cdb9e82930b2d920ee02b71673e6e236b5f8;p=koha.git diff --git a/C4/Koha.pm b/C4/Koha.pm index 2bdcc284b8..0192989ecb 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. # @@ -22,10 +23,7 @@ package C4::Koha; use strict; #use warnings; FIXME - Bug 2505 use C4::Context; -use C4::Output; -use URI::Split qw(uri_split); use Memoize; -use Business::ISBN; use vars qw($VERSION @ISA @EXPORT $DEBUG); @@ -57,6 +55,8 @@ BEGIN { &GetKohaAuthorisedValues &GetKohaAuthorisedValuesFromField &GetKohaAuthorisedValueLib + &GetAuthorisedValueByCode + &GetKohaImageurlFromAuthorisedValues &GetAuthValCode &GetNormalizedUPC &GetNormalizedISBN @@ -452,7 +452,7 @@ sub getitemtypeimagedir { if ($src eq 'intranet') { return C4::Context->config('intrahtdocs') . '/' .C4::Context->preference('template') . '/img/itemtypeimg'; } else { - return C4::Context->config('opachtdocs') . '/' . C4::Context->preference('template') . '/itemtypeimg'; + return C4::Context->config('opachtdocs') . '/' . C4::Context->preference('opacthemes') . '/itemtypeimg'; } } @@ -461,7 +461,7 @@ sub getitemtypeimagesrc { if ($src eq 'intranet') { return '/intranet-tmpl' . '/' . C4::Context->preference('template') . '/img/itemtypeimg'; } else { - return '/opac-tmpl' . '/' . C4::Context->preference('template') . '/itemtypeimg'; + return '/opac-tmpl' . '/' . C4::Context->preference('opacthemes') . '/itemtypeimg'; } } @@ -469,8 +469,9 @@ sub getitemtypeimagelocation($$) { my ( $src, $image ) = @_; return '' if ( !$image ); + require URI::Split; - my $scheme = ( uri_split( $image ) )[0]; + my $scheme = ( URI::Split::uri_split( $image ) )[0]; return $image if ( $scheme ); @@ -570,9 +571,8 @@ sub getImageSets { my @imagesets = (); # list of hasrefs of image set data to pass to template my @subdirectories = _getSubdirectoryNames( $paths->{'staff'}{'filesystem'} ); -warn $paths->{'staff'}{'filesystem'}; foreach my $imagesubdir ( @subdirectories ) { - warn $imagesubdir; + warn $imagesubdir if $DEBUG; my @imagelist = (); # hashrefs of image info my @imagenames = _getImagesFromDirectory( File::Spec->catfile( $paths->{'staff'}{'filesystem'}, $imagesubdir ) ); my $imagesetactive = 0; @@ -678,95 +678,89 @@ sub getFacets { if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) { $facets = [ { - link_value => 'su-to', - label_value => 'Topics', - tags => - [ '600', '601', '602', '603', '604', '605', '606', '610' ], - subfield => 'a', + idx => 'su-to', + label => 'Topics', + tags => [ qw/ 600a 601a 602a 603a 604a 605a 606ax 610a/ ], + sep => ' - ', }, { - link_value => 'su-geo', - label_value => 'Places', - tags => ['651'], - subfield => 'a', + idx => 'su-geo', + label => 'Places', + tags => [ qw/ 651a / ], + sep => ' - ', }, { - link_value => 'su-ut', - label_value => 'Titles', - tags => [ '500', '501', '502', '503', '504', ], - subfield => 'a', + idx => 'su-ut', + label => 'Titles', + tags => [ qw/ 500a 501a 502a 503a 504a / ], + sep => ', ', }, { - link_value => 'au', - label_value => 'Authors', - tags => [ '700', '701', '702', ], - subfield => 'a', + idx => 'au', + label => 'Authors', + tags => [ qw/ 700ab 701ab 702ab / ], + sep => ', ', }, { - link_value => 'se', - label_value => 'Series', - tags => ['225'], - subfield => 'a', + idx => 'se', + label => 'Series', + tags => [ qw/ 225a / ], + sep => ', ', }, - ]; - - my $library_facet; - - $library_facet = { - link_value => 'branch', - label_value => 'Libraries', - tags => [ '995', ], - subfield => 'b', - expanded => '1', - }; - push @$facets, $library_facet unless C4::Context->preference("singleBranchMode"); + ]; + my $library_facet = { + idx => 'branch', + label => 'Libraries', + tags => [ qw/ 995b / ], + expanded => '1', + }; + push @$facets, $library_facet unless C4::Context->preference("singleBranchMode"); } else { $facets = [ { - link_value => 'su-to', - label_value => 'Topics', - tags => ['650'], - subfield => 'a', + idx => 'su-to', + label => 'Topics', + tags => [ qw/ 650a / ], + sep => '--', }, - # { - # link_value => 'su-na', - # label_value => 'People and Organizations', - # tags => ['600', '610', '611'], - # subfield => 'a', + # idx => 'su-na', + # label => 'People and Organizations', + # tags => [ qw/ 600a 610a 611a / ], + # sep => 'a', # }, { - link_value => 'su-geo', - label_value => 'Places', - tags => ['651'], - subfield => 'a', + idx => 'su-geo', + label => 'Places', + tags => [ qw/ 651a / ], + sep => '--', }, { - link_value => 'su-ut', - label_value => 'Titles', - tags => ['630'], - subfield => 'a', + idx => 'su-ut', + label => 'Titles', + tags => [ qw/ 630a / ], + sep => '--', }, { - link_value => 'au', - label_value => 'Authors', - tags => [ '100', '110', '700', ], - subfield => 'a', + idx => 'au', + label => 'Authors', + tags => [ qw/ 100a 110a 700a / ], + sep => ', ', }, { - link_value => 'se', - label_value => 'Series', - tags => [ '440', '490', ], - subfield => 'a', + idx => 'se', + label => 'Series', + tags => [ qw/ 440a 490a / ], + sep => ', ', }, ]; my $library_facet; $library_facet = { - link_value => 'branch', - label_value => 'Libraries', - tags => [ '952', ], - subfield => 'b', + idx => 'branch', + label => 'Libraries', + tags => [ qw/ 952b / ], + sep => ', ', expanded => '1', }; push @$facets, $library_facet unless C4::Context->preference("singleBranchMode"); @@ -941,6 +935,25 @@ sub displayServers { return \@primaryserverloop; } + +=head2 GetKohaImageurlFromAuthorisedValues + +$authhorised_value = GetKohaImageurlFromAuthorisedValues( $category, $authvalcode ); + +Return the first url of the authorised value image represented by $lib. + +=cut + +sub GetKohaImageurlFromAuthorisedValues { + my ( $category, $lib ) = @_; + 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'}; + } +} + =head2 GetAuthValCode $authvalcode = GetAuthValCode($kohafield,$frameworkcode); @@ -1029,12 +1042,32 @@ 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; } +=head2 GetAuthorisedValueByCode + +$authhorised_value = GetAuthorisedValueByCode( $category, $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 $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'}; + } +} + =head2 GetKohaAuthorisedValues Takes $kohafield, $fwcode as parameters. @@ -1161,21 +1194,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; } } @@ -1195,10 +1229,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 { @@ -1206,10 +1240,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 { @@ -1217,28 +1251,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; } } @@ -1248,7 +1281,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'); @@ -1260,8 +1296,6 @@ sub GetNormalizedOCLCNumber { } } } - else { # TODO: add UNIMARC fields - } } sub _normalize_match_point { @@ -1273,6 +1307,7 @@ sub _normalize_match_point { } sub _isbn_cleanup { + require Business::ISBN; my $isbn = Business::ISBN->new( $_[0] ); if ( $isbn ) { $isbn = $isbn->as_isbn10 if $isbn->type eq 'ISBN13';