From f078103e33093731a9dd50d20340279accd0d269 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Tue, 29 Mar 2011 15:46:29 +1300 Subject: [PATCH] Bug 5984 : Allowing the librarians to hide items in the Opac using a system preference Squashed commit of the following: commit 72b578928b287ba3b5fa8965e42ff1ccbdf9013a Author: Matthias Meusburger Date: Wed Oct 20 11:26:46 2010 +0200 Bug 5984 : MT4587, Follow-up: Hiding rules are now in a syspref commit d95329955f976900afdafa82fe0a1699e8e892dc Author: Matthias Meusburger Date: Tue Oct 19 15:19:16 2010 +0200 Bug 5984 : MT4587, Follow-up: Adds yaml config file for custom opac items hiding commit 6777c1a97700b77095e4e499ca73040bf94271e2 Author: Matthias Meusburger Date: Mon Oct 18 11:14:03 2010 +0200 Bug 5984 : MT4587 : Adds yaml config file for custom opac items hiding Signed-off-by: Claire Hernandez Signed-off-by: Chris Cormack --- C4/Items.pm | 53 +++++++++++++++++++ C4/Search.pm | 25 ++++++--- docs/opac/OpacHiddenItems.txt | 12 +++++ installer/data/mysql/updatedatabase.pl | 8 +++ .../prog/en/modules/opac-results.tmpl | 3 +- opac/opac-detail.pl | 22 ++++++-- 6 files changed, 110 insertions(+), 13 deletions(-) create mode 100644 docs/opac/OpacHiddenItems.txt diff --git a/C4/Items.pm b/C4/Items.pm index 939e68241b..01509c2974 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -33,6 +33,7 @@ use C4::Branch; require C4::Reserves; use C4::Charset; use C4::Acquisition; +use List::MoreUtils qw/any/; use vars qw($VERSION @ISA @EXPORT); @@ -69,6 +70,7 @@ BEGIN { get_itemnumbers_of GetItemnumberFromBarcode GetBarcodeFromItemnumber + GetHiddenItemnumbers DelItemCheck MoveItemFromBiblio @@ -1534,6 +1536,57 @@ sub GetBarcodeFromItemnumber { return ($result); } +=head2 GetHiddenItemnumbers + +=over 4 + +$result = GetHiddenItemnumbers(@items); + +=back + +=cut + +sub GetHiddenItemnumbers { + my (@items) = @_; + my @resultitems; + + my $yaml = C4::Context->preference('OpacHiddenItems'); + my $hidingrules; + eval { + $hidingrules = YAML::Load($yaml); + }; + if ($@) { + warn "Unable to parse OpacHiddenItems syspref : $@"; + return (); + } else { + my $dbh = C4::Context->dbh; + + # For each item + foreach my $item (@items) { + + # We check each rule + foreach my $field (keys %$hidingrules) { + my $query = "SELECT $field from items where itemnumber = ?"; + my $sth = $dbh->prepare($query); + $sth->execute($item->{'itemnumber'}); + my ($result) = $sth->fetchrow; + + # If the results matches the values in the yaml file + if (any { $result eq $_ } @{$hidingrules->{$field}}) { + + # We add the itemnumber to the list + push @resultitems, $item->{'itemnumber'}; + + # If at least one rule matched for an item, no need to test the others + last; + } + } + } + return @resultitems; + } + + } + =head3 get_item_authorised_values find the types and values for all authorised values assigned to this item. diff --git a/C4/Search.pm b/C4/Search.pm index a19a5b7e44..a8d6625a05 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -30,6 +30,8 @@ use C4::XSLT; use C4::Branch; use C4::Reserves; # CheckReserves use C4::Debug; +use C4::Items; +use YAML; use URI::Escape; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); @@ -1594,8 +1596,14 @@ sub searchResults { $item->{$code} = $field->subfield( $subfieldstosearch{$code} ); } - my $hbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch' : 'holdingbranch'; - my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch'; + # Hidden items + my @items = ($item); + my (@hiddenitems) = GetHiddenItemnumbers(@items); + $item->{'hideatopac'} = 1 if (@hiddenitems); + + my $hbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch' : 'holdingbranch'; + my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch'; + # set item's branch name, use HomeOrHoldingBranch syspref first, fall back to the other one if ($item->{$hbranch}) { $item->{'branchname'} = $branches{$item->{$hbranch}}; @@ -1668,6 +1676,7 @@ sub searchResults { || $item->{itemlost} || $item->{damaged} || $item->{notforloan} > 0 + || $item->{hideatopac} || $reservestatus eq 'Waiting' || ($transfertwhen ne '')) { @@ -1679,11 +1688,11 @@ sub searchResults { $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan}; $other_count++; - my $key = $prefix . $item->{status}; - foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber)) { - $other_items->{$key}->{$_} = $item->{$_}; - } - $other_items->{$key}->{intransit} = ($transfertwhen ne '') ? 1 : 0; + my $key = $prefix . $item->{status}; + foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber hideatopac)) { + $other_items->{$key}->{$_} = $item->{$_}; + } + $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0; $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0; $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value; $other_items->{$key}->{count}++ if $item->{$hbranch}; @@ -1695,7 +1704,7 @@ sub searchResults { $can_place_holds = 1; $available_count++; $available_items->{$prefix}->{count}++ if $item->{$hbranch}; - foreach (qw(branchname itemcallnumber)) { + foreach (qw(branchname itemcallnumber hideatopac)) { $available_items->{$prefix}->{$_} = $item->{$_}; } $available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} }; diff --git a/docs/opac/OpacHiddenItems.txt b/docs/opac/OpacHiddenItems.txt new file mode 100644 index 0000000000..625d465d04 --- /dev/null +++ b/docs/opac/OpacHiddenItems.txt @@ -0,0 +1,12 @@ +The OpacHiddenItems syspref allow the user to define custom rules +for hiding specific items at opac. + +YAML syntax is used for defining such rules. + +Items can be hidden according to values from the items table: + +field: [value1, value2, ...] + +Example : +wthdrawn: [0, 1] +homebranch: [homebranch1, homebranch2] diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 7729a7ec4d..bac3a64f73 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4231,6 +4231,14 @@ $DBversion = '3.03.00.044'; if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { $dbh->do("ALTER TABLE `aqbasketgroups` ADD `freedeliveryplace` TEXT NULL AFTER `deliveryplace`;"); print "Upgrade to $DBversion done (adding freedeliveryplace to basketgroups)\n"; +} + +$DBversion = "3.03.00.045"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(" + INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHiddenItems','','This syspref allows to define custom rules for hiding specific items at opac. See docs/opac/OpacHiddenItems.txt for more informations.','','Textarea'); + "); + print "Upgrade to $DBversion done (Adding OpacHiddenItems syspref)\n"; SetVersion($DBversion); } diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl index 090490113c..c8b76b1013 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl @@ -440,7 +440,7 @@ $(document).ready(function(){ Copies available: - + @@ -452,6 +452,7 @@ $(document).ready(function(){ [">] (), + diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index f2308347a2..3e4c76ca33 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -44,6 +44,7 @@ use C4::ShelfBrowser; use C4::Charset; use MARC::Record; use MARC::Field; +use List::MoreUtils qw/any none/; BEGIN { if (C4::Context->preference('BakerTaylorEnabled')) { @@ -86,14 +87,27 @@ $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowChec # change back when ive fixed request.pl my @all_items = &GetItemsInfo( $biblionumber, 'opac' ); my @items; -@items = @all_items unless C4::Context->preference('hidelostitems'); -if (C4::Context->preference('hidelostitems')) { - # Hide host items +# Getting items to be hidden +my @hiddenitems = GetHiddenItemnumbers(@all_items); + +# Are there items to hide? +my $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0; + +# Hide items +if ($hideitems) { for my $itm (@all_items) { - push @items, $itm unless $itm->{itemlost}; + if ( C4::Context->preference('hidelostitems') ) { + push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems; + } else { + push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems; } } +} else { + # Or not + @items = @all_items; +} + my $dat = &GetBiblioData($biblionumber); my $itemtypes = GetItemTypes(); -- 2.39.5