Squashed commit of the following:
commit
72b578928b287ba3b5fa8965e42ff1ccbdf9013a
Author: Matthias Meusburger <matthias.meusburger@biblibre.com>
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 <matthias.meusburger@biblibre.com>
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 <matthias.meusburger@biblibre.com>
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 <claire.hernandez@biblibre.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
require C4::Reserves;
use C4::Charset;
use C4::Acquisition;
+use List::MoreUtils qw/any/;
use vars qw($VERSION @ISA @EXPORT);
get_itemnumbers_of
GetItemnumberFromBarcode
GetBarcodeFromItemnumber
+ GetHiddenItemnumbers
DelItemCheck
MoveItemFromBiblio
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.
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);
$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}};
|| $item->{itemlost}
|| $item->{damaged}
|| $item->{notforloan} > 0
+ || $item->{hideatopac}
|| $reservestatus eq 'Waiting'
|| ($transfertwhen ne ''))
{
$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};
$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} };
--- /dev/null
+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]
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);
}
<!-- TMPL_IF NAME="available_items_loop" -->
<span class="available"><strong>Copies available:</strong>
<!-- TMPL_LOOP NAME="available_items_loop" -->
-
+ <!-- TMPL_UNLESS NAME="hideatopac" -->
<!-- TMPL_IF NAME="singleBranchMode" -->
<!-- TMPL_VAR NAME="location" -->
<!-- TMPL_ELSE -->
<!-- TMPL_IF NAME="itemcallnumber" -->[<a href="/cgi-bin/koha/opac-search.pl?q=callnum:<!-- TMPL_VAR NAME="itemcallnumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="itemcallnumber" --></a>]<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
(<!-- TMPL_VAR NAME="count" -->),
+ <!-- /TMPL_UNLESS -->
<!-- /TMPL_LOOP -->
</span>
<!-- TMPL_ELSE -->
use C4::Charset;
use MARC::Record;
use MARC::Field;
+use List::MoreUtils qw/any none/;
BEGIN {
if (C4::Context->preference('BakerTaylorEnabled')) {
# 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();