From 891835895cd9d2849c6f5e8e569af20451d26364 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 8 Jun 2023 10:00:53 +0200 Subject: [PATCH] Bug 33949: Replace GetAllIssues with Koha::Checkouts - opac Same as bug 33948 for the OPAC side. Additionally you will test * OPACMySummaryHTML * The different cover images services * Display of ISBN * Display of UPC * Ratings Signed-off-by: David Nind Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- .../en/modules/opac-readingrecord.tt | 90 +++++++++-------- opac/opac-readingrecord.pl | 98 ++++++------------- 2 files changed, 79 insertions(+), 109 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt index e36f871dc6..d877c9422d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt @@ -42,8 +42,8 @@

Checkout history

- - [% IF READING_RECORD.size == 0 %] + [% SET all_checkouts = checkouts.merge(old_checkouts) %] + [% IF all_checkouts.size == 0 %] You have never borrowed anything from this library. [% ELSE %]
@@ -91,16 +91,16 @@ [% END # /WRAPPER tabs_nav %] [% WRAPPER tab_panels %] [% WRAPPER tab_panel tabname="tabs-container" bt_active= 1 %] - [% PROCESS checkout_history_table %] + [% PROCESS checkout_history_table checkouts=all_checkouts %] [% END # /tab_panel# %] [% END # /WRAPPER tab_panels %] [% END # /WRAPPER tabs %] [% ELSE %] - [% PROCESS checkout_history_table %] + [% PROCESS checkout_history_table checkouts=all_checkouts %] [% END %]
- [% END # / IF READING_RECORD.size %] + [% END # / IF checkouts.size == 0 %]
@@ -120,91 +120,103 @@ Call number Vol info Date - [% IF ( OPACMySummaryHTML ) %] + [% IF Koha.Preference('OPACMySummaryHTML') %] Links [% END %] - [% FOREACH issue IN READING_RECORD %] + [% FOREACH checkout IN checkouts %] + [% SET item = checkout.item %] + [% SET biblio = item.biblio %] - [% IF issue.onsite_checkout %][% issuetype = 'onsite_checkout' %] + [% IF checkout.onsite_checkout %][% issuetype = 'onsite_checkout' %] [% ELSE %][% issuetype = 'standard_checkout' %] [% END %] [% issuetype | html %] - [% IF OPACAmazonCoverImages %] - [% IF issue.normalized_isbn %] - + [% SET normalized_isbn = biblio.normalized_isbn %] + [% IF OPACAmazonCoverImages %] + [% IF normalized_isbn %] + [% ELSE %] No cover image available [% END %] [% END %] [% IF GoogleJackets %] - [% IF issue.normalized_isbn %] -
+ [% IF normalized_isbn %] +
[% ELSE %] - No cover image available + No cover image available [% END %] [% END %] - [% IF BakerTaylorEnabled %] - [% bt_id = ( issue.normalized_upc || issue.normalized_isbn ) %] - [% IF ( bt_id ) %] - See Baker & Taylor - [% ELSE %] - No cover image available - [% END %] + [% IF BakerTaylorEnabled || SyndeticsEnabled && SyndeticsCoverImages %] + [% SET normalized_upc = biblio.normalized_upc %] + [% END %] + [% IF BakerTaylorEnabled %] + [% bt_id = ( normalized_upc || normalized_isbn ) %] + [% IF ( bt_id ) %] + See Baker & Taylor + [% ELSE %] + No cover image available + [% END %] [% END %] [% IF SyndeticsEnabled && SyndeticsCoverImages %] - + [% END %] - [% INCLUDE 'biblio-title.inc' biblio=issue, link => 1 %] + [% INCLUDE 'biblio-title.inc' biblio=biblio, link => 1 %] [% IF ( Koha.Preference( 'OpacStarRatings' ) == 'all' ) %] - [% INCLUDE 'user-star-ratings.inc' item=issue %] + [% SET ratings = {ratings => biblio.ratings, itemnumber => item.itemnumber, biblionumber => biblio.biblionumber, my_rating => biblio.ratings.search( borrowernumber => logged_in_user.borrowernumber ).next } %] + [% INCLUDE 'user-star-ratings.inc' item=ratings %] [% END %] - [% issue.author | html %] + [% biblio.author | html %] + [% SET item_type = item_types.${item.effective_itemtype} %] [% UNLESS ( Koha.Preference('OpacNoItemTypeImages') ) %] - [% IF ( issue.imageurl ) %] - + [% SET image_location = item_type.image_location %] + [% IF image_location %] + [% END %] [% END %] - Item type: - [% issue.translated_description | html %] + + Item type: + [% item_type.translated_description | html %] + Call number: - [% issue.itemcallnumber | html %] + [% item.itemcallnumber | html %] - [% IF issue.enumchron %] - [% issue.enumchron | html %] + [% IF item.enumchron %] + [% item.enumchron | html %] [% END %] - [% IF issue.returndate %] - + [% IF checkout.returndate %] + Check-in date: - [% issue.returndate | $KohaDates %] + [% checkout.returndate | $KohaDates %] + [% ELSE %] (Checked out) + [% END %] - - [% IF OPACMySummaryHTML %] - [% issue.MySummaryHTML | $raw %] + [% IF Koha.Preference('OPACMySummaryHTML') %] + [% biblio.opac_summary_html | $raw %] [% END %] - [% END # / FOREACH issue %] + [% END # / FOREACH checkout %] [% END %] diff --git a/opac/opac-readingrecord.pl b/opac/opac-readingrecord.pl index 7ee0a5f697..a671ca0f01 100755 --- a/opac/opac-readingrecord.pl +++ b/opac/opac-readingrecord.pl @@ -21,23 +21,14 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth qw( get_template_and_user ); -use C4::Koha qw( - getitemtypeimagelocation - GetNormalizedISBN - GetNormalizedUPC - GetNormalizedOCLCNumber -); use C4::Biblio; -use C4::Members qw( GetAllIssues ); use C4::External::BakerTaylor qw( image_url link_url ); use MARC::Record; use C4::Output qw( output_html_with_http_headers ); -use C4::Charset qw( StripNonXmlChars ); use Koha::Patrons; use Koha::ItemTypes; -use Koha::Ratings; my $query = CGI->new; @@ -55,7 +46,12 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +my $patron = Koha::Patrons->find( $borrowernumber ); +my @itemtypes = Koha::ItemTypes->search_with_localization->as_list; +my %item_types = map { + $_->itemtype => $_ +} @itemtypes; +$template->param(item_types => \%item_types); # get the record my $order = $query->param('order') || ''; @@ -75,64 +71,27 @@ my $limit = $query->param('limit'); $limit //= ''; $limit = ( $limit eq 'full' ) ? 0 : 50; -my $issues = GetAllIssues( $borrowernumber, $order, $limit ); - -my $itype_attribute = - ( C4::Context->preference('item-level_itypes') ) ? 'itype' : 'itemtype'; - -my $opac_summary_html = C4::Context->preference('OPACMySummaryHTML'); -foreach my $issue ( @{$issues} ) { - $issue->{normalized_isbn} = GetNormalizedISBN( $issue->{isbn} ); - if ( $issue->{$itype_attribute} ) { - $issue->{translated_description} = - $itemtypes->{ $issue->{$itype_attribute} }->{translated_description}; - $issue->{imageurl} = - getitemtypeimagelocation( 'opac', - $itemtypes->{ $issue->{$itype_attribute} }->{imageurl} ); - } - - if ( C4::Context->preference('BakerTaylorEnabled') - || C4::Context->preference('SyndeticsEnabled') - || C4::Context->preference('SyndeticsCoverImages') ) - { - my $marcxml = C4::Biblio::GetXmlBiblio( $issue->{biblionumber} ); - if ( $marcxml ) { - $marcxml = StripNonXmlChars( $marcxml ); - my $marc_rec = - MARC::Record::new_from_xml( $marcxml, 'UTF-8', - C4::Context->preference('marcflavour') ); - $issue->{normalized_upc} = GetNormalizedUPC( $marc_rec, C4::Context->preference('marcflavour') ); - $issue->{normalized_oclc} = GetNormalizedOCLCNumber($marc_rec, C4::Context->preference('marcflavour')); +my $checkouts = [ + $patron->checkouts( + {}, + { + order_by => $order, + prefetch => { item => { biblio => 'biblioitems' } }, + ( $limit ? ( limit => $limit ) : () ), } - - } - # My Summary HTML - if ($opac_summary_html) { - my $my_summary_html = $opac_summary_html; - $issue->{author} - ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g - : $my_summary_html =~ s/{AUTHOR}//g; - my $title = $issue->{title}; - $title =~ s/\/+$//; # remove trailing slash - $title =~ s/\s+$//; # remove trailing space - $title - ? $my_summary_html =~ s/{TITLE}/$title/g - : $my_summary_html =~ s/{TITLE}//g; - $issue->{normalized_isbn} - ? $my_summary_html =~ s/{ISBN}/$issue->{normalized_isbn}/g - : $my_summary_html =~ s/{ISBN}//g; - $issue->{biblionumber} - ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g - : $my_summary_html =~ s/{BIBLIONUMBER}//g; - $issue->{MySummaryHTML} = $my_summary_html; - } - # Star ratings - if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { - my $ratings = Koha::Ratings->search({ biblionumber => $issue->{biblionumber} }); - $issue->{ratings} = $ratings; - $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef; - } -} + )->as_list +]; +$limit -= scalar(@$checkouts) if $limit; +my $old_checkouts = [ + $patron->old_checkouts( + {}, + { + order_by => $order, + prefetch => { item => { biblio => 'biblioitems' } }, + ( $limit ? ( limit => $limit ) : () ), + } + )->as_list +]; if (C4::Context->preference('BakerTaylorEnabled')) { $template->param( @@ -152,15 +111,14 @@ for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above my $saving_display = C4::Context->preference('OPACShowSavings'); if ( $saving_display =~ /checkouthistory/ ) { - my $patron = Koha::Patrons->find( $borrowernumber ); $template->param( savings => $patron->get_savings ); } $template->param( - READING_RECORD => $issues, + checkouts => $checkouts, + old_checkouts => $old_checkouts, limit => $limit, readingrecview => 1, - OPACMySummaryHTML => $opac_summary_html ? 1 : 0, ); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.39.5