From 3edaba0cc0d85d9b2b61f91e7236750b90a0c7e7 Mon Sep 17 00:00:00 2001
From: Joshua Ferraro
Date: Thu, 20 Dec 2007 17:33:07 -0600
Subject: [PATCH] fixes to search results list, ccl.properties tweak
patch updateitem.pl (was failing ... missing 'my')
update OPAC results
fix limit by availability
Signed-off-by: Joshua Ferraro
---
C4/Search.pm | 191 +++++++++++-------
catalogue/updateitem.pl | 2 +-
etc/zebradb/ccl.properties | 3 +-
.../intranet-tmpl/prog/en/includes/facets.inc | 12 +-
.../prog/en/includes/resort_form.inc | 8 +-
.../prog/en/modules/catalogue/results.tmpl | 59 ++++--
.../prog/en/modules/opac-results.tmpl | 32 +--
opac/opac-search.pl | 7 +-
8 files changed, 203 insertions(+), 111 deletions(-)
diff --git a/C4/Search.pm b/C4/Search.pm
index d616b692be..6f98b34be5 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -881,12 +881,14 @@ sub buildQuery {
warn "QUERY BEFORE LIMITS: >$query<" if $DEBUG;
# add limits
+ $DEBUG=1;
my $group_OR_limits;
my $availability_limit;
foreach my $this_limit (@limits) {
if ( $this_limit =~ /available/ ) {
# available is defined as (items.notloan is NULL) and (items.itemlost > 0 or NULL) (last clause handles NULL values for lost in zebra)
- $availability_limit .="( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and ((lost,st-numeric ge 0) or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
+ # all records not indexed in the onloan register and allrecords not indexed in the lost register, or where the value of lost is equal to or less than 0
+ $availability_limit .="( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and ((lost,st-numeric <= 0) or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
$limit_cgi .= "&limit=available";
$limit_desc .="";
}
@@ -912,8 +914,8 @@ sub buildQuery {
$limit.="($group_OR_limits)";
}
if ($availability_limit) {
- $limit.=" not " if ($query || $limit );
- $limit.="$availability_limit";
+ $limit.=" and " if ($query || $limit );
+ $limit.="($availability_limit)";
}
# normalize the strings
$query =~ s/:/=/g;
@@ -966,6 +968,12 @@ sub searchResults {
while ( my $bdata = $bsth->fetchrow_hashref ) {
$branches{ $bdata->{'branchcode'} } = $bdata->{'branchname'};
}
+ my %locations;
+ my $lsch = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category = 'SHELF_LOC'");
+ $lsch->execute();
+ while (my $ldata = $lsch->fetchrow_hashref ) {
+ $locations{ $ldata->{'authorised_value'} } = $ldata->{'lib'};
+ }
#Build itemtype hash
#find itemtype & itemtype image
@@ -1092,94 +1100,131 @@ sub searchResults {
}
$oldbiblio->{'toggle'} = $toggle;
my @fields = $marcrecord->field($itemtag);
- my @items_loop;
- my $items;
+
+# Setting item statuses for display
+ my @available_items_loop;
+ my @onloan_items_loop;
+ my @other_items_loop;
+
+ my $available_items;
+ 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 $norequests = 1;
-
- #
- # check the loan status of the item :
- # it is not stored in the MARC record, for pref (zebra reindexing)
- # reason. Thus, we have to get the status from a specific SQL query
- #
- my $sth_issue = $dbh->prepare("
- SELECT date_due,returndate
- FROM issues
- WHERE itemnumber=? AND returndate IS NULL");
+ my $itembinding_count = 0;
+ my $itemdamaged_count = 0;
+ my $can_place_holds = 0;
my $items_count=scalar(@fields);
+ my $items_counter;
+ my $maxitems = (C4::Context->preference('maxItemsinSearchResults')) ? C4::Context->preference('maxItemsinSearchResults')- 1 : 1;
foreach my $field (@fields) {
my $item;
+ $items_counter++;
+
+ # populate the items hash
foreach my $code ( keys %subfieldstosearch ) {
$item->{$code} = $field->subfield( $subfieldstosearch{$code} );
}
- $sth_issue->execute($item->{itemnumber});
- $item->{due_date} = format_date($sth_issue->fetchrow) if $sth_issue->fetchrow;
- $item->{onloan} = 1 if $item->{due_date};
- # at least one item can be reserved : suppose no
- $norequests = 1;
- if ( $item->{wthdrawn} ) {
- $wthdrawn_count++;
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{unavailable}=1;
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{wthdrawn}=1;
- }
- elsif ( $item->{itemlost} ) {
- $itemlost_count++;
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{unavailable}=1;
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{itemlost}=1;
- }
- unless ( $item->{notforloan}) {
- # OK, this one can be issued, so at least one can be reserved
- $norequests = 0;
- }
- if ( ( $item->{onloan} ) && ( $item->{onloan} != '0000-00-00' ) )
- {
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{unavailable}=1;
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{onloancount} = 1;
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{due_date} = $item->{due_date};
- $onloan_count++;
- }
- if ( $item->{'homebranch'} ) {
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{count}++;
- }
+ # set item's branch name, use homebranch first, fall back to holdingbranch
+ if ($item->{'homebranch'}) {
+ $item->{'branchname'} = $branches{$item->{homebranch}};
+ }
# Last resort
- elsif ( $item->{'holdingbranch'} ) {
- $items->{ $item->{'holdingbranch'} }->{count}++;
+ elsif ($item->{'holdingbranch'}) {
+ $item->{'branchname'} = $branches{$item->{holdingbranch}};
}
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{itemcallnumber} = $item->{itemcallnumber};
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{location} = $item->{location};
- $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{branchcode} = $item->{homebranch};
- } # notforloan, item level and biblioitem level
-
- # last check for norequest : if itemtype is notforloan, it can't be reserved either, whatever the items
- $norequests = 1 if $itemtypes{$oldbiblio->{itemtype}}->{notforloan};
- my $itemscount;
- for my $key ( sort keys %$items ) {
- $itemscount++;
- my $this_item = {
- branchname => $branches{$items->{$key}->{branchcode}},
- branchcode => $items->{$key}->{branchcode},
- count => $items->{$key}->{count},
- itemcallnumber => $items->{$key}->{itemcallnumber},
- location => $items->{$key}->{location},
- onloancount => $items->{$key}->{onloancount},
- due_date => $items->{$key}->{due_date},
- wthdrawn => $items->{$key}->{wthdrawn},
- lost => $items->{$key}->{itemlost},
- };
- # only show the number specified by the user
- my $maxitems = (C4::Context->preference('maxItemsinSearchResults')) ? C4::Context->preference('maxItemsinSearchResults')- 1 : 1;
- push @items_loop, $this_item unless $itemscount > $maxitems;;
+ # key for items results is built from branchcode . coded location qualifier . itemcallnumber
+ if ($item->{onloan}) {
+ $onloan_count++;
+ $onloan_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{due_date} }->{due_date} = format_date($item->{onloan});
+ $onloan_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{due_date} }->{count}++ if $item->{'homebranch'};
+ $onloan_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{due_date} }->{branchname} = $item->{'branchname'};
+ $onloan_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{due_date} }->{location} = $locations{$item->{location}};
+ $onloan_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{due_date} }->{itemcallnumber} = $item->{itemcallnumber};
+
+ # if something's checked out and lost, mark it as 'long overdue'
+ if ( $item->{itemlost} ) {
+ $onloan_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{due_date} }->{longoverdue}++;
+ $longoverdue_count++;
+ }
+ # can place holds as long as this item isn't lost
+ else {
+ $can_place_holds = 1;
+ }
+ }
+
+ # items not on loan, but still unavailable ( lost, withdrawn, damaged )
+ else {
+ # item is on order
+ if ( $item->{notforloan} == -1) {
+ $ordered_count++;
+ }
+
+ # item is withdrawn, lost or damaged
+ if ( $item->{wthdrawn} || $item->{itemlost} || $item->{damaged} ) {
+ $wthdrawn_count++ if $item->{wthdrawn};
+ $itemlost_count++ if $item->{itemlost};
+ $itemdamaged_count++ if $item->{damaged};
+ $item->{status} = $item->{wthdrawn}."-".$item->{itemlost}."-".$item->{damaged};
+ $other_count++;
+ $other_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{status} }->{wthdrawn} = $item->{wthdrawn};
+ $other_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{status} }->{itemlost} = $item->{itemlost};
+ $other_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{status} }->{damaged} = $item->{damaged};
+ $other_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{status} }->{count}++ if $item->{'homebranch'};
+ $other_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{status} }->{branchname} = $item->{'branchname'};
+ $other_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{status} }->{location} = $locations{$item->{location}};
+ $other_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'}.$item->{status} }->{itemcallnumber} = $item->{itemcallnumber};
+ }
+
+ # item is available
+ else {
+ $can_place_holds = 1;
+ $available_count++;
+ $available_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'} }->{count}++ if $item->{'homebranch'};
+ $available_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'} }->{branchname} = $item->{'branchname'};
+ $available_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'} }->{location} = $locations{$item->{location}};
+ $available_items->{ $item->{'homebranch'}.'--'.$item->{location}.$item->{'itemcallnumber'} }->{itemcallnumber} = $item->{itemcallnumber};
+ }
+ }
+ } # notforloan, item level and biblioitem level
+ my ($availableitemscount, $onloanitemscount, $otheritemscount);
+ my $maxitems = (C4::Context->preference('maxItemsinSearchResults')) ? C4::Context->preference('maxItemsinSearchResults')- 1 : 1;
+ for my $key ( sort keys %$onloan_items ) {
+ $onloanitemscount++;
+ push @onloan_items_loop, $onloan_items->{$key} unless $onloanitemscount > $maxitems;
+ }
+ for my $key ( sort keys %$other_items ) {
+ $otheritemscount++;
+ push @other_items_loop, $other_items->{$key} unless $otheritemscount > $maxitems;
+ }
+ for my $key ( sort keys %$available_items ) {
+ $availableitemscount++;
+ push @available_items_loop, $available_items->{$key} unless $availableitemscount > $maxitems;
}
- $oldbiblio->{norequests} = $norequests;
+ # last check for norequest : if itemtype is notforloan, it can't be reserved either, whatever the items
+ $can_place_holds = 0 if $itemtypes{$oldbiblio->{itemtype}}->{notforloan};
+ $oldbiblio->{norequests} = 1 unless $can_place_holds;
+ $oldbiblio->{itemsplural} = 1 if $items_count>1;
$oldbiblio->{items_count} = $items_count;
- $oldbiblio->{items_loop} = \@items_loop;
+ $oldbiblio->{available_items_loop} = \@available_items_loop;
+ $oldbiblio->{onloan_items_loop} = \@onloan_items_loop;
+ $oldbiblio->{other_items_loop} = \@other_items_loop;
+ $oldbiblio->{availablecount} = $available_count;
+ $oldbiblio->{availableplural} = 1 if $available_count>1;
$oldbiblio->{onloancount} = $onloan_count;
+ $oldbiblio->{onloanplural} = 1 if $onloan_count>1;
+ $oldbiblio->{othercount} = $other_count;
+ $oldbiblio->{otherplural} = 1 if $other_count>1;
$oldbiblio->{wthdrawncount} = $wthdrawn_count;
$oldbiblio->{itemlostcount} = $itemlost_count;
+ $oldbiblio->{damagedcount} = $itemdamaged_count;
$oldbiblio->{orderedcount} = $ordered_count;
$oldbiblio->{isbn} =~ s/-//g; # deleting - in isbn to enable amazon content
push( @newresults, $oldbiblio );
diff --git a/catalogue/updateitem.pl b/catalogue/updateitem.pl
index 9c95ec3d2a..cdd8d464f8 100755
--- a/catalogue/updateitem.pl
+++ b/catalogue/updateitem.pl
@@ -64,7 +64,7 @@ if ( $itemnotes ne $item_data_hashref->{'itemnotes'}) {
$newitemdata->{'itemnumber'} = $itemnumber;
# &C4::Biblio::_koha_modify_item($dbh,$newitemdata);
- $sth = $dbh->prepare("UPDATE items SET wthdrawn=?,itemlost=?,damaged=?,itemnotes=? WHERE itemnumber=?");
+ my $sth = $dbh->prepare("UPDATE items SET wthdrawn=?,itemlost=?,damaged=?,itemnotes=? WHERE itemnumber=?");
$sth->execute($wthdrawn,$itemlost,$damaged,$itemnotes,$itemnumber);
&ModZebra($biblionumber,"specialUpdate","biblioserver");
diff --git a/etc/zebradb/ccl.properties b/etc/zebradb/ccl.properties
index 7e49986831..ebd2ea7caa 100644
--- a/etc/zebradb/ccl.properties
+++ b/etc/zebradb/ccl.properties
@@ -859,7 +859,8 @@ st-free-form-text 4=105
st-document-text 4=106
st-local-number 4=107
st-string 4=108
-st-numeric 4=109
+# http://indexdata.dk/yaz/doc/tools.tkl#ccl.special.attribute.combos
+st-numeric 4=109 r=o
#string 109
### 5. BIB1 TRUNCATION ATTRIBUTES
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc
index 4a23a96ba7..ffa14b9a28 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc
@@ -3,14 +3,12 @@
Refine your search
+
Availability
+ (related searches: )
+
-
-
-
">
+
+ ">
&sort_by=&limit=:" title=""> ) -->
&expand=#">Show More
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/resort_form.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/resort_form.inc
index fcbfb76350..5b3f216530 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/resort_form.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/resort_form.inc
@@ -1,23 +1,27 @@
Relevance
+
selected="selected" >Popularity (Most to Least)
selected="selected" >Popularity (Least to Most)
+
selected="selected" >Author (A-Z)
selected="selected" >Author (Z-A)
+
selected="selected" >Call Number (Non-fiction 0-9 to Fiction A-Z)
selected="selected" >Call Number (Fiction Z-A to Non-fiction 9-0)
-
+
+
selected="selected" >Publication/Copyright Date: Newest to Oldest
-
selected="selected" >Publication/Copyright Date: Oldest to Newest
selected="selected" >Acquisition Date: Newest to Oldest
selected="selected" >Acquisition Date: Oldest to Newest
+
selected="selected" >Title (A-Z)
selected="selected" >Title (Z-A)
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 8d8a716c6a..898cc70552 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
@@ -274,7 +274,7 @@ $(window).load(function() {
- " title="" style="float: left; margin: .1em;" />
+ " title="" style="float: left; margin: .1em;" alt="img" />
" title="Search for this Author">
@@ -289,6 +289,7 @@ $(window).load(function() {
;
(modified on )
+ ["> ]
@@ -298,19 +299,53 @@ $(window).load(function() {
">Holds
-
-
- copies available at:
+
+
+
+
+ itemsitem
+
+
+ available:
+
-
No copies available:
+
No items available
+
+
+
+ on loan:
+
+
+
+
+
+ ["> ]
+ (, long overdue) date due:
+
-
- On loan (),
- Withdrawn (),
- Lost ()
- On order ()
-
-
+
+
+ unavailable:
+
+
+
+
+
+ ["> ]
+ (Withdrawn)
+ (Lost)
+ (Damaged)
+ ()
+
+
+
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 5e1333db1d..297376599c 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
@@ -139,19 +139,27 @@ href="/cgi-bin/koha/opac-rss.pl?q= -
:
;
- (modified on )
+ (modified on )
+
+
-
- copies available at: -->["> ](),
-
-No copies available:
-
-
- On loan (),
- Withdrawn (),
- Lost ()
- On order ()
-
+
+ Copies available at:
+
+
+ (),
+
+
+
+ No items available:
+
+
+ On loan (),
+ Withdrawn (),
+ Lost (),
+ Damaged (),
+ On order (),
+
">Place Reserve " title="Click to add to book bag" /> "> /images/.gif" alt="" title="" />
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index 0cc0dcc560..518b5afdec 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -445,15 +445,16 @@ $template->param ( QUERY_INPUTS => \@query_inputs );
my @limit_inputs = _input_cgi_parse($query_cgi);
# add OPAC 'hidelostitems'
-# not items with
if (C4::Context->preference('hidelostitems') == 1) {
- $query ="($query) not ((lost,st-numeric gt 0) or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches=''))";
- warn "Q".$query;
+ # either lost ge 0 or no value in the lost register
+ $query ="($query) and ( (lost,st-numeric <= 0) or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='') )";
}
+
# add OPAC suppression - requires at least one item indexed with Suppress
if (C4::Context->preference('OpacSuppression')) {
$query = "($query) not Suppress=1";
}
+
$template->param ( LIMIT_INPUTS => \@limit_inputs );
## II. DO THE SEARCH AND GET THE RESULTS
--
2.39.5