added age-protect logic to the hold permit code
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 3 Aug 2006 15:29:48 +0000 (15:29 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 3 Aug 2006 15:29:48 +0000 (15:29 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5246 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/ils_events.xml
Open-ILS/src/javascript/backend/circ/circ_permit_hold.js
Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm
Open-ILS/web/opac/common/js/opac_utils.js
Open-ILS/web/opac/skin/default/js/holds.js
Open-ILS/web/opac/skin/default/xml/common/holds.xml

index d4f28bc..5df39b6 100644 (file)
        <event code='1217' textcode='PATRON_INACTIVE'>
                <desc xml:lang="en-US">This account is marked as inactive</desc>
        </event>
+       <event code='1218' textcode='ITEM_AGE_PROTECTED'>
+               <desc xml:lang="en-US">This item is too new to have a hold placed on it</desc>
+       </event>
 
 
 
index e5c61cf..d0ca408 100644 (file)
@@ -1,4 +1,3 @@
-
 function go() {
 
 load_lib('circ/circ_lib.js');
@@ -7,15 +6,12 @@ log_vars('circ_permit_hold');
 if( isTrue(patron.barred) ) 
        result.events.push('PATRON_BARRED');
 
-/* projected medium */
+/* projected medium 
+       this needs to be expanded to check circ_modifiers as well
+*/
 if( getMARCItemType() == 'g' &&
                !isOrgDescendent(copy.circ_lib.shortname, patron.home_ou.id) )
        result.events.push('CIRC_EXCEEDS_COPY_RANGE');
 
-
-/* XXX Age-hold protection */
-
-
-
 } go();
 
index 285e756..95e0547 100644 (file)
@@ -5,8 +5,10 @@ use OpenSRF::Utils;
 use OpenSRF::Utils::SettingsClient;
 use OpenILS::Utils::ScriptRunner;
 use OpenILS::Application::AppUtils;
+use DateTime::Format::ISO8601;
 use OpenILS::Application::Circ::ScriptBuilder;
 use OpenSRF::Utils::Logger qw(:logger);
+use OpenILS::Event;
 my $U  = "OpenILS::Application::AppUtils";
 
 my $script;                    # - the permit script
@@ -19,22 +21,26 @@ my $script_libs;    # - extra script libs
 # requestor, request_lib, title, title_descriptor
 sub permit_copy_hold {
        my $params      = shift;
+       my @allevents;
 
-       my $runner = OpenILS::Application::Circ::ScriptBuilder->build(
-               {
-                       patron_id       => $$params{patron_id},
-                       patron          => $$params{patron},
-                       copy                    => $$params{copy},
-                       requestor       => $$params{requestor},
-                       title                   => $$params{title},
-                       volume          => $$params{volume},
-                       flesh_age_protect => 1,
-                       _direct => {
-                               requestLib      => $$params{request_lib},
-                               pickupLib       => $$params{pickup_lib},
-                       }
+       my $ctx = {
+               patron_id       => $$params{patron_id},
+               patron          => $$params{patron},
+               copy                    => $$params{copy},
+               requestor       => $$params{requestor},
+               title                   => $$params{title},
+               volume          => $$params{volume},
+               flesh_age_protect => 1,
+               _direct => {
+                       requestLib      => $$params{request_lib},
+                       pickupLib       => $$params{pickup_lib},
                }
-       );
+       };
+
+       my $runner = OpenILS::Application::Circ::ScriptBuilder->build($ctx);
+
+       my $evt = check_age_protect($ctx->{patron}, $ctx->{copy});
+       push( @allevents, $evt ) if $evt;
 
        $logger->debug("Running permit_copy_hold on copy " . $$params{copy}->id);
 
@@ -51,7 +57,6 @@ sub permit_copy_hold {
        my $pid = ($params->{patron}) ? $params->{patron}->id : $params->{patron_id};
        $logger->debug("circ_permit_hold for user $pid returned events: [@$events]");
 
-       my @allevents;
        push( @allevents, OpenILS::Event->new($_)) for @$events;
        my %hash = map { ($_->{ilsevent} => $_) } @allevents;
        @allevents = values %hash;
@@ -78,5 +83,43 @@ sub load_scripts {
 }
 
 
+sub check_age_protect {
+       my( $patron, $copy ) = @_;
+
+       return undef unless $copy->age_protect;
+
+       my $prox = $U->storagereq(
+               'open-ils.storage.asset.copy.proximity', 
+               $copy->id, $patron->home_ou->id );
+
+       # If this copy is within the appropriate proximity, 
+       # age protect does not apply
+       return undef if $prox <= $copy->age_protect->prox;
+
+       # How many seconds old does the copy have to be to escape age protection
+       my $interval = OpenSRF::Utils::interval_to_seconds($copy->age_protect->age);
+       my $start_date = time - $interval;
+
+       # Now, now many seconds old is this copy
+       my $dparser = DateTime::Format::ISO8601->new;
+       my $create_date = $dparser->parse_datetime(
+               OpenSRF::Utils::clense_ISO8601($copy->create_date));
+       my $age = $create_date->epoch;
+
+       $logger->debug("age_protect create_date = $create_date : age=$age, start_date=$start_date");
+
+       unless( $start_date < $age ) {
+               $logger->info("age_protect prevents copy from having a hold placed on it: ".$copy->id);
+               return OpenILS::Event->new('ITEM_AGE_PROTECTED', copy => $copy->id );
+       }
+
+       return undef;
+}
+
+
+
+
+
+
 
 23;
index 8f28e5c..c145dd2 100644 (file)
@@ -914,3 +914,14 @@ function parseForm(form) {
 
 function isTrue(x) { return ( x && x != "0" && !x.match(/^f$/i) ); }
 
+function fetchPermOrgs() {
+       var a = []; /* why does arguments come accross as an object and not an array? */
+       for( var i = 0; i < arguments.length; i++ ) 
+               a.push(arguments[i])
+
+       var preq = new Request(FETCH_HIGHEST_PERM_ORG, 
+               G.user.session, G.user.id(), a );
+       preq.send(true);
+       return preq.result();
+}
+
index 9b5a6ba..c1a8587 100644 (file)
@@ -688,23 +688,17 @@ function holdProcessResult( hold, res, recurse ) {
                }
 
                if( grep(res, function(e) { return (e.textcode == 'HOLD_EXISTS'); }) ) {
-
-                       /* see if the requestor has the ability to create duplicate holds */
-                       var preq = new Request(FETCH_HIGHEST_PERM_ORG, 
-                               G.user.session, G.user.id(), ['CREATE_DUPLICATE_HOLDS']);
-                       preq.send(true);
-                       var org = preq.result()[0];
-
-                       if( org ) {
+                       if( fetchPermOrgs('HOLD_EXISTS')[0] ) {
                                if( confirm($('hold_dup_exists_override').innerHTML) ) {
-                                       holdsPlaceHold(hold, true);
+                                       return holdsPlaceHold(hold, true);
                                }
 
                        } else {
-                               alert($('hold_dup_exists').innerHTML);
-                               return;
+                               return alert($('hold_dup_exists').innerHTML);
                        }
                }
+
+               alert($('holds_failure').innerHTML);
        }
 }
 
index d25de49..9ccdb3d 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.
+                       It's possible that choosing a different format will result in a successful hold.
+                       Otherwise, please consult your local librarian.
                </span>
 
        </div>
                Please see any notes in the "Staff Notes" section of your "My Account" page or contact your local library.
        </span>
 
-
-
 </div>