Bugzilla – Attachment 68818 Details for
Bug 11213
GetItemsInfo() called twice
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
bug_11213: Changed XSLTParse4Display() interface
bug11213-Changed-XSLTParse4Display-interface.patch (text/plain), 14.10 KB, created by
Srdjan Jankovic
on 2017-10-30 03:17:52 UTC
(
hide
)
Description:
bug_11213: Changed XSLTParse4Display() interface
Filename:
MIME Type:
Creator:
Srdjan Jankovic
Created:
2017-10-30 03:17:52 UTC
Size:
14.10 KB
patch
obsolete
>From 732659f4edc97804dd07f14ecd362ec03c4213a7 Mon Sep 17 00:00:00 2001 >From: Srdjan <srdjan@catalyst.net.nz> >Date: Fri, 8 Nov 2013 15:45:13 +1300 >Subject: [PATCH] bug_11213: Changed XSLTParse4Display() interface > >The list of biblio items is passed on now, instead of GetItemsInfo() being >called. This is because the callers already have the list ready, so the >GetItemsInfo() call is being duplicated unnecessarily. >Search::searchResults() builds items list from XML, and that one is >passed instead. > >* XSLT::XSLTParse4Display() >- supply the items list as input param >- removed hidden items list param - hidden should not be in the items > list >- changed buildKohaItemsNamespace() accordingly > >* Items >- added sort_by input param to GetItemsInfo() > >* catalogue/detail.pl, opac/opac-detail.pl, shelfpage() >- added items list to the XSLTParse4Display() call > >* Search::searchResults() >- include all available info when building items lists >- added combined items list (available, on loan, other) to the > XSLTParse4Display() call > >To test: >This change is a noop, so following screens need to be checked against >any changes: >* Intranet: >- catalogue/search.pl (results) >- catalogue/detail.pl >- virtualshelves/shelves.pl >* Opac >- opac-search.pl (results, hidelostitems syspref on and off) >- opac-detail.pl >- opac-shelves.pl > >The display should stay the same before and after patch. The speed >should increase though. >--- > C4/Items.pm | 27 ++++++++++++++++++++++++--- > C4/Search.pm | 19 +++++-------------- > C4/XSLT.pm | 22 ++++++++++++---------- > catalogue/detail.pl | 30 +++++++++++++++--------------- > opac/opac-detail.pl | 28 ++++++++++++++-------------- > 5 files changed, 70 insertions(+), 56 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index b64aa60..7f061b0 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -977,10 +977,14 @@ sub GetItemsByBiblioitemnumber { > > =head2 GetItemsInfo > >- @results = GetItemsInfo($biblionumber); >+ @results = GetItemsInfo($biblionumber, $order_by); > > Returns information about items with the given biblionumber. > >+The list is ordered by home branch name and some complex criteria >+within it (see the code), unless $order_by is specified. >+Currently only "cn_sort" is supported. >+ > C<GetItemsInfo> returns a list of references-to-hash. Each element > contains a number of keys. Most of them are attributes from the > C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the >@@ -1018,7 +1022,8 @@ If this is set, it is set to C<One Order>. > =cut > > sub GetItemsInfo { >- my ( $biblionumber ) = @_; >+ my ( $biblionumber, $order_by ) = @_; >+ > my $dbh = C4::Context->dbh; > require C4::Languages; > my $language = C4::Languages::getlanguage(); >@@ -1073,7 +1078,18 @@ sub GetItemsInfo { > AND localization.lang = ? > |; > >- $query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ; >+ $query .= " WHERE items.biblionumber = ? ORDER BY "; >+ my $order_by_cause = "home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ; >+ if ($order_by) { >+ if ($order_by eq 'cn_sort') { >+ $order_by_cause = "cn_sort ASC"; >+ } >+ else { >+ warn qq{Unsupported order by "$order_by"}; >+ } >+ } >+ $query .= $order_by_cause; >+ > my $sth = $dbh->prepare($query); > $sth->execute($language, $biblionumber); > my $i = 0; >@@ -1104,6 +1120,11 @@ sub GetItemsInfo { > $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} }); > $data->{stack} = $descriptions->{lib} // ''; > >+ my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $data->{location} }); >+ $av = $av->count ? $av->next : undef; >+ $data->{location_intranet} = $av ? $av->lib : ''; >+ $data->{location_opac} = $av ? $av->opac_description : ''; >+ > # Find the last 3 people who borrowed this item. > my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers > WHERE itemnumber = ? >diff --git a/C4/Search.pm b/C4/Search.pm >index 9278f26..eeeb950 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -2052,7 +2052,6 @@ sub searchResults { > my $items_count = scalar(@fields); > my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults'); > my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1; >- my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref > > # loop through every item > foreach my $field (@fields) { >@@ -2074,7 +2073,6 @@ sub searchResults { > # hidden based on OpacHiddenItems syspref > my @hi = C4::Items::GetHiddenItemnumbers($item); > if (scalar @hi) { >- push @hiddenitems, @hi; > $hideatopac_count++; > next; > } >@@ -2091,7 +2089,7 @@ sub searchResults { > $item->{'branchname'} = $branches{$item->{$otherbranch}}; > } > >- my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber}; >+ my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber}; > # For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item > my $userenv = C4::Context->userenv; > if ( $item->{onloan} >@@ -2101,12 +2099,10 @@ sub searchResults { > { > $onloan_count++; > my $key = $prefix . $item->{onloan} . $item->{barcode}; >+ $onloan_items->{$key} = { %$item }; > $onloan_items->{$key}->{due_date} = $item->{onloan}; > $onloan_items->{$key}->{count}++ if $item->{$hbranch}; >- $onloan_items->{$key}->{branchname} = $item->{branchname}; > $onloan_items->{$key}->{location} = $shelflocations->{ $item->{location} }; >- $onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber}; >- $onloan_items->{$key}->{description} = $item->{description}; > $onloan_items->{$key}->{imageurl} = > getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} ); > >@@ -2192,25 +2188,20 @@ sub searchResults { > $other_count++; > > my $key = $prefix . $item->{status}; >- foreach (qw(withdrawn itemlost damaged branchname itemcallnumber)) { >- $other_items->{$key}->{$_} = $item->{$_}; >- } >+ $other_items->{$key} = { %$item }; > $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0; > $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0; > $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value and $item->{notforloan}; > $other_items->{$key}->{count}++ if $item->{$hbranch}; > $other_items->{$key}->{location} = $shelflocations->{ $item->{location} }; >- $other_items->{$key}->{description} = $item->{description}; > $other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} ); > } > # item is available > else { > $can_place_holds = 1; > $available_count++; >+ $available_items->{$prefix} = { %$item }; > $available_items->{$prefix}->{count}++ if $item->{$hbranch}; >- foreach (qw(branchname itemcallnumber description)) { >- $available_items->{$prefix}->{$_} = $item->{$_}; >- } > $available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} }; > $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} ); > } >@@ -2239,7 +2230,7 @@ sub searchResults { > # XSLT processing of some stuff > # we fetched the sysprefs already before the loop through all retrieved record! > if (!$scan && $xslfile) { >- $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang); >+ $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, [@available_items_loop, @onloan_items_loop, @other_items_loop], 1, $sysxml, $xslfile, $lang); > # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs > } > >diff --git a/C4/XSLT.pm b/C4/XSLT.pm >index bf2647a..1b0098f 100644 >--- a/C4/XSLT.pm >+++ b/C4/XSLT.pm >@@ -187,8 +187,16 @@ sub get_xslt_sysprefs { > return $sysxml; > } > >+=head2 XSLTParse4Display( $biblionumber, $orig_record, $xslsyspref, $items, $fixamps, $sysxml, $xslfilename, $lang ) >+ >+ $items => an array of items rerords, as returned from eg. GetItemsInfo >+ >+Returns XSLT block >+ >+=cut >+ > sub XSLTParse4Display { >- my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang ) = @_; >+ my ( $biblionumber, $orig_record, $xslsyspref, $items, $fixamps, $sysxml, $xslfilename, $lang ) = @_; > > $sysxml ||= C4::Context->preference($xslsyspref); > $xslfilename ||= C4::Context->preference($xslsyspref); >@@ -240,7 +248,7 @@ sub XSLTParse4Display { > > # grab the XML, run it through our stylesheet, push it out to the browser > my $record = transformMARCXML4XSLT($biblionumber, $orig_record); >- my $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items); >+ my $itemsxml = $items ? buildKohaItemsNamespace($biblionumber, $items) : ""; > my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); > > $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/; >@@ -266,13 +274,7 @@ Is only used in this module currently. > =cut > > sub buildKohaItemsNamespace { >- my ($biblionumber, $hidden_items) = @_; >- >- my @items = C4::Items::GetItemsInfo($biblionumber); >- if ($hidden_items && @$hidden_items) { >- my %hi = map {$_ => 1} @$hidden_items; >- @items = grep { !$hi{$_->{itemnumber}} } @items; >- } >+ my ($biblionumber, $items) = @_; > > my $shelflocations = > { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.location' } ) }; >@@ -285,7 +287,7 @@ sub buildKohaItemsNamespace { > my $location = ""; > my $ccode = ""; > my $xml = ''; >- for my $item (@items) { >+ for my $item (@$items) { > my $status; > > my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber}); >diff --git a/catalogue/detail.pl b/catalogue/detail.pl >index 1359c0b..4e0f2f7 100755 >--- a/catalogue/detail.pl >+++ b/catalogue/detail.pl >@@ -88,21 +88,6 @@ my $fw = GetFrameworkCode($biblionumber); > my $showallitems = $query->param('showallitems'); > my $marcflavour = C4::Context->preference("marcflavour"); > >-# XSLT processing of some stuff >-my $xslfile = C4::Context->preference('XSLTDetailsDisplay'); >-my $lang = $xslfile ? C4::Languages::getlanguage() : undef; >-my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; >- >-if ( $xslfile ) { >- $template->param( >- XSLTDetailsDisplay => '1', >- XSLTBloc => XSLTParse4Display( >- $biblionumber, $record, "XSLTDetailsDisplay", >- 1, undef, $sysxml, $xslfile, $lang >- ) >- ); >-} >- > $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") ); > $template->param( ocoins => GetCOinSBiblio($record) ); > >@@ -150,6 +135,21 @@ if (@hostitems){ > push (@items,@hostitems); > } > >+# XSLT processing of some stuff >+my $xslfile = C4::Context->preference('XSLTDetailsDisplay'); >+my $lang = $xslfile ? C4::Languages::getlanguage() : undef; >+my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; >+ >+if ( $xslfile ) { >+ $template->param( >+ XSLTDetailsDisplay => '1', >+ XSLTBloc => XSLTParse4Display( >+ $biblionumber, $record, "XSLTDetailsDisplay", \@all_items, >+ 1, $sysxml, $xslfile, $lang >+ ) >+ ); >+} >+ > my $dat = &GetBiblioData($biblionumber); > > #coping with subscriptions >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index e68d813..112a412 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -155,20 +155,6 @@ SetUTF8Flag($record); > my $marcflavour = C4::Context->preference("marcflavour"); > my $ean = GetNormalizedEAN( $record, $marcflavour ); > >-# XSLT processing of some stuff >-my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay'); >-my $lang = $xslfile ? C4::Languages::getlanguage() : undef; >-my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; >- >-if ( $xslfile ) { >- $template->param( >- XSLTBloc => XSLTParse4Display( >- $biblionumber, $record, "OPACXSLTDetailsDisplay", >- 1, undef, $sysxml, $xslfile, $lang >- ) >- ); >-} >- > my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults"); > $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults; > >@@ -502,6 +488,20 @@ if ($hideitems) { > @items = @all_items; > } > >+# XSLT processing of some stuff >+my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay'); >+my $lang = $xslfile ? C4::Languages::getlanguage() : undef; >+my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; >+ >+if ( $xslfile ) { >+ $template->param( >+ XSLTBloc => XSLTParse4Display( >+ $biblionumber, $record, "OPACXSLTDetailsDisplay", \@items, >+ 1, $sysxml, $xslfile, $lang >+ ) >+ ); >+} >+ > my $branch = ''; > if (C4::Context->userenv){ > $branch = C4::Context->userenv->{branch}; >-- >2.7.4
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 11213
:
22800
|
26394
|
26430
|
26431
|
26499
|
26500
|
26695
|
26696
|
26713
|
26718
|
26719
|
26720
|
26721
|
29557
|
29558
|
29559
|
29560
|
29561
|
29562
|
29563
|
29564
|
38584
|
38585
|
38586
|
38587
|
38588
|
38589
|
38590
|
39023
|
39024
|
39025
|
39026
|
39027
|
39028
|
39029
|
42234
|
42235
|
42236
|
42237
|
42238
|
42239
|
42240
|
42425
|
49750
|
49751
|
49752
|
49753
|
49754
|
49755
|
50163
|
50164
|
50165
|
50166
|
50167
|
50168
|
54447
|
54448
|
54449
|
54450
|
54451
|
54452
|
57578
|
57579
|
57580
|
57581
|
57582
|
57583
|
62434
|
62435
|
62436
|
62437
|
62438
|
62439
|
68646
| 68818 |
68819
|
68820
|
68821
|
68822
|
68823