bug 2677: restore RandomizeHoldsQueueWeight and StaticHoldsQueueWeight

Restoring the functionality of these sysprefs as part of the
rework of build_holds_queue.pl:

* StaticHoldsQueueWeight is an ordered list of library codes.
  The order of the libraries in this list determines the order
  of libraries in which available items will be chosen to be
  targeted to holds.  Note that if this list does not include
  a library, items from that library will never be targeted to
  holds and staff will never be asked to retrieve items for
  title-level holds from those libraries.

* RandomizeHoldsQueueWeight is a Boolean parameter, indicating
  whether to randomize the libraries in the StaticHoldsQueueWeight
  list.

If neither RandomizeHoldsQueueWeight nor StaticHoldsQueueWeight is
set, then the libraries will be used to target items to holds in
alphabetical order by library code.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
Galen Charlton 2008-10-15 08:52:34 -05:00
parent 2cf0eeedb6
commit 9fd39af7a0
1 changed files with 43 additions and 6 deletions

View File

@ -20,7 +20,8 @@ use C4::Branch;
use C4::Circulation;
use C4::Members;
use C4::Biblio;
use Data::Dumper;
use List::Util qw(shuffle);
my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests();
@ -32,13 +33,16 @@ my $total_bibs = 0;
my $total_requests = 0;
my $total_available_items = 0;
my $num_items_mapped = 0;
my @branches_to_use = _get_branches_to_pull_from();
foreach my $biblionumber (@$bibs_with_pending_requests) {
$total_bibs++;
my $hold_requests = GetPendingHoldRequestsForBib($biblionumber);
$total_requests += scalar(@$hold_requests);
my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber);
my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, @branches_to_use);
$total_available_items += scalar(@$available_items);
my $item_map = MapItemsToHoldRequests($hold_requests, $available_items);
my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, @branches_to_use);
if (defined($item_map)) {
$num_items_mapped += scalar(keys %$item_map);
CreatePicklistFromItemMap($item_map);
@ -151,6 +155,7 @@ to fill a hold request if and only if:
sub GetItemsAvailableToFillHoldRequestsForBib {
my $biblionumber = shift;
my @branches_to_use = @_;
my $dbh = C4::Context->dbh;
my $items_query = "SELECT itemnumber, homebranch, holdingbranch
@ -176,8 +181,13 @@ sub GetItemsAvailableToFillHoldRequestsForBib {
AND (found IS NOT NULL OR priority = 0)
)
AND biblionumber = ?";
my @params = ($biblionumber, $biblionumber);
if ($#branches_to_use > -1) {
$items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @branches_to_use) . ")";
push @params, @branches_to_use;
}
my $sth = $dbh->prepare($items_query);
$sth->execute($biblionumber, $biblionumber);
$sth->execute(@params);
my $items = $sth->fetchall_arrayref({});
return [ grep { my @transfers = GetTransfers($_->{itemnumber}); $#transfers == -1; } @$items ];
@ -196,6 +206,7 @@ MapItemsToHoldRequests($hold_requests, $available_items);
sub MapItemsToHoldRequests {
my $hold_requests = shift;
my $available_items = shift;
my @branches_to_use = @_;
# handle trival cases
return unless scalar(@$hold_requests) > 0;
@ -271,8 +282,14 @@ sub MapItemsToHoldRequests {
};
$num_items_remaining--;
} else {
# FIXME implement static, random options
foreach my $branch (sort keys %items_by_branch) {
my @pull_branches = ();
if ($#branches_to_use > -1) {
@pull_branches = @branches_to_use;
} else {
@pull_branches = sort keys %items_by_branch;
}
foreach my $branch (@pull_branches) {
next unless exists $items_by_branch{$branch};
my $item = pop @{ $items_by_branch{$branch} };
delete $items_by_branch{$branch} if scalar(@{ $items_by_branch{$branch} }) == 0;
$item_map{$item->{itemnumber}} = {
@ -358,3 +375,23 @@ sub AddToHoldTargetMap {
$mapped_item->{holdingbranch}, $mapped_item->{item_level});
}
}
=head2 _get_branches_to_pull_from
Query system preferences to get ordered list of
branches to use to fill hold requests.
=cut
sub _get_branches_to_pull_from {
my @branches_to_use = ();
my $static_branch_list = C4::Context->preference("StaticHoldsQueueWeight");
if ($static_branch_list) {
@branches_to_use = map { s/^\s+//; s/\s+$//; $_; } split /,/, $static_branch_list;
}
@branches_to_use = shuffle(@branches_to_use) if C4::Context->preference("RandomizeHoldsQueueWeight");
return @branches_to_use;
}