From 549d033cb119687c8eb75e6d2a2bfa178dbd9be6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 29 Jul 2020 18:18:15 +0200 Subject: [PATCH] Bug 26145: Display the cover image at the OPAC Sponsored-by: Gerhard Sondermann Dialog e.K. (presseplus.de, presseshop.at, presseshop.ch) Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- C4/Images.pm | 2 +- .../bootstrap/en/modules/opac-detail.tt | 13 +++++++ .../opac-tmpl/bootstrap/js/localcovers.js | 37 ++++++++++++++++++- opac/opac-detail.pl | 14 +++++++ opac/opac-imageviewer.pl | 19 +++++++--- 5 files changed, 78 insertions(+), 7 deletions(-) diff --git a/C4/Images.pm b/C4/Images.pm index 811c144991..a5c6258fdf 100644 --- a/C4/Images.pm +++ b/C4/Images.pm @@ -113,7 +113,7 @@ sub RetrieveImage { my $dbh = C4::Context->dbh; my $query = -'SELECT imagenumber, mimetype, imagefile, thumbnail FROM biblioimages WHERE imagenumber = ?'; +'SELECT biblionumber, itemnumber, imagenumber, mimetype, imagefile, thumbnail FROM biblioimages WHERE imagenumber = ?'; my $sth = $dbh->prepare($query); $sth->execute($imagenumber); my $imagedata = $sth->fetchrow_hashref; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index d566d4c04b..03d07e2986 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -1212,6 +1212,9 @@ + [% IF ( tab == 'holdings' && itemloop_has_images || tab == 'otherholdings' && otheritemloop_has_images ) %] + + [% END %] [% IF ( item_level_itypes ) %] [% END %] @@ -1263,6 +1266,13 @@ [% ELSE %] [% END %] + + [% IF ( tab == 'holdings' && itemloop_has_images || tab == 'otherholdings' && otheritemloop_has_images ) %] + + [% END %] + [% IF ( item_level_itypes ) %]
Cover imageItem type
+
+
[% UNLESS ( Koha.Preference('OpacNoItemTypeImages') ) %] @@ -1619,6 +1629,9 @@ [% END %] [% IF OPACLocalCoverImages %] KOHA.LocalCover.GetCoverFromBibnumber(true); + [% IF itemloop_has_images OR oheritemloop_has_images %] + KOHA.LocalCover.GetCoverFromItemnumber(true); + [% END %] [% END %] [% IF ( NovelistSelectProfile && ( normalized_isbn || normalized_upc ) ) %] novSelect.loadContentForQuery( diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/localcovers.js b/koha-tmpl/opac-tmpl/bootstrap/js/localcovers.js index daae010239..94c29e78a2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/localcovers.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/localcovers.js @@ -49,5 +49,40 @@ KOHA.LocalCover = { } }) }); - } + }, + GetCoverFromItemnumber: function(uselink) { + $("div[class^=local-thumbnail],span[class^=local-thumbnail]").each(function(i) { + var mydiv = this; + var message = document.createElement("span"); + var imagenumber = $(mydiv).data("imagenumber"); + var biblionumber = $(mydiv).data("biblionumber"); + $(message).attr("class","no-image"); + $(message).html(NO_LOCAL_JACKET); + $(mydiv).parent().find('.no-image').remove(); + $(mydiv).append(message); + var img = $("").attr('src', + '/cgi-bin/koha/opac-image.pl?thumbnail=1&imagenumber=' + imagenumber) + .load(function () { + this.setAttribute("class", "thumbnail"); + if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) { + //IE HACK + try { + $(mydiv).append(img); + $(mydiv).children('.no-image').remove(); + } + catch(err){ + }; + } else if (this.width > 1) { // don't show the silly 1px "no image" img + if (uselink) { + var a = $("").attr('href', '/cgi-bin/koha/opac-imageviewer.pl?imagenumber=' + imagenumber + '&biblionumber=' + biblionumber); + $(a).append(img); + $(mydiv).empty().append(a); + } else { + $(mydiv).empty().append(img); + } + $(mydiv).children('.no-image').remove(); + } + }) + }); + }, }; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 8d4723e338..326c7f5d12 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -709,6 +709,7 @@ if ( C4::Context->preference('OPACAcquisitionDetails' ) ) { } my $allow_onshelf_holds; +my ( $itemloop_has_images, $otheritemloop_has_images ); if ( not $viewallitems and @items > $max_items_to_display ) { $template->param( too_many_items => 1, @@ -762,15 +763,23 @@ if ( not $viewallitems and @items > $max_items_to_display ) { if grep { $_ eq $itm->{itemnumber} } @itemnumbers_on_order; } + if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) { + $itm->{imagenumber} = + C4::Images::GetImageForItem( $itm->{itemnumber} ); + } + my $itembranch = $itm->{$separatebranch}; if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) { if ($itembranch and $itembranch eq $currentbranch) { push @itemloop, $itm; + $itemloop_has_images++ if $itm->{imagenumber}; } else { push @otheritemloop, $itm; + $otheritemloop_has_images++ if $itm->{imagenumber}; } } else { push @itemloop, $itm; + $itemloop_has_images++ if $itm->{imagenumber}; } } } @@ -779,6 +788,11 @@ if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_item $template->param( ReservableItems => 1 ); } +$template->param( + itemloop_has_images => $itemloop_has_images, + otheritemloop_has_images => $otheritemloop_has_images, +); + # Display only one tab if one items list is empty if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { $template->param(SeparateHoldings => 0); diff --git a/opac/opac-imageviewer.pl b/opac/opac-imageviewer.pl index 09be474226..2e4dc39181 100755 --- a/opac/opac-imageviewer.pl +++ b/opac/opac-imageviewer.pl @@ -26,6 +26,7 @@ use C4::Output; use C4::Images; use Koha::Biblios; +use Koha::Items; my $query = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( @@ -39,14 +40,22 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $biblionumber = $query->param('biblionumber') || $query->param('bib'); my $imagenumber = $query->param('imagenumber'); +unless ( $biblionumber ) { + # Retrieving the biblio from the imagenumber + my $image = C4::Images::RetrieveImage($imagenumber); + my $item = Koha::Items->find($image->{itemnumber}); + $biblionumber = $item->biblionumber; +} my $biblio = Koha::Biblios->find( $biblionumber ); if ( C4::Context->preference("OPACLocalCoverImages") ) { - my @images = ListImagesForBiblio($biblionumber); - $template->{VARS}->{'OPACLocalCoverImages'} = 1; - $template->{VARS}->{'images'} = \@images; - $template->{VARS}->{'biblionumber'} = $biblionumber; - $template->{VARS}->{'imagenumber'} = $imagenumber || $images[0] || ''; + my @images = !$imagenumber ? ListImagesForBiblio($biblionumber) : (); + $template->param( + OPACLocalCoverImages => 1, + images => \@images, + biblionumber => $biblionumber, + imagenumber => $imagenumber || $images[0] || '', + ); } $template->{VARS}->{'biblio'} = $biblio; -- 2.39.5