From 556538e101686a74c3053f7818b373ba02a92430 Mon Sep 17 00:00:00 2001
From: Galen Charlton
Date: Fri, 20 Jun 2008 17:37:05 -0500
Subject: [PATCH] bug 2248 [2/2]: import item status display in search results
The in transit status now displays as such in the
OPAC search results. In the non-XSLT version, the status
is checked only for bibs having 20 or fewer items to avoid
extra hits on the database during result set presentation.
In the XSLT version, all items are checked.
Note that because an item's transfer status is not
stored in the MARC record, the transfer status
has no effect when limiting a search by item
availability. For a future version, the transit status
should be added to the Zebra index.
Signed-off-by: Joshua Ferraro
---
C4/Search.pm | 60 ++++++++++++++-----
C4/XSLT.pm | 11 +++-
.../prog/en/modules/catalogue/results.tmpl | 1 +
.../prog/en/modules/opac-results-grouped.tmpl | 1 +
.../prog/en/modules/opac-results.tmpl | 1 +
.../prog/en/xslt/MARC21slim2OPACResults.xsl | 6 ++
6 files changed, 64 insertions(+), 16 deletions(-)
diff --git a/C4/Search.pm b/C4/Search.pm
index 7442847299..d138594ff4 100755
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -1354,17 +1354,18 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
my $onloan_items;
my $other_items;
- my $ordered_count = 0;
- my $available_count = 0;
- my $onloan_count = 0;
- my $longoverdue_count = 0;
- my $other_count = 0;
- my $wthdrawn_count = 0;
- my $itemlost_count = 0;
- my $itembinding_count = 0;
- my $itemdamaged_count = 0;
- my $can_place_holds = 0;
- my $items_count = scalar(@fields);
+ my $ordered_count = 0;
+ my $available_count = 0;
+ my $onloan_count = 0;
+ my $longoverdue_count = 0;
+ my $other_count = 0;
+ my $wthdrawn_count = 0;
+ my $itemlost_count = 0;
+ my $itembinding_count = 0;
+ my $itemdamaged_count = 0;
+ my $item_in_transit_count = 0;
+ my $can_place_holds = 0;
+ my $items_count = scalar(@fields);
my $items_counter;
my $maxitems =
( C4::Context->preference('maxItemsinSearchResults') )
@@ -1418,15 +1419,42 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
$ordered_count++;
}
+ # is item in transit?
+ my $transfertwhen = '';
+ my ($transfertfrom, $transfertto);
+
+ unless ($item->{wthdrawn}
+ || $item->{itemlost}
+ || $item->{damaged}
+ || $item->{notforloan}
+ || $items_count > 20) {
+
+ # A couple heuristics to limit how many times
+ # we query the database for item transfer information, sacrificing
+ # accuracy in some cases for speed;
+ #
+ # 1. don't query if item has one of the other statuses
+ # 2. don't check transit status if the bib has
+ # more than 20 items
+ #
+ # FIXME: to avoid having the query the database like this, and to make
+ # the in transit status count as unavailable for search limiting,
+ # should map transit status to record indexed in Zebra.
+ #
+ ($transfertwhen, $transfertfrom, $transfertto) = C4::Circulation::GetTransfers($item->{itemnumber});
+ }
+
# item is withdrawn, lost or damaged
if ( $item->{wthdrawn}
|| $item->{itemlost}
|| $item->{damaged}
- || $item->{notforloan} )
+ || $item->{notforloan}
+ || ($transfertwhen ne ''))
{
- $wthdrawn_count++ if $item->{wthdrawn};
- $itemlost_count++ if $item->{itemlost};
- $itemdamaged_count++ if $item->{damaged};
+ $wthdrawn_count++ if $item->{wthdrawn};
+ $itemlost_count++ if $item->{itemlost};
+ $itemdamaged_count++ if $item->{damaged};
+ $item_in_transit_count++ if $transfertwhen ne '';
$item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
$other_count++;
@@ -1434,6 +1462,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber)) {
$other_items->{$key}->{$_} = $item->{$_};
}
+ $other_items->{$key}->{intransit} = ($transfertwhen ne '') ? 1 : 0;
$other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value;
$other_items->{$key}->{count}++ if $item->{homebranch};
$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
@@ -1494,6 +1523,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
$oldbiblio->{wthdrawncount} = $wthdrawn_count;
$oldbiblio->{itemlostcount} = $itemlost_count;
$oldbiblio->{damagedcount} = $itemdamaged_count;
+ $oldbiblio->{intransitcount} = $item_in_transit_count;
$oldbiblio->{orderedcount} = $ordered_count;
$oldbiblio->{isbn} =~
s/-//g; # deleting - in isbn to enable amazon content
diff --git a/C4/XSLT.pm b/C4/XSLT.pm
index aea933c6fc..3c781d265f 100644
--- a/C4/XSLT.pm
+++ b/C4/XSLT.pm
@@ -22,6 +22,7 @@ use C4::Branch;
use C4::Items;
use C4::Koha;
use C4::Biblio;
+use C4::Circulation;
use XML::LibXML;
use XML::LibXSLT;
@@ -132,9 +133,14 @@ sub buildKohaItemsNamespace {
my $xml;
for my $item (@items) {
my $status;
- if ( $item->{notforloan} == -1 || $item->{onloan} || $item->{wthdrawn} || $item->{itemlost} || $item->{damaged}) {
+ my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
+ if ( $item->{notforloan} == -1 || $item->{onloan} || $item->{wthdrawn} || $item->{itemlost} || $item->{damaged} ||
+ ($transfertwhen ne '') || $item->{itemnotforloan} ) {
if ( $item->{notforloan} == -1) {
$status = "On order";
+ }
+ if ( $item->{itemnotforloan} ) {
+ $status = "Not for loan";
}
if ($item->{onloan}) {
$status = "Checked out";
@@ -148,6 +154,9 @@ sub buildKohaItemsNamespace {
if ($item->{damaged}) {
$status = "Damaged";
}
+ if ($transfertwhen ne '') {
+ $status = 'In transit';
+ }
} else {
$status = "available";
}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
index bb25c6825f..9b6216f975 100755
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
@@ -360,6 +360,7 @@ $(window).load(function() {
(Withdrawn)
(Lost)
(Damaged)
+ (In transit)
()
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tmpl
index 62f26d8125..ff7d064d91 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tmpl
@@ -220,6 +220,7 @@ $(document).ready(function(){
Lost (),
Damaged (),
On order (),
+ In transit (),
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
index a5f54c56a9..347a02abc5 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
@@ -246,6 +246,7 @@ $(document).ready(function(){
Lost (),
Damaged (),
On order (),
+ In transit (),
diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl
index 16362d4667..4cb2421d97 100644
--- a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl
+++ b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl
@@ -881,6 +881,12 @@
)
+
+
+ In transit (
+
+ )
+
--
2.39.5