From b101b06bf8b53eecd681dfc95a0fdfffe5346134 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 28 Feb 2013 15:26:55 +0100 Subject: [PATCH] Bug 9743: Mandatory opac hold notes under specified conditions Content-Type: text/plain; charset="utf-8" Description: Adds a new preference OPACMandatoryHoldNotes controlling when hold notes are mandatory for opac users placing a hold. In this initial implementation four reasons for a mandatory hold are added: 1) MARC21 300$a contains a reference to multiple volumes/parts 2) Biblio has one item (used in combination with 1) 3) UNIMARC 200$a contains the word test (for testing purposes only) 4) MARC21 leader pos 7 is collection A new file is added to describe the use of this pref. The opac preferences form shows a link to that file. Test plan: 1) Enable OPACShowHoldNotes. 2) Enter 1&2,4 into OPACMandatoryHoldNotes (for MARC21 testing). For UNIMARC, you could use 3. 3) Change two biblios: one with leader 7==c and one with 1 item and 300a==2 v. For UNIMARC, you could add the word test to 200$a. 4) Place a hold in opac on these two books separately. Just verify if the hold notes display the reason for mandatory notes. Do not place the holds. Test if you can place a hold if the notes are empty. You should not be allowed to do so. 5) Enable DisplayMultiPlaceHold. Place hold on both books simultaneously. Verify if you see both reasons for mandatory notes. Place the holds. Check them in staff. --- C4/Reserves.pm | 71 ++++++++++++++++++++ .../prog/en/modules/admin/mandatory-hold-notes.tt | 18 +++++ .../prog/en/modules/admin/preferences/opac.pref | 4 + .../opac-tmpl/prog/en/modules/opac-reserve.tt | 25 ++++++- opac/opac-reserve.pl | 2 +- 5 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/mandatory-hold-notes.tt diff --git a/C4/Reserves.pm b/C4/Reserves.pm index a380bf0..54a6324 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2151,6 +2151,77 @@ sub ReserveSlip { ); } +=head2 GetMandatoryNoteReason + + my $reason= GetMandatoryNoteReason( $biblionumber, $marcrecord ) + + Returns an integer representing the reason for a mandatory holds note. + Returns zero if the note is not mandatory or OPACShowHoldNotes is disabled. + + The reasons are listed in the opac-reserve template. + +=cut + +sub GetMandatoryNoteReason { + my ($biblionumber, $marcrecord) = @_; + + my $mandatoryReasons= C4::Context->preference('OPACMandatoryHoldNotes'); + my $shownotes= C4::Context->preference('OPACShowHoldNotes'); + return 0 if !$mandatoryReasons || !$shownotes; + + my ($res,$first); + my @subexpr= split ',',$mandatoryReasons; + #contains a list of numbered reasons in the form of 1,3&4,2,5&4,6 + #meaning check 1, or 3 and 4, or 2, or 5 and 4, or 6 .. + #for a combined check 3&4, the firstmentioned reason (3) is returned + foreach my $expr (@subexpr) { + my @checks= split '&', $expr; + $first=0; + foreach my $check (@checks) { + next if $check!~/(\d+)/; + $first=$1 if !$first; + $res= _CheckReason($biblionumber, $marcrecord, $1); + last if !$res; + } + return $first if $res; + } + return 0; #nothing found to justify a mandatory note +} + +sub _CheckReason { +#Returns false if the condition is not met or an error occurred + my ($biblionumber, $marcrecord, $check)= @_; + + if($check==1) { #MARC21: 300a contains ref to multiple parts/volumes + if(my $f=$marcrecord->field('300') ) { + if($f->subfield('a') && $f->subfield('a')=~ /(\d+)\s*(v\.|vol|dl|delen|bd|tle|parts|pts|t\.|tome)/i) { + #FIXME: Actually a cataloging language dependent test + return 1 if $1>1; + } + } + } + elsif($check==2) { #Number of items==1 + my $sql="select count(*) from items where biblionumber=?"; + my $dbh= C4::Context->dbh; + my @c=$dbh->selectrow_array($sql,undef,($biblionumber)); + return 1 if @c && $c[0]==1; + #if @c does not have rows, something went very wrong: return false + } + elsif($check==3) { #Added for UNIMARC testing: Title contains test + if(my $f=$marcrecord->field('200') ) { + if($f->subfield('a')) { + return 1 if $f->subfield('a')=~/test/i; + } + } + } + elsif($check==4) { #MARC21: Leader pos 07 equals c (collection) + if(my $ldr=$marcrecord->leader) { + return 1 if substr($ldr,7,1) eq 'c'; + } + } + return 0; +} + =head1 AUTHOR Koha Development Team diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/mandatory-hold-notes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/mandatory-hold-notes.tt new file mode 100644 index 0000000..568ef83 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/mandatory-hold-notes.tt @@ -0,0 +1,18 @@ +The following reasons can be used: + +1) MARC21 300$a contains a term indicating multiple volumes or parts (like v. or vol or pts). +2) The biblio record only has one item. This reason is only meant for use in combination with another reason like number 1. +3) UNIMARC 200$a contains the word 'test'. Added for test purposes. +4) MARC21 leader position 7 contains c for collection. + +How do you specify the reasons you want to use? +Just add them in your preferred order between commas in preference OPACMandatoryHoldNotes. +When you want to include an additional subcondition like number 2, use an expression like 1&2 indicating that you check for 1 AND 2. +So, as an example, you could write 4,1&2,3 meaning check reason 4 first, then check on 1 and 2, and finally check 3. + +For developers: How do you add a mandatory hold notes reason? +1) Pick the next free number from opac-reserves.tt: add an entry to the ForceHoldNotesReasons array. +2) Add your new reason to this documentation file: koha-tmpl/intranet-tmpl/prog/en/modules/admin/mandatory-hold-notes.tt. +3) Add the code for this reason to sub _CheckReason in Reserves.pm. +4) Submit a patch! +5) Edit pref OPACMandatoryHoldNotes and add the new number. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 4f10e68..31bf382 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -492,6 +492,10 @@ OPAC: no: "Don't allow" yes: Allow - opac users to share private lists with other patrons. This feature is not active yet but will be released soon + - + - You can specify which conditions make hold notes mandatory. This pref is only active when OPACShowHoldNotes is enabled. For more information, click here. + - pref: OPACMandatoryHoldNotes + type: textarea Privacy: - diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt index f5feb29..45c88a8 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt @@ -4,9 +4,13 @@