return false;
}
+/* returns the number of unfulfilled holds open on this user */
+function userHoldCount(userid) {
+ var key = scratchKey();
+ __OILS_FUNC_userHoldCount(scratchPad(key), userid);
+ return getScratch(key);
+}
+
function hasCommonAncestor( org1, org2, depth ) {
var key = scratchKey();
__OILS_FUNC_hasCommonAncestor(scratchPad(key), org1, org2, depth);
load_lib('circ/circ_lib.js');
log_vars('circ_permit_hold');
+
+
+/* non-staff members are allowed 50 open holds at most */
+if( ! isGroupDescendant('Staff', patronProfile) ) {
+ var count = userHoldCount(patron.id);
+ log_info("patron has " + count + " open holds");
+ if( count >= 50 )
+ result.events.push('MAX_HOLDS');
+}
+
+
if( isTrue(patron.barred) )
result.events.push('PATRON_BARRED');
}
}
+
+__PACKAGE__->register_method(
+ method => 'user_hold_count',
+ api_name => 'open-ils.circ.hold.user.count');
+
+sub user_hold_count {
+ my( $self, $conn, $auth, $userid ) = @_;
+ my $e = new_editor(authtoken=>$auth);
+ return $e->event unless $e->checkauth;
+ my $patron = $e->retrieve_actor_user($userid)
+ or return $e->event;
+ return $e->event unless $e->allowed('VIEW_HOLD', $patron->home_ou);
+ return $self->__user_hold_count($e, $userid);
+}
+
+sub __user_hold_count {
+ my( $self, $e, $userid ) = @_;
+ my $holds = $e->search_action_hold_request(
+ { usr => $userid ,
+ fulfillment_time => undef,
+ cancel_time => undef,
+ },
+ {idlist => 1}
+ );
+
+ return scalar(@$holds);
+}
+
+
__PACKAGE__->register_method(
method => "retrieve_holds_by_pickup_lib",
api_name => "open-ils.circ.holds.retrieve_by_pickup_lib",
insert_org_methods( $editor, $runner );
insert_copy_methods( $editor, $ctx, $runner );
+ insert_user_funcs( $editor, $ctx, $runner );
return $runner;
}
$runner->insert_method( 'environment.copy', '__OILS_FUNC_fetch_best_hold', sub {
my $key = shift;
$logger->debug("script_builder: searching for permitted hold for copy ".$copy->barcode);
- my ($hold) = $holdcode->find_nearest_permitted_hold( $e, $copy, $reqr, 1 );
+ my ($hold) = $holdcode->find_nearest_permitted_hold( $e, $copy, $reqr, 1 ); # do we need a new editor here since the xact may be dead??
$runner->insert( $key, $hold, 1 );
}
);
}
}
+sub insert_user_funcs {
+ my( $e, $ctx, $runner ) = @_;
+
+ # tells how many holds a user has
+ $runner->insert(__OILS_FUNC_userHoldCount =>
+ sub {
+ my( $write_key, $userid ) = @_;
+ my $val = $holdcode->__user_hold_count(new_editor(), $userid);
+ $logger->info("script_runner: user hold count is $val");
+ $runner->insert($write_key, $val, 1) if $val;
+ return $val;
+ }
+ );
+}
<span class='hide_me' id='hold_not_allowed'>
No items were found that could fulfill the requested holds.
It's possible that choosing a different format will result in a successful hold.
- Otherwise, please consult your local librarian.
+ It is also possible that you have exceeded the number of allowable holds.
+ For further information, please consult your local librarian.
</span>
</div>