added a MAX_HOLDS event and tests in the hold permit scripts
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 8 Jan 2007 18:47:08 +0000 (18:47 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 8 Jan 2007 18:47:08 +0000 (18:47 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6741 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/backend/circ/circ_lib.js
Open-ILS/src/javascript/backend/circ/circ_permit_hold.js
Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/ScriptBuilder.pm
Open-ILS/web/opac/skin/default/xml/common/holds.xml

index cf71a3e..28639e7 100644 (file)
@@ -181,6 +181,13 @@ function isOrgDescendent( parentName, childId ) {
        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);
index f098ebd..8cf1705 100644 (file)
@@ -3,6 +3,17 @@ function go() {
 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');
 
index a0da315..ef708c0 100644 (file)
@@ -363,6 +363,35 @@ sub retrieve_holds {
        }
 }
 
+
+__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",
index 6e48b35..41ab511 100644 (file)
@@ -104,6 +104,7 @@ sub build_runner {
 
        insert_org_methods( $editor, $runner );
        insert_copy_methods( $editor, $ctx, $runner );
+   insert_user_funcs( $editor, $ctx, $runner );
 
        return $runner;
 }
@@ -369,13 +370,27 @@ sub insert_copy_methods {
                $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;
+               }
+       );
+}
 
 
 
index 5c6170c..31ba993 100644 (file)
                <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>