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

Joshua Ferraro jmf at kados.org
Sun Jul 23 20:55:26 CEST 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		dev_week
Changes by:	Joshua Ferraro <kados>	06/07/23 18:55:25

Modified files:
	C4             : Search.pm 
	opac           : opac-zoomsearch.pl 

Log message:
	Move searchResults routine to Search.pm from opac-zoomsearch.pl

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.8&r2=1.99.2.11.2.9
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-zoomsearch.pl?cvsroot=koha&only_with_tag=dev_week&r1=1.1.2.12&r2=1.1.2.13

Patches:
Index: C4/Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.99.2.11.2.8
retrieving revision 1.99.2.11.2.9
diff -u -b -r1.99.2.11.2.8 -r1.99.2.11.2.9
--- C4/Search.pm	23 Jul 2006 18:02:09 -0000	1.99.2.11.2.8
+++ C4/Search.pm	23 Jul 2006 18:55:25 -0000	1.99.2.11.2.9
@@ -35,7 +35,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.8 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.99.2.11.2.9 $' =~ /\d+/g;
           shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 =head1 NAME
@@ -73,7 +73,7 @@
 &findseealso &findguarantor &getwebsites &getwebbiblioitems &itemcount2 &FindDuplicate
 &isbnsearch &getbranchname &getborrowercategory &getborrowercategoryinfo 
 
-&searchZOOM &catalogsearch &catalogsearch3 &CatSearch3 &catalogsearch4
+&searchZOOM &catalogsearch &catalogsearch3 &CatSearch3 &catalogsearch4 &searchResults
 
 &getMARCnotes &getMARCsubjects &getMARCurls);
 # make all your functions, whether exported or not;
@@ -4408,6 +4408,141 @@
     return(undef,$numresults,$facets, at results);
 }
 
+
+sub searchResults {
+    my ($num,$count, at marcresults)=@_;
+    use C4::Date;
+
+    my $dbh= C4::Context->dbh;
+    my $toggle;
+    my $even=1;
+    my @newresults;
+
+    #Build brancnames hash
+    #find branchname
+    #get branch information.....
+    my %branches;
+    my $bsth=$dbh->prepare("SELECT branchcode,branchname FROM branches");
+    $bsth->execute();
+    while (my $bdata=$bsth->fetchrow_hashref){
+        $branches{$bdata->{'branchcode'}}= $bdata->{'branchname'};
+    }
+
+    #search item field code
+    my $sth = $dbh->prepare(
+        "select tagfield from marc_subfield_structure where kohafield like 'items.itemnumber'"
+        );
+    $sth->execute;
+    my ($itemtag) = $sth->fetchrow;
+
+    ## find column names of items related to MARC
+    my $sth2=$dbh->prepare("SHOW COLUMNS from items");
+    $sth2->execute;
+    my %subfieldstosearch;
+    while ((my $column)=$sth2->fetchrow){
+        my ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.".$column,"");
+        $subfieldstosearch{$column}=$tagsubfield;
+    }
+    if ($num>$count) {
+            $num = $count;
+    }
+    for ( my $i=0; $i<$num ; $i++){
+        my $marcrecord;
+        $marcrecord = MARC::File::USMARC::decode($marcresults[$i]);
+        my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,'');
+        if ($i % 2) {
+            $toggle="#ffffcc";
+        } else {
+            $toggle="white";
+        }
+        $oldbiblio->{'toggle'}=$toggle;
+        my @fields = $marcrecord->field($itemtag);
+        my @items;
+        my $item;
+        my %counts;
+        $counts{'total'}=0;
+
+#
+##Loop for each item field
+        foreach my $field (@fields) {
+        foreach my $code ( keys %subfieldstosearch ) {
+
+        $item->{$code}=$field->subfield($subfieldstosearch{$code});
+        }
+
+        my $status;
+        $item->{'branchname'}=$branches{$item->{'homebranch'}};
+        $item->{'date_due'}=$item->{onloan};
+        $status="Lost" if ($item->{itemlost});
+        $status="Withdrawn" if ($item->{wthdrawn});
+        $status =" On loan" if ($item->{onloan});
+        #$status="Due:".format_date($item->{onloan}) if ($item->{onloan}>0 );
+        # $status="On Loan" if ($item->{onloan} );
+        if ($item->{'location'}){
+            $status = $item->{'branchname'}."[".$item->{'location'}."]" unless defined $status;
+        }else{
+            $status = $item->{'branchname'} unless defined $status;
+        }
+        $counts{$status}++;
+        $counts{'total'}++;
+        push @items,$item;
+    }
+    my $norequests = 1;
+    my $noitems    = 1;
+    if (@items) {
+        $noitems = 0;
+        foreach my $itm (@items) {
+            $norequests = 0 unless $itm->{'itemnotforloan'};
+        }
+    }
+    $oldbiblio->{'noitems'} = $noitems;
+    $oldbiblio->{'norequests'} = $norequests;
+    $oldbiblio->{'even'} = $even = not $even;
+    $oldbiblio->{'itemcount'} = $counts{'total'};
+    my $totalitemcounts = 0;
+    foreach my $key (keys %counts){
+        if ($key ne 'total'){
+            $totalitemcounts+= $counts{$key};
+            $oldbiblio->{'locationhash'}->{$key}=$counts{$key};
+        }
+    }
+    my ($locationtext, $locationtextonly, $notavailabletext) = ('','','');
+    foreach (sort keys %{$oldbiblio->{'locationhash'}}) {
+        if ($_ eq 'notavailable') {
+            $notavailabletext="Not available";
+            my $c=$oldbiblio->{'locationhash'}->{$_};
+            $oldbiblio->{'not-available-p'}=$c;
+        } else {
+            $locationtext.="$_";
+            my $c=$oldbiblio->{'locationhash'}->{$_};
+            if ($_ eq 'Item Lost') {
+                $oldbiblio->{'lost-p'} = $c;
+            } elsif ($_ eq 'Withdrawn') {
+                $oldbiblio->{'withdrawn-p'} = $c;
+            } elsif ($_ eq 'On Loan') {
+                $oldbiblio->{'on-loan-p'} = $c;
+            } else {
+                $locationtextonly.= $_;
+                $locationtextonly.= " ($c)<br/> " if $totalitemcounts > 1;
+            }
+            if ($totalitemcounts>1) {
+                $locationtext.=" ($c)<br/> ";
+            }
+        }
+    }
+    if ($notavailabletext) {
+        $locationtext.= $notavailabletext;
+    } else {
+        $locationtext=~s/, $//;
+    }
+    $oldbiblio->{'location'} = $locationtext;
+    $oldbiblio->{'location-only'} = $locationtextonly;
+    $oldbiblio->{'use-location-flags-p'} = 1;
+    push (@newresults, $oldbiblio);
+
+    }
+    return @newresults;
+}
 END { }       # module clean-up code here (global destructor)
 
 1;

Index: opac/opac-zoomsearch.pl
===================================================================
RCS file: /sources/koha/koha/opac/Attic/opac-zoomsearch.pl,v
retrieving revision 1.1.2.12
retrieving revision 1.1.2.13
diff -u -b -r1.1.2.12 -r1.1.2.13
--- opac/opac-zoomsearch.pl	23 Jul 2006 18:02:09 -0000	1.1.2.12
+++ opac/opac-zoomsearch.pl	23 Jul 2006 18:55:25 -0000	1.1.2.13
@@ -466,140 +466,3 @@
 	warn "NICE: $nice_query";
 	return ('',$pqf_sort_by, $pqf_prox_ops, $pqf_bool_ops, $pqf_query, $nice_query);
 }
-
-
-
-sub searchResults {
-	my ($num,$count, at marcresults)=@_;	
-	use C4::Date;
-
-	my $dbh= C4::Context->dbh;
-	my $toggle;
-	my $even=1;
-	my @newresults;
-
-	#Build brancnames hash
-	#find branchname
-	#get branch information.....
-	my %branches;
-	my $bsth=$dbh->prepare("SELECT branchcode,branchname FROM branches");
-	$bsth->execute();
-	while (my $bdata=$bsth->fetchrow_hashref){
-		$branches{$bdata->{'branchcode'}}= $bdata->{'branchname'};
-	}
-
-	#search item field code
-	my $sth = $dbh->prepare(
-		"select tagfield from marc_subfield_structure where kohafield like 'items.itemnumber'"
-        );
-	$sth->execute;
-	my ($itemtag) = $sth->fetchrow;
-	
-	## find column names of items related to MARC
-	my $sth2=$dbh->prepare("SHOW COLUMNS from items");
-	$sth2->execute;
-	my %subfieldstosearch;
-	while ((my $column)=$sth2->fetchrow){
-		my ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.".$column,"");
-		$subfieldstosearch{$column}=$tagsubfield;
-	}
-	if ($num>$count) {
-			$num = $count;
-	}
-	for ( my $i=0; $i<$num ; $i++){
-		my $marcrecord;					
-		$marcrecord = MARC::File::USMARC::decode($marcresults[$i]);
-		my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,'');
-		if ($i % 2) {
-			$toggle="#ffffcc";
-		} else {
-			$toggle="white";
-		}
-		$oldbiblio->{'toggle'}=$toggle;
- 		my @fields = $marcrecord->field($itemtag);
-		my @items;
-		my $item;
-		my %counts;
-		$counts{'total'}=0;
-
-#	
-##Loop for each item field
-		foreach my $field (@fields) {
-	   	foreach my $code ( keys %subfieldstosearch ) {
-
-		$item->{$code}=$field->subfield($subfieldstosearch{$code});
-		}
-
-		my $status;
-		$item->{'branchname'}=$branches{$item->{'homebranch'}};
-		$item->{'date_due'}=$item->{onloan};
-		$status="Lost" if ($item->{itemlost});
-		$status="Withdrawn" if ($item->{wthdrawn});
-		$status =" On loan" if ($item->{onloan});
-		#$status="Due:".format_date($item->{onloan}) if ($item->{onloan}>0 );
-		# $status="On Loan" if ($item->{onloan} );
-		if ($item->{'location'}){
-			$status = $item->{'branchname'}."[".$item->{'location'}."]" unless defined $status;
-		}else{
-			$status = $item->{'branchname'} unless defined $status;
-		}
-		$counts{$status}++;
-		$counts{'total'}++;
-		push @items,$item;
-	}
-	my $norequests = 1;
-	my $noitems    = 1;
-	if (@items) {
-		$noitems = 0;
-		foreach my $itm (@items) {
-			$norequests = 0 unless $itm->{'itemnotforloan'};
-		}
-	}
-	$oldbiblio->{'noitems'} = $noitems;
-	$oldbiblio->{'norequests'} = $norequests;
-	$oldbiblio->{'even'} = $even = not $even;
-	$oldbiblio->{'itemcount'} = $counts{'total'};
-	my $totalitemcounts = 0;
-	foreach my $key (keys %counts){
-		if ($key ne 'total'){	
-			$totalitemcounts+= $counts{$key};
-			$oldbiblio->{'locationhash'}->{$key}=$counts{$key};
-		}
-	}
-	my ($locationtext, $locationtextonly, $notavailabletext) = ('','','');
-	foreach (sort keys %{$oldbiblio->{'locationhash'}}) {
-		if ($_ eq 'notavailable') {
-			$notavailabletext="Not available";
-			my $c=$oldbiblio->{'locationhash'}->{$_};
-			$oldbiblio->{'not-available-p'}=$c;
-		} else {
-			$locationtext.="$_";
-			my $c=$oldbiblio->{'locationhash'}->{$_};
-			if ($_ eq 'Item Lost') {
-				$oldbiblio->{'lost-p'} = $c;
-			} elsif ($_ eq 'Withdrawn') {
-				$oldbiblio->{'withdrawn-p'} = $c;
-			} elsif ($_ eq 'On Loan') {
-				$oldbiblio->{'on-loan-p'} = $c;
-			} else {
-				$locationtextonly.= $_;
-				$locationtextonly.= " ($c)<br/> " if $totalitemcounts > 1;
-			}
-			if ($totalitemcounts>1) {
-				$locationtext.=" ($c)<br/> ";
-			}
-		}
-	}
-	if ($notavailabletext) {
-		$locationtext.= $notavailabletext;
-	} else {
-		$locationtext=~s/, $//;
-	}
-	$oldbiblio->{'location'} = $locationtext;
-	$oldbiblio->{'location-only'} = $locationtextonly;
-	$oldbiblio->{'use-location-flags-p'} = 1;
-	push (@newresults, $oldbiblio);
-
-	}
-	return @newresults;
-}





More information about the Koha-cvs mailing list