@@ -, +, @@ conditions --- 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 --- a/C4/Reserves.pm +++ a/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 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/mandatory-hold-notes.tt +++ a/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. --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ a/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: - --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt +++ a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt @@ -4,9 +4,13 @@