[Koha-cvs] CVS: koha/C4 Reserves2.pm,1.29,1.30

Paul POULAIN tipaul at users.sourceforge.net
Thu Apr 24 18:29:12 CEST 2003


Update of /cvsroot/koha/koha/C4
In directory sc8-pr-cvs1:/tmp/cvs-serv979/C4

Modified Files:
	Reserves2.pm 
Log Message:
some fixes

Index: Reserves2.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Reserves2.pm,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -r1.29 -r1.30
*** Reserves2.pm	7 Apr 2003 14:05:29 -0000	1.29
--- Reserves2.pm	24 Apr 2003 16:29:09 -0000	1.30
***************
*** 104,179 ****
  #'
  sub FindReserves {
!   my ($bib,$bor)=@_;
!   my $dbh = C4::Context->dbh;
!   # Find the desired items in the reserves
!   my $query="SELECT *,reserves.branchcode,biblio.title AS btitle
!                       FROM reserves,borrowers,biblio ";
!   # FIXME - These three bits of SQL seem to contain a fair amount of
!   # redundancy. Wouldn't it be better to have a @clauses array, add
!   # one or two clauses as necessary, then join(" AND ", @clauses) ?
!   if ($bib ne ''){
!       $bib = $dbh->quote($bib);
!       if ($bor ne ''){
! 	  # Both $bib and $bor specified
! 	  # Find a particular book for a particular patron
! 	  $bor = $dbh->quote($bor);
!           $query .=  " where reserves.biblionumber   = $bib
!                          and borrowers.borrowernumber = $bor
!                          and reserves.borrowernumber = borrowers.borrowernumber
!                          and biblio.biblionumber     = $bib
!                          and cancellationdate is NULL
!                          and (found <> 'F' or found is NULL)";
!       } else {
! 	  # $bib specified, but not $bor
! 	  # Find a particular book for all patrons
!           $query .= " where reserves.borrowernumber = borrowers.borrowernumber
!                         and biblio.biblionumber     = $bib
!                         and reserves.biblionumber   = $bib
!                         and cancellationdate is NULL
!                         and (found <> 'F' or found is NULL)";
!       }
!   } else {
!       # FIXME - Check that $bor was given
! 
!       # No $bib given.
!       # Find all books for the given patron.
!       $query .= " where borrowers.borrowernumber = $bor
!                     and reserves.borrowernumber  = borrowers.borrowernumber
!                     and reserves.biblionumber    = biblio.biblionumber
!                     and cancellationdate is NULL and
!                     (found <> 'F' or found is NULL)";
!   }
!   $query.=" order by priority";
!   my $sth=$dbh->prepare($query);
!   $sth->execute;
!   my @results;
!   while (my $data=$sth->fetchrow_hashref){
!       # FIXME - What is this if-statement doing? How do constraints work?
!       if ($data->{'constrainttype'} eq 'o') {
! 	  my $conquery = "SELECT biblioitemnumber FROM reserveconstraints
!                            WHERE biblionumber   = ?
!                              AND borrowernumber = ?
!                              AND reservedate    = ?";
! 	  my $csth=$dbh->prepare($conquery);
! 	  # FIXME - Why use separate variables for this?
! 	  my $bibn = $data->{'biblionumber'};
! 	  my $born = $data->{'borrowernumber'};
! 	  my $resd = $data->{'reservedate'};
! 	  $csth->execute($bibn, $born, $resd);
! 	  my ($bibitemno) = $csth->fetchrow_array;
! 	  $csth->finish;
! 	  # Look up the book we just found.
! 	  my $bdata = C4::Search::bibitemdata($bibitemno);
! 	  # Add the results of this latest search to the current
! 	  # results.
! 	  # FIXME - An 'each' would probably be more efficient.
! 	  foreach my $key (keys %$bdata) {
! 	      $data->{$key} = $bdata->{$key};
! 	  }
!       }
! 	push @results, $data;
!   }
!   $sth->finish;
!   return($#results+1,\@results);
  }
  
--- 104,178 ----
  #'
  sub FindReserves {
! 	my ($bib,$bor)=@_;
! 	warn "bib : $bib , bor : $bor";
! 	my $dbh = C4::Context->dbh;
! 	# Find the desired items in the reserves
! 	my $query="SELECT *,reserves.branchcode,biblio.title AS btitle  FROM reserves,borrowers,biblio ";
! 	# FIXME - These three bits of SQL seem to contain a fair amount of
! 	# redundancy. Wouldn't it be better to have a @clauses array, add
! 	# one or two clauses as necessary, then join(" AND ", @clauses) ?
! 	if ($bib ne ''){
! 		$bib = $dbh->quote($bib);
! 		if ($bor ne ''){
! 			# Both $bib and $bor specified
! 			# Find a particular book for a particular patron
! 			$bor = $dbh->quote($bor);
! 			$query .=  " where reserves.biblionumber   = $bib
! 						and borrowers.borrowernumber = $bor
! 						and reserves.borrowernumber = borrowers.borrowernumber
! 						and biblio.biblionumber     = $bib
! 						and cancellationdate is NULL
! 						and (found <> 'F' or found is NULL)";
! 		} else {
! 			# $bib specified, but not $bor
! 			# Find a particular book for all patrons
! 			$query .= " where reserves.borrowernumber = borrowers.borrowernumber
! 					and biblio.biblionumber     = $bib
! 					and reserves.biblionumber   = $bib
! 					and cancellationdate is NULL
! 					and (found <> 'F' or found is NULL)";
! 		}
! 	} else {
! 		# FIXME - Check that $bor was given
! 		# No $bib given.
! 		# Find all books for the given patron.
! 		$query .= " where borrowers.borrowernumber = $bor
! 					and reserves.borrowernumber  = borrowers.borrowernumber
! 					and reserves.biblionumber    = biblio.biblionumber
! 					and cancellationdate is NULL and
! 					(found <> 'F' or found is NULL)";
! 	}
! 	$query.=" order by priority";
! 	my $sth=$dbh->prepare($query);
! 	$sth->execute;
! 	my @results;
! 	while (my $data=$sth->fetchrow_hashref){
! 		# FIXME - What is this if-statement doing? How do constraints work?
! 		if ($data->{'constrainttype'} eq 'o') {
! 			my $conquery = "SELECT biblioitemnumber FROM reserveconstraints
! 							WHERE biblionumber   = ?
! 							AND borrowernumber = ?
! 							AND reservedate    = ?";
! 			my $csth=$dbh->prepare($conquery);
! 			# FIXME - Why use separate variables for this?
! 			my $bibn = $data->{'biblionumber'};
! 			my $born = $data->{'borrowernumber'};
! 			my $resd = $data->{'reservedate'};
! 			$csth->execute($bibn, $born, $resd);
! 			my ($bibitemno) = $csth->fetchrow_array;
! 			$csth->finish;
! 			# Look up the book we just found.
! 			my $bdata = C4::Search::bibitemdata($bibitemno);
! 			# Add the results of this latest search to the current
! 			# results.
! 			# FIXME - An 'each' would probably be more efficient.
! 			foreach my $key (keys %$bdata) {
! 				$data->{$key} = $bdata->{$key};
! 			}
! 		}
! 		push @results, $data;
! 	}
! 	$sth->finish;
! 	return($#results+1,\@results);
  }
  
***************
*** 380,383 ****
--- 379,383 ----
                                    AND borrowernumber = $borr
                                    AND reservedate    = $resdate)";
+ 	warn "q : $query";
      my $sth=$dbh->prepare($query);
      $sth->execute;





More information about the Koha-cvs mailing list