From: erickson Date: Thu, 3 Aug 2006 15:29:48 +0000 (+0000) Subject: added age-protect logic to the hold permit code X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=534f867866fe94731680c2db691726d89252292c;p=Evergreen.git added age-protect logic to the hold permit code git-svn-id: svn://svn.open-ils.org/ILS/trunk@5246 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index d4f28bcdb6..5df39b6562 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -100,6 +100,9 @@ This account is marked as inactive + + This item is too new to have a hold placed on it + diff --git a/Open-ILS/src/javascript/backend/circ/circ_permit_hold.js b/Open-ILS/src/javascript/backend/circ/circ_permit_hold.js index e5c61cf877..d0ca4085a2 100644 --- a/Open-ILS/src/javascript/backend/circ/circ_permit_hold.js +++ b/Open-ILS/src/javascript/backend/circ/circ_permit_hold.js @@ -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(); diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm b/Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm index 285e756a24..95e054721c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm @@ -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; diff --git a/Open-ILS/web/opac/common/js/opac_utils.js b/Open-ILS/web/opac/common/js/opac_utils.js index 8f28e5cb9d..c145dd2cd5 100644 --- a/Open-ILS/web/opac/common/js/opac_utils.js +++ b/Open-ILS/web/opac/common/js/opac_utils.js @@ -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(); +} + diff --git a/Open-ILS/web/opac/skin/default/js/holds.js b/Open-ILS/web/opac/skin/default/js/holds.js index 9b5a6ba60e..c1a8587d73 100644 --- a/Open-ILS/web/opac/skin/default/js/holds.js +++ b/Open-ILS/web/opac/skin/default/js/holds.js @@ -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); } } diff --git a/Open-ILS/web/opac/skin/default/xml/common/holds.xml b/Open-ILS/web/opac/skin/default/xml/common/holds.xml index d25de49942..9ccdb3d31a 100644 --- a/Open-ILS/web/opac/skin/default/xml/common/holds.xml +++ b/Open-ILS/web/opac/skin/default/xml/common/holds.xml @@ -164,8 +164,8 @@ 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. @@ -198,8 +198,6 @@ Please see any notes in the "Staff Notes" section of your "My Account" page or contact your local library. - -