X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FKoha.pm;h=36e81dad192b63064c40f8d726ae449595c1a799;hb=eb04d174d91201b05b6e348dc672f9351dc0aaf0;hp=86bf45b18931cb2bd72bf12a4612c674ddae90f4;hpb=960458dee4a9c09506f48fa73950c0e2da3611e7;p=koha.git diff --git a/C4/Koha.pm b/C4/Koha.pm index 86bf45b189..36e81dad19 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -32,25 +32,20 @@ use DateTime::Format::MySQL; use Business::ISBN; use autouse 'Data::cselectall_arrayref' => qw(Dumper); use DBI qw(:sql_types); -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); +use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG); BEGIN { - $VERSION = 3.07.00.049; require Exporter; @ISA = qw(Exporter); @EXPORT = qw( - &slashifyDate - &subfield_is_koha_internal_p &GetPrinters &GetPrinter &GetItemTypes &getitemtypeinfo &GetItemTypesCategorized &GetItemTypesByCategory &GetSupportName &GetSupportList - &get_itemtypeinfos_of &getframeworks &getframeworkinfo &GetFrameworksLoop &getallthemes &getFacets - &displayServers &getnbpages &get_infos_of &get_notforloan_label_of @@ -59,15 +54,12 @@ BEGIN { &getitemtypeimagelocation &GetAuthorisedValues &GetAuthorisedValueCategories - &IsAuthorisedValueCategory &GetKohaAuthorisedValues &GetKohaAuthorisedValuesFromField &GetKohaAuthorisedValuesMapping &GetKohaAuthorisedValueLib &GetAuthorisedValueByCode - &GetKohaImageurlFromAuthorisedValues &GetAuthValCode - &AddAuthorisedValue &GetNormalizedUPC &GetNormalizedISBN &GetNormalizedEAN @@ -100,34 +92,6 @@ Koha.pm provides many functions for Koha scripts. =cut -=head2 slashifyDate - - $slash_date = &slashifyDate($dash_date); - -Takes a string of the form "DD-MM-YYYY" (or anything separated by -dashes), converts it to the form "YYYY/MM/DD", and returns the result. - -=cut - -sub slashifyDate { - - # accepts a date of the form xx-xx-xx[xx] and returns it in the - # form xx/xx/xx[xx] - my @dateOut = split( '-', shift ); - return ("$dateOut[2]/$dateOut[1]/$dateOut[0]"); -} - -# FIXME.. this should be moved to a MARC-specific module -sub subfield_is_koha_internal_p { - my ($subfield) = @_; - - # We could match on 'lib' and 'tab' (and 'mandatory', & more to come!) - # But real MARC subfields are always single-character - # so it really is safer just to check the length - - return length $subfield != 1; -} - =head2 GetSupportName $itemtypename = &GetSupportName($codestring); @@ -339,22 +303,6 @@ sub GetItemTypesByCategory { return @$tmp; } -sub get_itemtypeinfos_of { - my @itemtypes = @_; - - my $placeholders = join( ', ', map { '?' } @itemtypes ); - my $query = <<"END_SQL"; -SELECT itemtype, - description, - imageurl, - notforloan - FROM itemtypes - WHERE itemtype IN ( $placeholders ) -END_SQL - - return get_infos_of( $query, 'itemtype', undef, \@itemtypes ); -} - =head2 getframework $frameworks = &getframework(); @@ -794,8 +742,7 @@ sub getFacets { } ]; - unless ( C4::Context->preference("singleBranchMode") - || Koha::Libraries->search->count == 1 ) + unless ( Koha::Libraries->search->count == 1 ) { my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets'); if ( $DisplayLibraryFacets eq 'both' @@ -876,8 +823,7 @@ sub getFacets { }, ]; - unless ( C4::Context->preference("singleBranchMode") - || Koha::Libraries->search->count == 1 ) + unless ( Koha::Libraries->search->count == 1 ) { my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets'); if ( $DisplayLibraryFacets eq 'both' @@ -1010,92 +956,6 @@ SELECT lib, return \%notforloan_label_of; } -=head2 displayServers - - my $servers = displayServers(); - my $servers = displayServers( $position ); - my $servers = displayServers( $position, $type ); - -displayServers returns a listref of hashrefs, each containing -information about available z3950 servers. Each hashref has a format -like: - - { - 'checked' => 'checked', - 'encoding' => 'utf8', - 'icon' => undef, - 'id' => 'LIBRARY OF CONGRESS', - 'label' => '', - 'name' => 'server', - 'opensearch' => '', - 'value' => 'lx2.loc.gov:210/', - 'zed' => 1, - }, - -=cut - -sub displayServers { - my ( $position, $type ) = @_; - my $dbh = C4::Context->dbh; - - my $strsth = 'SELECT * FROM z3950servers'; - my @where_clauses; - my @bind_params; - - if ($position) { - push @bind_params, $position; - push @where_clauses, ' position = ? '; - } - - if ($type) { - push @bind_params, $type; - push @where_clauses, ' type = ? '; - } - - # reassemble where clause from where clause pieces - if (@where_clauses) { - $strsth .= ' WHERE ' . join( ' AND ', @where_clauses ); - } - - my $rq = $dbh->prepare($strsth); - $rq->execute(@bind_params); - my @primaryserverloop; - - while ( my $data = $rq->fetchrow_hashref ) { - push @primaryserverloop, - { label => $data->{description}, - id => $data->{name}, - name => "server", - value => $data->{host} . ":" . $data->{port} . "/" . $data->{database}, - encoding => ( $data->{encoding} ? $data->{encoding} : "iso-5426" ), - checked => "checked", - icon => $data->{icon}, - zed => $data->{type} eq 'zed', - opensearch => $data->{type} eq 'opensearch' - }; - } - 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); @@ -1244,28 +1104,6 @@ sub GetAuthorisedValueCategories { return \@results; } -=head2 IsAuthorisedValueCategory - - $is_auth_val_category = IsAuthorisedValueCategory($category); - -Returns whether a given category name is a valid one - -=cut - -sub IsAuthorisedValueCategory { - my $category = shift; - my $query = ' - SELECT category - FROM authorised_values - WHERE category=? - LIMIT 1 - '; - my $sth = C4::Context->dbh->prepare($query); - $sth->execute($category); - $sth->fetchrow ? return 1 - : return 0; -} - =head2 GetAuthorisedValueByCode $authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac ); @@ -1432,26 +1270,6 @@ sub GetKohaAuthorisedValueLib { return $value; } -=head2 AddAuthorisedValue - - AddAuthorisedValue($category, $authorised_value, $lib, $lib_opac, $imageurl); - -Create a new authorised value. - -=cut - -sub AddAuthorisedValue { - my ($category, $authorised_value, $lib, $lib_opac, $imageurl) = @_; - - my $dbh = C4::Context->dbh; - my $query = qq{ - INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) - VALUES (?,?,?,?,?) - }; - my $sth = $dbh->prepare($query); - $sth->execute($category, $authorised_value, $lib, $lib_opac, $imageurl); -} - =head2 display_marc_indicators my $display_form = C4::Koha::display_marc_indicators($field); @@ -1476,29 +1294,27 @@ sub display_marc_indicators { sub GetNormalizedUPC { my ($marcrecord,$marcflavour) = @_; - if ($marcrecord) { - if ($marcflavour eq 'UNIMARC') { - my @fields = $marcrecord->field('072'); - foreach my $field (@fields) { - my $upc = _normalize_match_point($field->subfield('a')); - if ($upc) { - return $upc; - } + return unless $marcrecord; + if ($marcflavour eq 'UNIMARC') { + my @fields = $marcrecord->field('072'); + foreach my $field (@fields) { + my $upc = _normalize_match_point($field->subfield('a')); + if ($upc) { + return $upc; } - } - else { # assume marc21 if not unimarc - my @fields = $marcrecord->field('024'); - foreach my $field (@fields) { - my $indicator = $field->indicator(1); - my $upc = _normalize_match_point($field->subfield('a')); - if ($upc && $indicator == 1 ) { - return $upc; - } + + } + else { # assume marc21 if not unimarc + my @fields = $marcrecord->field('024'); + foreach my $field (@fields) { + my $indicator = $field->indicator(1); + my $upc = _normalize_match_point($field->subfield('a')); + if ($upc && $indicator == 1 ) { + return $upc; } } } - return; } # Normalizes and returns the first valid ISBN found in the record @@ -1511,60 +1327,60 @@ sub GetNormalizedISBN { ($isbn) = split(/\|/, $isbn ); return _isbn_cleanup($isbn); } - if ($marcrecord) { - - if ($marcflavour eq 'UNIMARC') { - my @fields = $marcrecord->field('010'); - foreach my $field (@fields) { - my $isbn = $field->subfield('a'); - if ($isbn) { - return _isbn_cleanup($isbn); - } + + return unless $marcrecord; + + if ($marcflavour eq 'UNIMARC') { + my @fields = $marcrecord->field('010'); + foreach my $field (@fields) { + my $isbn = $field->subfield('a'); + if ($isbn) { + return _isbn_cleanup($isbn); } } - else { # assume marc21 if not unimarc - my @fields = $marcrecord->field('020'); - foreach my $field (@fields) { - $isbn = $field->subfield('a'); - if ($isbn) { - return _isbn_cleanup($isbn); - } + } + else { # assume marc21 if not unimarc + my @fields = $marcrecord->field('020'); + foreach my $field (@fields) { + $isbn = $field->subfield('a'); + if ($isbn) { + return _isbn_cleanup($isbn); } } } - return; } sub GetNormalizedEAN { my ($marcrecord,$marcflavour) = @_; - if ($marcrecord) { - if ($marcflavour eq 'UNIMARC') { - my @fields = $marcrecord->field('073'); - foreach my $field (@fields) { - my $ean = _normalize_match_point($field->subfield('a')); - if ( $ean ) { - return $ean; - } + return unless $marcrecord; + + if ($marcflavour eq 'UNIMARC') { + my @fields = $marcrecord->field('073'); + foreach my $field (@fields) { + my $ean = _normalize_match_point($field->subfield('a')); + if ( $ean ) { + return $ean; } } - else { # assume marc21 if not unimarc - my @fields = $marcrecord->field('024'); - foreach my $field (@fields) { - my $indicator = $field->indicator(1); - my $ean = _normalize_match_point($field->subfield('a')); - if ( $ean && $indicator == 3 ) { - return $ean; - } + } + else { # assume marc21 if not unimarc + my @fields = $marcrecord->field('024'); + foreach my $field (@fields) { + my $indicator = $field->indicator(1); + my $ean = _normalize_match_point($field->subfield('a')); + if ( $ean && $indicator == 3 ) { + return $ean; } } } - return; } sub GetNormalizedOCLCNumber { my ($marcrecord,$marcflavour) = @_; - if ($marcrecord && $marcflavour ne 'UNIMARC' ) { + return unless $marcrecord; + + if ($marcflavour ne 'UNIMARC' ) { my @fields = $marcrecord->field('035'); foreach my $field (@fields) { my $oclc = $field->subfield('a'); @@ -1573,8 +1389,10 @@ sub GetNormalizedOCLCNumber { return $oclc; } } + } else { + # TODO for UNIMARC } - return; + return } sub GetAuthvalueDropbox {