Lines 767-806
sub GetReservesForBranch {
Link Here
|
767 |
|
767 |
|
768 |
=head2 GetReserveStatus |
768 |
=head2 GetReserveStatus |
769 |
|
769 |
|
770 |
$reservestatus = GetReserveStatus($itemnumber, $biblionumber); |
770 |
$reservestatus = GetReserveStatus($itemnumber); |
771 |
|
771 |
|
772 |
Take an itemnumber or a biblionumber and return the status of the reserve places on it. |
772 |
Takes an itemnumber and returns the status of the reserve placed on it. |
773 |
If several reserves exist, the reserve with the lower priority is given. |
773 |
Note that this could be an item level hold OR a title level hold. |
|
|
774 |
If several reserves exist, the reserve with the lowest priority is given. |
774 |
|
775 |
|
775 |
=cut |
776 |
=cut |
776 |
|
777 |
|
777 |
## FIXME: I don't think this does what it thinks it does. |
|
|
778 |
## It only ever checks the first reserve result, even though |
779 |
## multiple reserves for that bib can have the itemnumber set |
780 |
## the sub is only used once in the codebase. |
781 |
sub GetReserveStatus { |
778 |
sub GetReserveStatus { |
782 |
my ($itemnumber, $biblionumber) = @_; |
779 |
my ($itemnumber) = @_; |
783 |
|
780 |
|
784 |
my $dbh = C4::Context->dbh; |
781 |
my $dbh = C4::Context->dbh; |
785 |
|
782 |
|
786 |
my ($sth, $found, $priority); |
783 |
my ($sth, $found, $priority); |
787 |
if ( $itemnumber ) { |
784 |
$sth = $dbh->prepare("SELECT found, priority FROM reserves re LEFT JOIN items it ON re.biblionumber=it.biblionumber WHERE (re.itemnumber IS NULL OR re.itemnumber=it.itemnumber) AND it.itemnumber=? ORDER BY priority LIMIT 1"); |
788 |
$sth = $dbh->prepare("SELECT found, priority FROM reserves WHERE itemnumber = ? order by priority LIMIT 1"); |
785 |
#Note that we catch title level holds by joining the items table |
789 |
$sth->execute($itemnumber); |
786 |
#via the biblionumber. |
790 |
($found, $priority) = $sth->fetchrow_array; |
787 |
#The reserves table does not yet contain the item number in that case ! |
791 |
} |
788 |
$sth->execute($itemnumber); |
792 |
|
789 |
($found, $priority) = $sth->fetchrow_array; |
793 |
if ( $biblionumber and not defined $found and not defined $priority ) { |
790 |
$found//=''; |
794 |
$sth = $dbh->prepare("SELECT found, priority FROM reserves WHERE biblionumber = ? order by priority LIMIT 1"); |
|
|
795 |
$sth->execute($biblionumber); |
796 |
($found, $priority) = $sth->fetchrow_array; |
797 |
} |
798 |
|
791 |
|
799 |
if(defined $found) { |
792 |
return 'Waiting' if $found eq 'W' and $priority == 0; |
800 |
return 'Waiting' if $found eq 'W' and $priority == 0; |
793 |
return 'Finished' if $found eq 'F'; |
801 |
return 'Finished' if $found eq 'F'; |
794 |
return 'Reserved' if $priority > 0; |
802 |
return 'Reserved' if $priority > 0; |
|
|
803 |
} |
804 |
return ''; |
795 |
return ''; |
805 |
#empty string here will remove need for checking undef, or less log lines |
796 |
#empty string here will remove need for checking undef, or less log lines |
806 |
} |
797 |
} |