Bug 29803: Prevent local cover image to be hidden if Coce is enabled
[srvgit] / C4 / Koha.pm
index dd0a165..681d6ff 100644 (file)
@@ -20,52 +20,45 @@ package C4::Koha;
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 
-use strict;
-#use warnings; FIXME - Bug 2505
+use Modern::Perl;
 
 use C4::Context;
 use Koha::Caches;
-use Koha::DateUtils qw(dt_from_string);
 use Koha::AuthorisedValues;
 use Koha::Libraries;
 use Koha::MarcSubfieldStructures;
-use DateTime::Format::MySQL;
 use Business::ISBN;
 use Business::ISSN;
 use autouse 'Data::cselectall_arrayref' => qw(Dumper);
-use DBI qw(:sql_types);
-use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG);
 
+our (@ISA, @EXPORT_OK);
 BEGIN {
-       require Exporter;
-       @ISA    = qw(Exporter);
-       @EXPORT = qw(
-        &GetPrinters &GetPrinter
-        &GetItemTypesCategorized
-        &getallthemes
-        &getFacets
-        &getnbpages
-               &getitemtypeimagedir
-               &getitemtypeimagesrc
-               &getitemtypeimagelocation
-               &GetAuthorisedValues
-               &GetNormalizedUPC
-               &GetNormalizedISBN
-               &GetNormalizedEAN
-               &GetNormalizedOCLCNumber
-        &xml_escape
-
-        &GetVariationsOfISBN
-        &GetVariationsOfISBNs
-        &NormalizeISBN
-        &GetVariationsOfISSN
-        &GetVariationsOfISSNs
-        &NormalizeISSN
-
-               $DEBUG
-       );
-       $DEBUG = 0;
-@EXPORT_OK = qw( GetDailyQuote );
+    require Exporter;
+    @ISA       = qw(Exporter);
+    @EXPORT_OK = qw(
+      GetItemTypesCategorized
+      getallthemes
+      getFacets
+      getImageSets
+      getnbpages
+      getitemtypeimagedir
+      getitemtypeimagesrc
+      getitemtypeimagelocation
+      GetAuthorisedValues
+      GetNormalizedUPC
+      GetNormalizedISBN
+      GetNormalizedEAN
+      GetNormalizedOCLCNumber
+      xml_escape
+
+      GetVariationsOfISBN
+      GetVariationsOfISBNs
+      NormalizeISBN
+      GetVariationsOfISSN
+      GetVariationsOfISSNs
+      NormalizeISSN
+
+    );
 }
 
 =head1 NAME
@@ -102,7 +95,7 @@ sub GetItemTypesCategorized {
         SELECT itemtype, description, imageurl, hideinopac, 0 as 'iscat' FROM itemtypes WHERE ISNULL(searchcategory) or length(searchcategory) = 0
         UNION
         SELECT DISTINCT searchcategory AS `itemtype`,
-                        authorised_values.lib_opac AS description,
+                        COALESCE(authorised_values.lib_opac,authorised_values.lib) AS description,
                         authorised_values.imageurl AS imageurl,
                         hideinopac, 1 as 'iscat'
         FROM itemtypes
@@ -110,7 +103,7 @@ sub GetItemTypesCategorized {
         WHERE searchcategory > '' and hideinopac=1
         UNION
         SELECT DISTINCT searchcategory AS `itemtype`,
-                        authorised_values.lib_opac AS description,
+                        COALESCE(authorised_values.lib_opac,authorised_values.lib) AS description,
                         authorised_values.imageurl AS imageurl,
                         hideinopac, 1 as 'iscat'
         FROM itemtypes
@@ -255,7 +248,6 @@ sub getImageSets {
     my @imagesets = (); # list of hasrefs of image set data to pass to template
     my @subdirectories = _getSubdirectoryNames( $paths->{'staff'}{'filesystem'} );
     foreach my $imagesubdir ( @subdirectories ) {
-    warn $imagesubdir if $DEBUG;
         my @imagelist     = (); # hashrefs of image info
         my @imagenames = _getImagesFromDirectory( File::Spec->catfile( $paths->{'staff'}{'filesystem'}, $imagesubdir ) );
         my $imagesetactive = 0;
@@ -277,45 +269,6 @@ sub getImageSets {
     return \@imagesets;
 }
 
-=head2 GetPrinters
-
-  $printers = &GetPrinters();
-  @queues = keys %$printers;
-
-Returns information about existing printer queues.
-
-C<$printers> is a reference-to-hash whose keys are the print queues
-defined in the printers table of the Koha database. The values are
-references-to-hash, whose keys are the fields in the printers table.
-
-=cut
-
-sub GetPrinters {
-    my %printers;
-    my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("select * from printers");
-    $sth->execute;
-    while ( my $printer = $sth->fetchrow_hashref ) {
-        $printers{ $printer->{'printqueue'} } = $printer;
-    }
-    return ( \%printers );
-}
-
-=head2 GetPrinter
-
-  $printer = GetPrinter( $query, $printers );
-
-=cut
-
-sub GetPrinter {
-    my ( $query, $printers ) = @_;    # get printer for this query from printers
-    my $printer = $query->param('printer');
-    my %cookie = $query->cookie('userenv');
-    ($printer) || ( $printer = $cookie{'printer'} ) || ( $printer = '' );
-    ( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] );
-    return $printer;
-}
-
 =head2 getnbpages
 
 Returns the number of pages to display in a pagination bar, given the number
@@ -374,12 +327,6 @@ sub getFacets {
                 sep   => ' - ',
             },
             {
-                idx   => 'su-ut',
-                label => 'Titles',
-                tags  => [ qw/ 500a 501a 503a / ],
-                sep   => ', ',
-            },
-            {
                 idx   => 'au',
                 label => 'Authors',
                 tags  => [ qw/ 700ab 701ab 702ab / ],
@@ -722,7 +669,7 @@ sub GetNormalizedOCLCNumber {
         my @fields = $marcrecord->field('035');
         foreach my $field (@fields) {
             my $oclc = $field->subfield('a');
-            if ($oclc =~ /OCoLC/) {
+            if ($oclc && $oclc =~ /OCoLC/) {
                 $oclc =~ s/\(OCoLC\)//;
                 return $oclc;
             }
@@ -733,77 +680,6 @@ sub GetNormalizedOCLCNumber {
     return
 }
 
-=head2 GetDailyQuote($opts)
-
-Takes a hashref of options
-
-Currently supported options are:
-
-'id'        An exact quote id
-'random'    Select a random quote
-noop        When no option is passed in, this sub will return the quote timestamped for the current day
-
-The function returns an anonymous hash following this format:
-
-        {
-          'source' => 'source-of-quote',
-          'timestamp' => 'timestamp-value',
-          'text' => 'text-of-quote',
-          'id' => 'quote-id'
-        };
-
-=cut
-
-# This is definitely a candidate for some sort of caching once we finally settle caching/persistence issues...
-# at least for default option
-
-sub GetDailyQuote {
-    my %opts = @_;
-    my $dbh = C4::Context->dbh;
-    my $query = '';
-    my $sth = undef;
-    my $quote = undef;
-    if ($opts{'id'}) {
-        $query = 'SELECT * FROM quotes WHERE id = ?';
-        $sth = $dbh->prepare($query);
-        $sth->execute($opts{'id'});
-        $quote = $sth->fetchrow_hashref();
-    }
-    elsif ($opts{'random'}) {
-        # Fall through... we also return a random quote as a catch-all if all else fails
-    }
-    else {
-        $query = 'SELECT * FROM quotes WHERE timestamp LIKE CONCAT(CURRENT_DATE,\'%\') ORDER BY timestamp DESC LIMIT 0,1';
-        $sth = $dbh->prepare($query);
-        $sth->execute();
-        $quote = $sth->fetchrow_hashref();
-    }
-    unless ($quote) {        # if there are not matches, choose a random quote
-        # get a list of all available quote ids
-        $sth = C4::Context->dbh->prepare('SELECT count(*) FROM quotes;');
-        $sth->execute;
-        my $range = ($sth->fetchrow_array)[0];
-        # chose a random id within that range if there is more than one quote
-        my $offset = int(rand($range));
-        # grab it
-        $query = 'SELECT * FROM quotes ORDER BY id LIMIT 1 OFFSET ?';
-        $sth = C4::Context->dbh->prepare($query);
-        # see http://www.perlmonks.org/?node_id=837422 for why
-        # we're being verbose and using bind_param
-        $sth->bind_param(1, $offset, SQL_INTEGER);
-        $sth->execute();
-        $quote = $sth->fetchrow_hashref();
-        # update the timestamp for that quote
-        $query = 'UPDATE quotes SET timestamp = ? WHERE id = ?';
-        $sth = C4::Context->dbh->prepare($query);
-        $sth->execute(
-            DateTime::Format::MySQL->format_datetime( dt_from_string() ),
-            $quote->{'id'}
-        );
-    }
-    return $quote;
-}
-
 sub _normalize_match_point {
     my $match_point = shift;
     (my $normalized_match_point) = $match_point =~ /([\d-]*[X]*)/;
@@ -847,7 +723,7 @@ sub NormalizeISBN {
 
     my $string        = $params->{isbn};
     my $strip_hyphens = $params->{strip_hyphens};
-    my $format        = $params->{format};
+    my $format        = $params->{format} || q{};
     my $return_invalid = $params->{return_invalid};
 
     return unless $string;