[Koha-cvs] koha/C4 Search.pm [dev_week]

Joshua Ferraro jmf at kados.org
Sun Oct 8 23:19:38 CEST 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		dev_week
Changes by:	Joshua Ferraro <kados>	06/10/08 21:19:38

Modified files:
	C4             : Search.pm 

Log message:
	The limit searches weren't working logically ...

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.99.2.11.2.29&r2=1.99.2.11.2.30

Patches:
Index: Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.99.2.11.2.29
retrieving revision 1.99.2.11.2.30
diff -u -b -r1.99.2.11.2.29 -r1.99.2.11.2.30
--- Search.pm	6 Oct 2006 02:31:27 -0000	1.99.2.11.2.29
+++ Search.pm	8 Oct 2006 21:19:38 -0000	1.99.2.11.2.30
@@ -39,7 +39,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.99.2.11.2.29 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.99.2.11.2.30 $' =~ /\d+/g;
           shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 =head1 NAME
@@ -1241,7 +1241,7 @@
 sub ItemInfo {
 	my ($env,$biblionumber,$type) = @_;
 	my $dbh   = C4::Context->dbh;
-	my $query = "SELECT *,itemtypes.notforloan AS itemnotforloan FROM items, biblio, biblioitems 
+	my $query = "SELECT *,items.notforloan AS notforloan, itemtypes.notforloan AS itemnotforloan FROM items, biblio, biblioitems 
 					LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
 					WHERE items.biblionumber = ?
 					AND biblioitems.biblioitemnumber = items.biblioitemnumber
@@ -1285,9 +1285,11 @@
 		$sthnflstatus->execute;
 		my ($authorised_valuecode) = $sthnflstatus->fetchrow;
 		if ($authorised_valuecode) {
+			warn "authorised valuecode: $authorised_valuecode";
 			$sthnflstatus = $dbh->prepare("select lib from authorised_values where category=? and authorised_value=?");
-			$sthnflstatus->execute($authorised_valuecode,$data->{itemnotforloan});
+			$sthnflstatus->execute($authorised_valuecode,$data->{notforloan});
 			my ($lib) = $sthnflstatus->fetchrow;
+			#warn "lib: $lib from $authorised_valuecode,$data->{notforloan}";
 			$data->{notforloan} = $lib;
 		}
 
@@ -2925,7 +2927,6 @@
             			# here we create a minimal MARC record and hand it off to the
             			# template just like a normal result ... perhaps not ideal, but
             			# it works for now FIXME: distinguish between MARC21 and UNIMARC
-        #    			use MARC::Record;
             			my $tmprecord = MARC::Record->new();
             			$tmprecord->encoding('UTF-8');
             			my $tmptitle = MARC::Field->new( '245',' ',' ',
@@ -3181,19 +3182,29 @@
 			$limit_query.=" and (($query and datedue=0000-00-00) or ($query and datedue=0000-00-00 not lost=1) or ($query and datedue=0000-00-00 not lost=2))";
 			#$limit_search_desc.=" and available";
 		}
+		# these queries are treated as OR
 		elsif (($limit_query) && ($limit =~/mc/)) {
 			$limit_query.=" or $limit" if $limit;
 			$limit_search_desc.=" or $limit" if $limit;
 		}
-		elsif (($limit_query) || ($query)) {
+
+		# these are treated as AND
+		elsif ($limit_query) {
         	$limit_query.=" and $limit" if $limit;
 			$limit_search_desc.=" and $limit" if $limit;
 		}
+		# otherwise, there is nothing but the limit
 		else {
         	$limit_query.="$limit" if $limit;
         	$limit_search_desc.="$limit" if $limit;
 		}
     }
+	# if there's also a query, we need to AND the limits to it
+	if (($limit_query) && ($query)) {
+		$limit_query=" and (".$limit_query.")";
+		$limit_search_desc=" and ($limit_search_desc)";
+
+	}
 	$query .= $limit_query;
 	$human_search_desc .= $limit_search_desc;
 	# now normalize the strings
@@ -3268,7 +3279,7 @@
         my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,'');
 		# add spans to search term in results
 		foreach my $term (keys %$span_terms_hashref) {
-			warn "term: $term";
+			#warn "term: $term";
 			my $old_term = $term;
 			if (length($term) > 3) {
 				$term =~ s/(.*=|\)|\(|\+|\.)//g;
@@ -3293,9 +3304,11 @@
         my @fields = $marcrecord->field($itemtag);
 		my @items_loop;
 		my $items;
+		my $ordered_count = 0;
 		my $onloan_count = 0;
 		my $wthdrawn_count = 0;
 		my $itemlost_count = 0;
+		my $itembinding_count = 0;
 		my $norequests = 1;
         foreach my $field (@fields) {
 			my $item;
@@ -3305,19 +3318,27 @@
 			if ($item->{wthdrawn}) {
 				$wthdrawn_count++;
 			}
+			elsif ($item->{notforloan} == -1) {
+				$ordered_count++;
+				$norequests = 0;
+			}
 			elsif ($item->{itemlost}) {
 				$itemlost_count++;
 			}
+			elsif ($item->{binding}) {
+				$itembinding_count++;
+			}
 			elsif (($item->{onloan}) && ($item->{onloan} != '0000-00-00')) {
 				$onloan_count++;
 				$norequests = 0;
 			}
 			else {
 				$norequests = 0;
-				if ($item->{'holdingbranch'}) {
+				if ($item->{'homebranch'}) {
 					$items->{$item->{'holdingbranch'}}->{count}++;
 				}
-				elsif ($item->{'homebranch'}) {
+				# Last resort
+				elsif ($item->{'holdingbranch'}) {
 					$items->{$item->{'homebranch'}}->{count}++;
 				}
 			}
@@ -3333,6 +3354,8 @@
 		$oldbiblio->{onloancount} = $onloan_count;
 		$oldbiblio->{wthdrawncount} = $wthdrawn_count;
 		$oldbiblio->{itemlostcount} = $itemlost_count;
+		$oldbiblio->{bindingcount} = $itembinding_count;
+		$oldbiblio->{orderedcount} = $ordered_count;
 
 =head
 Ugh ... this is ugly, I'll re-write it better above then delete it





More information about the Koha-cvs mailing list