From 4567e4df629e3c0ab00d8a53c16d33361e1a5ce1 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 15 Dec 2014 14:10:56 +0100 Subject: [PATCH] Bug 15545: Optionally require notes when placing a hold Content-Type: text/plain; charset=utf-8 This report adds three cases where you could want to require a note when placing a hold. Each of these cases may be enabled separately via the system preference HoldNoteReasons. (The hold note itself is triggered by OpacHoldNotes.) These three cases are: [1] serial indication in the leader (called LEADER_SERIAL) [2] collection indication in the leader (LEADER_COLLECTION) [3] MARC 300$a contains an indication of multiple parts/volumes, as identified by a regular expression (MARC300A_PARTS). The new sub IsHoldNoteRequired in Reserves.pm handles these cases. And will be easily extensible. Also this patch removes some unused code in the reserves template for mandatory hold notes reasons. Test plan: [1] Enable OpacHoldNotes. Set HoldNoteReasons to LEADER_SERIAL. [2] In OPAC, place a hold on a serial record (with correct leader). Verify that the hold notes are required. [3] Set HoldNoteReasons to MARC300A_PARTS. Verify that the hold notes are no longer required for the record in the preceding step. (This actually depends on your 300$a..) Cancel the hold you placed. [4] Add "2 vols" to MARC 300$a in the same record. Try to place the hold again. The hold notes should be required again. [5] Place a multiple hold request with the same record and another one. Click Place Hold while more-options is collapsed (blank notes). Is the correct hold note made visible? --- C4/Reserves.pm | 44 +++++++++++++++++++- .../opac-tmpl/bootstrap/en/modules/opac-reserve.tt | 36 ++++++++-------- opac/opac-reserve.pl | 2 +- 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 7bb5d69..75d3c43 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -142,7 +142,7 @@ BEGIN { IsItemOnHoldAndFound ); - @EXPORT_OK = qw( MergeHolds ); + @EXPORT_OK = qw( MergeHolds IsHoldNoteRequired ); } =head2 AddReserve @@ -2471,6 +2471,48 @@ sub IsItemOnHoldAndFound { return $found; } +=head2 IsHoldNoteRequired + + my $boolean = IsHoldNoteRequired( $marc ); + + Checks if a hold note is required for a given record. + Triggered by the pref HoldNoteReasons. + This pref may contain a list of reason codes to be checked. + So, it could look like: LEADER_SERIAL|MARC300A_PARTS + + This routine returns true if the note is required, undef otherwise. + +=cut + +sub IsHoldNoteRequired { + my ( $marcrecord ) = @_; + return if !$marcrecord || !C4::Context->preference( 'OPACHoldNotes' ); + my $reasons = uc C4::Context->preference( 'HoldNoteReasons' ); + return if !$reasons; + my $ldr = $marcrecord->leader; + + # check LEADER_SERIAL + if( $reasons =~ /LEADER_SERIAL/ && substr($ldr,7,1) eq 's' ) { + return 1; + } + # check LEADER_COLLECTION + if( $reasons =~ /LEADER_COLLECTION/ && substr($ldr,7,1) eq 'c' ) { + return 1; + } + # check MARC300A_PARTS + if( $reasons =~ /MARC300A_PARTS/ && + ( my @fld = $marcrecord->field('300') )) { + my $re = qr/(\d+)\s*(v\.|vol|dl|delen|band|bd|tle|parts|pts|t\.|tome)/i; + foreach my $f ( @fld ) { + next if !$f->subfield('a'); + # Check for something like 3 parts or 22 volumes in 300$a + return 1 if $f->subfield('a') =~ /$re/ && $1 > 1; + } + } + # next reason comes here.. + return; +} + =head1 AUTHOR Koha Development Team diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt index ca35f76..27cf28c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt @@ -237,10 +237,11 @@ [% IF ( OpacHoldNotes ) %]
  • - - - - + + [% IF bibitemloo.reqholdnotes %] + Please enter additional information about the requested item: + [% END %] +
  • [% END # / IF OpacHoldNotes %] @@ -392,10 +393,6 @@