View | Details | Raw Unified | Return to bug 5984
Collapse All | Expand All

(-)a/C4/Items.pm (+53 lines)
Lines 33-38 use C4::Branch; Link Here
33
require C4::Reserves;
33
require C4::Reserves;
34
use C4::Charset;
34
use C4::Charset;
35
use C4::Acquisition;
35
use C4::Acquisition;
36
use List::MoreUtils qw/any/;
36
37
37
use vars qw($VERSION @ISA @EXPORT);
38
use vars qw($VERSION @ISA @EXPORT);
38
39
Lines 68-73 BEGIN { Link Here
68
        get_itemnumbers_of
69
        get_itemnumbers_of
69
        GetItemnumberFromBarcode
70
        GetItemnumberFromBarcode
70
        GetBarcodeFromItemnumber
71
        GetBarcodeFromItemnumber
72
      GetHiddenItemnumbers
71
73
72
		DelItemCheck
74
		DelItemCheck
73
		MoveItemFromBiblio 
75
		MoveItemFromBiblio 
Lines 1467-1472 sub GetBarcodeFromItemnumber { Link Here
1467
    return ($result);
1469
    return ($result);
1468
}
1470
}
1469
1471
1472
=head2 GetHiddenItemnumbers
1473
1474
=over 4
1475
1476
$result = GetHiddenItemnumbers(@items);
1477
1478
=back
1479
1480
=cut
1481
1482
sub GetHiddenItemnumbers {
1483
    my (@items) = @_;
1484
    my @resultitems;
1485
1486
    my $yaml = C4::Context->preference('OpacHiddenItems');
1487
    my $hidingrules;
1488
    eval {
1489
    	$hidingrules = YAML::Load($yaml);
1490
    };
1491
    if ($@) {
1492
    	warn "Unable to parse OpacHiddenItems syspref : $@";
1493
    	return ();
1494
    } else {
1495
    my $dbh = C4::Context->dbh;
1496
1497
	# For each item
1498
	foreach my $item (@items) {
1499
1500
	    # We check each rule
1501
	    foreach my $field (keys %$hidingrules) {
1502
		my $query = "SELECT $field from items where itemnumber = ?";
1503
		my $sth = $dbh->prepare($query);	
1504
		$sth->execute($item->{'itemnumber'});
1505
		my ($result) = $sth->fetchrow;
1506
1507
		# If the results matches the values in the yaml file
1508
		if (any { $result eq $_ } @{$hidingrules->{$field}}) {
1509
1510
		    # We add the itemnumber to the list
1511
		    push @resultitems, $item->{'itemnumber'};	    
1512
1513
		    # If at least one rule matched for an item, no need to test the others
1514
		    last;
1515
		}
1516
	    }
1517
	}
1518
	return @resultitems;
1519
    }
1520
1521
 }
1522
1470
=head3 get_item_authorised_values
1523
=head3 get_item_authorised_values
1471
1524
1472
find the types and values for all authorised values assigned to this item.
1525
find the types and values for all authorised values assigned to this item.
(-)a/C4/Search.pm (-8 / +17 lines)
Lines 29-34 use C4::XSLT; Link Here
29
use C4::Branch;
29
use C4::Branch;
30
use C4::Reserves;    # CheckReserves
30
use C4::Reserves;    # CheckReserves
31
use C4::Debug;
31
use C4::Debug;
32
use C4::Items;
33
use YAML;
32
use URI::Escape;
34
use URI::Escape;
33
35
34
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
36
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
Lines 1581-1588 sub searchResults { Link Here
1581
                $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
1583
                $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
1582
            }
1584
            }
1583
1585
1584
			my $hbranch     = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch'    : 'holdingbranch';
1586
	        # Hidden items
1585
			my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch';
1587
	        my @items = ($item);
1588
	        my (@hiddenitems) = GetHiddenItemnumbers(@items);
1589
    	    $item->{'hideatopac'} = 1 if (@hiddenitems); 
1590
1591
            my $hbranch     = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch'    : 'holdingbranch';
1592
            my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch';
1593
1586
            # set item's branch name, use HomeOrHoldingBranch syspref first, fall back to the other one
1594
            # set item's branch name, use HomeOrHoldingBranch syspref first, fall back to the other one
1587
            if ($item->{$hbranch}) {
1595
            if ($item->{$hbranch}) {
1588
                $item->{'branchname'} = $branches{$item->{$hbranch}};
1596
                $item->{'branchname'} = $branches{$item->{$hbranch}};
Lines 1654-1659 sub searchResults { Link Here
1654
                    || $item->{itemlost}
1662
                    || $item->{itemlost}
1655
                    || $item->{damaged}
1663
                    || $item->{damaged}
1656
                    || $item->{notforloan} > 0
1664
                    || $item->{notforloan} > 0
1665
                    || $item->{hideatopac}
1657
		    || $reservestatus eq 'Waiting'
1666
		    || $reservestatus eq 'Waiting'
1658
                    || ($transfertwhen ne ''))
1667
                    || ($transfertwhen ne ''))
1659
                {
1668
                {
Lines 1665-1675 sub searchResults { Link Here
1665
                    $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
1674
                    $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
1666
                    $other_count++;
1675
                    $other_count++;
1667
1676
1668
					my $key = $prefix . $item->{status};
1677
                    my $key = $prefix . $item->{status};
1669
					foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber)) {
1678
                    foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber hideatopac)) {
1670
                    	$other_items->{$key}->{$_} = $item->{$_};
1679
                        $other_items->{$key}->{$_} = $item->{$_};
1671
					}
1680
                    }
1672
                    $other_items->{$key}->{intransit} = ($transfertwhen ne '') ? 1 : 0;
1681
                    $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0;
1673
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
1682
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
1674
					$other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value;
1683
					$other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value;
1675
					$other_items->{$key}->{count}++ if $item->{$hbranch};
1684
					$other_items->{$key}->{count}++ if $item->{$hbranch};
Lines 1681-1687 sub searchResults { Link Here
1681
                    $can_place_holds = 1;
1690
                    $can_place_holds = 1;
1682
                    $available_count++;
1691
                    $available_count++;
1683
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
1692
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
1684
					foreach (qw(branchname itemcallnumber)) {
1693
					foreach (qw(branchname itemcallnumber hideatopac)) {
1685
                    	$available_items->{$prefix}->{$_} = $item->{$_};
1694
                    	$available_items->{$prefix}->{$_} = $item->{$_};
1686
					}
1695
					}
1687
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
1696
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
(-)a/docs/opac/OpacHiddenItems.txt (+12 lines)
Line 0 Link Here
1
The OpacHiddenItems syspref allow the user to define custom rules
2
for hiding specific items at opac.
3
4
YAML syntax is used for defining such rules.
5
6
Items can be hidden according to values from the items table:
7
8
field: [value1, value2, ...]
9
10
Example :
11
wthdrawn: [0, 1]
12
homebranch: [homebranch1, homebranch2]
(-)a/installer/data/mysql/updatedatabase.pl (+9 lines)
Lines 4134-4139 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4134
    SetVersion ($DBversion);
4134
    SetVersion ($DBversion);
4135
}
4135
}
4136
4136
4137
$DBversion = "3.03.00.XXX";
4138
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4139
    $dbh->do("
4140
	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');
4141
	");
4142
    print "Upgrade to $DBversion done (Adding OpacHiddenItems syspref)\n";
4143
    SetVersion($DBversion);
4144
}
4145
4137
=head1 FUNCTIONS
4146
=head1 FUNCTIONS
4138
4147
4139
=head2 DropAllForeignKeys($table)
4148
=head2 DropAllForeignKeys($table)
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl (-1 / +2 lines)
Lines 431-437 $(document).ready(function(){ Link Here
431
                    <!-- TMPL_IF NAME="available_items_loop" -->
431
                    <!-- TMPL_IF NAME="available_items_loop" -->
432
                    <span class="available"><strong>Copies available:</strong>
432
                    <span class="available"><strong>Copies available:</strong>
433
                    <!-- TMPL_LOOP NAME="available_items_loop" -->
433
                    <!-- TMPL_LOOP NAME="available_items_loop" -->
434
434
                    <!-- TMPL_UNLESS NAME="hideatopac" -->
435
                    <!-- TMPL_IF NAME="singleBranchMode" -->
435
                    <!-- TMPL_IF NAME="singleBranchMode" -->
436
                        <!-- TMPL_VAR NAME="location" -->
436
                        <!-- TMPL_VAR NAME="location" -->
437
                    <!-- TMPL_ELSE -->
437
                    <!-- TMPL_ELSE -->
Lines 443-448 $(document).ready(function(){ Link Here
443
                        <!-- 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 -->
443
                        <!-- 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 -->
444
                    <!-- /TMPL_IF -->
444
                    <!-- /TMPL_IF -->
445
                    (<!-- TMPL_VAR NAME="count" -->),
445
                    (<!-- TMPL_VAR NAME="count" -->),
446
                    <!-- /TMPL_UNLESS -->
446
                    <!-- /TMPL_LOOP -->
447
                    <!-- /TMPL_LOOP -->
447
                    </span>
448
                    </span>
448
                    <!-- TMPL_ELSE -->
449
                    <!-- TMPL_ELSE -->
(-)a/opac/opac-detail.pl (-5 / +18 lines)
Lines 41-46 use C4::Members; Link Here
41
use C4::VirtualShelves;
41
use C4::VirtualShelves;
42
use C4::XSLT;
42
use C4::XSLT;
43
use C4::ShelfBrowser;
43
use C4::ShelfBrowser;
44
use List::MoreUtils qw/any none/;
44
45
45
BEGIN {
46
BEGIN {
46
	if (C4::Context->preference('BakerTaylorEnabled')) {
47
	if (C4::Context->preference('BakerTaylorEnabled')) {
Lines 80-93 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowChec Link Here
80
# change back when ive fixed request.pl
81
# change back when ive fixed request.pl
81
my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
82
my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
82
my @items;
83
my @items;
83
@items = @all_items unless C4::Context->preference('hidelostitems');
84
84
85
if (C4::Context->preference('hidelostitems')) {
85
# Getting items to be hidden
86
    # Hide host items
86
my @hiddenitems = GetHiddenItemnumbers(@all_items);
87
88
# Are there items to hide?
89
my $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
90
91
# Hide items
92
if ($hideitems) {
87
    for my $itm (@all_items) {
93
    for my $itm (@all_items) {
88
        push @items, $itm unless $itm->{itemlost};
94
	if  ( C4::Context->preference('hidelostitems') ) {
95
	    push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
96
	} else {
97
	    push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
89
    }
98
    }
90
}
99
}
100
} else {
101
    # Or not
102
    @items = @all_items;
103
}
104
91
my $dat = &GetBiblioData($biblionumber);
105
my $dat = &GetBiblioData($biblionumber);
92
106
93
my $itemtypes = GetItemTypes();
107
my $itemtypes = GetItemTypes();
94
- 

Return to bug 5984