Bugzilla – Attachment 110863 Details for
Bug 26145
Add the ability to attach a cover image at item level
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26145: Display the cover image at the OPAC
Bug-26145-Display-the-cover-image-at-the-OPAC.patch (text/plain), 8.62 KB, created by
Jonathan Druart
on 2020-09-28 15:02:28 UTC
(
hide
)
Description:
Bug 26145: Display the cover image at the OPAC
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-09-28 15:02:28 UTC
Size:
8.62 KB
patch
obsolete
>From 3956a8146b595b600dcc5ed622eb7732ee788ca7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >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) >--- > 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 2854660887..5ab4d9faa0 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 @@ > <table class="table table-bordered table-striped" id="[% table_id | html %]"> > <thead> > <tr> >+ [% IF ( tab == 'holdings' && itemloop_has_images || tab == 'otherholdings' && otheritemloop_has_images ) %] >+ <th id="item_cover" data-colname="item_cover">Cover image</th> >+ [% END %] > [% IF ( item_level_itypes ) %] > <th id="item_itemtype" data-colname="item_itemtype" class="itype">Item type</th> > [% END %] >@@ -1263,6 +1266,13 @@ > [% ELSE %] > <tr vocab="http://schema.org/" typeof="Offer"> > [% END %] >+ >+ [% IF ( tab == 'holdings' && itemloop_has_images || tab == 'otherholdings' && otheritemloop_has_images ) %] >+ <td class="cover"> >+ <div title="[% ITEM_RESULT.itemnumber | html %]" data-imagenumber="[% ITEM_RESULT.imagenumber | html %]" data-biblionumber="[% ITEM_RESULT.biblionumber %]" class="local-thumbnail-preview"></div> >+ </td> >+ [% END %] >+ > [% IF ( item_level_itypes ) %] > <td class="itype"> > [% 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 = $("<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 = $("<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.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26145
:
109225
|
109226
|
110342
|
110343
|
110344
|
110345
|
110346
|
110347
|
110348
|
110349
|
110350
|
110351
|
110352
|
110353
|
110354
|
110675
|
110676
|
110677
|
110678
|
110679
|
110680
|
110681
|
110682
|
110683
|
110684
|
110685
|
110800
|
110861
|
110862
|
110863
|
110864
|
110865
|
110866
|
110867
|
110868
|
110869
|
110870
|
110871
|
110872
|
110873
|
110874
|
110875
|
111446
|
111447
|
111448
|
111449
|
111450
|
111451
|
111452
|
111453
|
111454
|
111455
|
111456
|
111457
|
111458