From bc7f37839b013e8612b77f35a35b8aee9371eab0 Mon Sep 17 00:00:00 2001 From: danyonsewell Date: Tue, 20 Aug 2024 05:11:45 +0000 Subject: [PATCH] Bug 37463: Show Amazon cover images in checkouts table for selected patron categories This patch allows cover images to display in the patron checkout module for selected patron categories but only ones from Amazon for now. Test plan: Step 1 - apply this patch Step 2 - Make sure AmazonCoverImages syspref is set to "show" step 3 - Search for the CoverImagesCategories syspref and enable it for a specific patron category (choose the category that your patron account is) step 4 - checkout an item to your patron account step 5 - in the patron checkouts page, click the "show checkouts" button, you should see the items cover image there, as long as there is one available from Amazon Sponsored by: Pymble Ladies College Signed-off-by: David Nind --- ...37463-add_CoverImagesCategories_syspref.pl | 16 ++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/circulation.pref | 5 +++++ koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 21 +++++++++++++++++++ svc/checkouts | 16 ++++++++++++-- 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_37463-add_CoverImagesCategories_syspref.pl diff --git a/installer/data/mysql/atomicupdate/bug_37463-add_CoverImagesCategories_syspref.pl b/installer/data/mysql/atomicupdate/bug_37463-add_CoverImagesCategories_syspref.pl new file mode 100755 index 0000000000..0ab6e4d78b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_37463-add_CoverImagesCategories_syspref.pl @@ -0,0 +1,16 @@ +use Modern::Perl; + +return { + bug_number => "37463", + description => "Add new system preference CoverImagesCategories", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('CoverImagesCategories', '', NULL, 'Cover images will show in the patron checkouts table for selected patron categories. Please note: this only currently works for Amazon cover images.:', 'Free')} + ); + + say $out "Added system preference 'CoverImagesCategories'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 35a5d15dd8..f2b1beef10 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -183,6 +183,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ContentWarningField', '', NULL, 'MARC field to use for content warnings', 'Free'), ('CookieConsent', '0', NULL, 'Require cookie consent to be displayed', 'YesNo'), ('CookieConsentedJS', '', NULL, 'Add Javascript code that will run if cookie consent is provided (e.g. tracking code).', 'Free'), +('CoverImagesCategories', '', NULL, 'Cover images will show in the patron checkouts table for selected patron categories. Please note: this only currently works for Amazon cover images', 'Free'), ('CreateAVFromCataloguing', '1', '', 'Ability to create authorized values from the cataloguing module', 'YesNo'), ('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo'), ('CSVDelimiter',',',';|tabulation|,|/|\\|#||','Define the default separator character for exporting reports','Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 82070552d6..1fc457bdbc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -1330,6 +1330,11 @@ Circulation: - pref: SelfCheckAllowByIPRanges class: short - (Leave blank if not used. Use ranges or simple IP addresses separated by spaces, like 192.168.1.1 192.168.0.0/24.) + - + - "Cover images will show in the patron checkouts table for selected patron categories. Please note: this only currently works for Amazon cover images" + - pref: CoverImagesCategories + choices: patron-categories + class: multiple - - "Patron categories allowed to check out in a batch while logged into the self-checkout system:" - pref: SCOBatchCheckoutsValidCategories diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index 222b39a781..7dbe8c382e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -261,6 +261,27 @@ function LoadIssuesTable() { "" + onsite_checkout; + if (oObj.showcoverimage == 1 ) { + var amazonurl = 'https://images-na.ssl-images-amazon.com/images/P/' + oObj.isbn + '.01.MZZZZZZZ.jpg'; + var img = new Image(); + img.src = amazonurl; + var w = img.width; + var h = img.height; + if (w == 1 && h == 1) { + /* Amazon returned single-pixel placeholder */ + } + else { + title += + '
' + + 'Amazon cover image
Image from Amazon.com
'; + } + } return title; }, type: "anti-the", diff --git a/svc/checkouts b/svc/checkouts index 9b45a03fbf..9b8ab1da66 100755 --- a/svc/checkouts +++ b/svc/checkouts @@ -241,6 +241,16 @@ while ( my $c = $sth->fetchrow_hashref() ) { } } + my @coverimagescategories = split( ",", C4::Context->preference("CoverImagesCategories") ); + my $showcoverimage = 0; + my $patroncategory = Koha::Patrons->find( $c->{borrowernumber} )->categorycode; + if ( grep( /^$patroncategory$/, @coverimagescategories ) ) { + $showcoverimage = 1; + } + + my $biblio = Koha::Biblios->find( $c->{biblionumber} ); + my $isbn = $biblio->normalized_isbn; + my $checkout = { DT_RowId => $c->{itemnumber} . '-' . $c->{borrowernumber}, title => $c->{title}, @@ -306,8 +316,10 @@ while ( my $c = $sth->fetchrow_hashref() ) { firstname => $c->{firstname}, cardnumber => $c->{cardnumber}, }, - issued_today => !$c->{not_issued_today}, - recalled => $recalled, + issued_today => !$c->{not_issued_today}, + recalled => $recalled, + isbn => $isbn, + showcoverimage => $showcoverimage, }; if ( $c->{not_issued_today} ) { -- 2.39.5