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 69-74 BEGIN { Link Here
69
        get_itemnumbers_of
70
        get_itemnumbers_of
70
        GetItemnumberFromBarcode
71
        GetItemnumberFromBarcode
71
        GetBarcodeFromItemnumber
72
        GetBarcodeFromItemnumber
73
      GetHiddenItemnumbers
72
74
73
		DelItemCheck
75
		DelItemCheck
74
		MoveItemFromBiblio 
76
		MoveItemFromBiblio 
Lines 1534-1539 sub GetBarcodeFromItemnumber { Link Here
1534
    return ($result);
1536
    return ($result);
1535
}
1537
}
1536
1538
1539
=head2 GetHiddenItemnumbers
1540
1541
=over 4
1542
1543
$result = GetHiddenItemnumbers(@items);
1544
1545
=back
1546
1547
=cut
1548
1549
sub GetHiddenItemnumbers {
1550
    my (@items) = @_;
1551
    my @resultitems;
1552
1553
    my $yaml = C4::Context->preference('OpacHiddenItems');
1554
    my $hidingrules;
1555
    eval {
1556
    	$hidingrules = YAML::Load($yaml);
1557
    };
1558
    if ($@) {
1559
    	warn "Unable to parse OpacHiddenItems syspref : $@";
1560
    	return ();
1561
    } else {
1562
    my $dbh = C4::Context->dbh;
1563
1564
	# For each item
1565
	foreach my $item (@items) {
1566
1567
	    # We check each rule
1568
	    foreach my $field (keys %$hidingrules) {
1569
		my $query = "SELECT $field from items where itemnumber = ?";
1570
		my $sth = $dbh->prepare($query);	
1571
		$sth->execute($item->{'itemnumber'});
1572
		my ($result) = $sth->fetchrow;
1573
1574
		# If the results matches the values in the yaml file
1575
		if (any { $result eq $_ } @{$hidingrules->{$field}}) {
1576
1577
		    # We add the itemnumber to the list
1578
		    push @resultitems, $item->{'itemnumber'};	    
1579
1580
		    # If at least one rule matched for an item, no need to test the others
1581
		    last;
1582
		}
1583
	    }
1584
	}
1585
	return @resultitems;
1586
    }
1587
1588
 }
1589
1537
=head3 get_item_authorised_values
1590
=head3 get_item_authorised_values
1538
1591
1539
find the types and values for all authorised values assigned to this item.
1592
find the types and values for all authorised values assigned to this item.
(-)a/C4/Search.pm (-8 / +17 lines)
Lines 30-35 use C4::XSLT; Link Here
30
use C4::Branch;
30
use C4::Branch;
31
use C4::Reserves;    # CheckReserves
31
use C4::Reserves;    # CheckReserves
32
use C4::Debug;
32
use C4::Debug;
33
use C4::Items;
34
use YAML;
33
use URI::Escape;
35
use URI::Escape;
34
36
35
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
37
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
Lines 1584-1591 sub searchResults { Link Here
1584
                $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
1586
                $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
1585
            }
1587
            }
1586
1588
1587
			my $hbranch     = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch'    : 'holdingbranch';
1589
	        # Hidden items
1588
			my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch';
1590
	        my @items = ($item);
1591
	        my (@hiddenitems) = GetHiddenItemnumbers(@items);
1592
    	    $item->{'hideatopac'} = 1 if (@hiddenitems); 
1593
1594
            my $hbranch     = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch'    : 'holdingbranch';
1595
            my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch';
1596
1589
            # set item's branch name, use HomeOrHoldingBranch syspref first, fall back to the other one
1597
            # set item's branch name, use HomeOrHoldingBranch syspref first, fall back to the other one
1590
            if ($item->{$hbranch}) {
1598
            if ($item->{$hbranch}) {
1591
                $item->{'branchname'} = $branches{$item->{$hbranch}};
1599
                $item->{'branchname'} = $branches{$item->{$hbranch}};
Lines 1658-1663 sub searchResults { Link Here
1658
                    || $item->{itemlost}
1666
                    || $item->{itemlost}
1659
                    || $item->{damaged}
1667
                    || $item->{damaged}
1660
                    || $item->{notforloan} > 0
1668
                    || $item->{notforloan} > 0
1669
                    || $item->{hideatopac}
1661
		    || $reservestatus eq 'Waiting'
1670
		    || $reservestatus eq 'Waiting'
1662
                    || ($transfertwhen ne ''))
1671
                    || ($transfertwhen ne ''))
1663
                {
1672
                {
Lines 1669-1679 sub searchResults { Link Here
1669
                    $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
1678
                    $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
1670
                    $other_count++;
1679
                    $other_count++;
1671
1680
1672
					my $key = $prefix . $item->{status};
1681
                    my $key = $prefix . $item->{status};
1673
					foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber)) {
1682
                    foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber hideatopac)) {
1674
                    	$other_items->{$key}->{$_} = $item->{$_};
1683
                        $other_items->{$key}->{$_} = $item->{$_};
1675
					}
1684
                    }
1676
                    $other_items->{$key}->{intransit} = ($transfertwhen ne '') ? 1 : 0;
1685
                    $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0;
1677
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
1686
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
1678
					$other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value;
1687
					$other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value;
1679
					$other_items->{$key}->{count}++ if $item->{$hbranch};
1688
					$other_items->{$key}->{count}++ if $item->{$hbranch};
Lines 1685-1691 sub searchResults { Link Here
1685
                    $can_place_holds = 1;
1694
                    $can_place_holds = 1;
1686
                    $available_count++;
1695
                    $available_count++;
1687
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
1696
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
1688
					foreach (qw(branchname itemcallnumber)) {
1697
					foreach (qw(branchname itemcallnumber hideatopac)) {
1689
                    	$available_items->{$prefix}->{$_} = $item->{$_};
1698
                    	$available_items->{$prefix}->{$_} = $item->{$_};
1690
					}
1699
					}
1691
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
1700
					$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 (+8 lines)
Lines 4231-4236 $DBversion = '3.03.00.044'; Link Here
4231
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4231
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4232
    $dbh->do("ALTER TABLE `aqbasketgroups` ADD `freedeliveryplace` TEXT NULL AFTER `deliveryplace`;");
4232
    $dbh->do("ALTER TABLE `aqbasketgroups` ADD `freedeliveryplace` TEXT NULL AFTER `deliveryplace`;");
4233
    print "Upgrade to $DBversion done (adding freedeliveryplace to basketgroups)\n";
4233
    print "Upgrade to $DBversion done (adding freedeliveryplace to basketgroups)\n";
4234
}
4235
4236
$DBversion = "3.03.00.045";
4237
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4238
    $dbh->do("
4239
	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');
4240
	");
4241
    print "Upgrade to $DBversion done (Adding OpacHiddenItems syspref)\n";
4234
    SetVersion($DBversion);
4242
    SetVersion($DBversion);
4235
}
4243
}
4236
4244
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl (-1 / +2 lines)
Lines 440-446 $(document).ready(function(){ Link Here
440
                    <!-- TMPL_IF NAME="available_items_loop" -->
440
                    <!-- TMPL_IF NAME="available_items_loop" -->
441
                    <span class="available"><strong>Copies available:</strong>
441
                    <span class="available"><strong>Copies available:</strong>
442
                    <!-- TMPL_LOOP NAME="available_items_loop" -->
442
                    <!-- TMPL_LOOP NAME="available_items_loop" -->
443
443
                    <!-- TMPL_UNLESS NAME="hideatopac" -->
444
                    <!-- TMPL_IF NAME="singleBranchMode" -->
444
                    <!-- TMPL_IF NAME="singleBranchMode" -->
445
                        <!-- TMPL_VAR NAME="location" -->
445
                        <!-- TMPL_VAR NAME="location" -->
446
                    <!-- TMPL_ELSE -->
446
                    <!-- TMPL_ELSE -->
Lines 452-457 $(document).ready(function(){ Link Here
452
                        <!-- 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 -->
452
                        <!-- 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 -->
453
                    <!-- /TMPL_IF -->
453
                    <!-- /TMPL_IF -->
454
                    (<!-- TMPL_VAR NAME="count" -->),
454
                    (<!-- TMPL_VAR NAME="count" -->),
455
                    <!-- /TMPL_UNLESS -->
455
                    <!-- /TMPL_LOOP -->
456
                    <!-- /TMPL_LOOP -->
456
                    </span>
457
                    </span>
457
                    <!-- TMPL_ELSE -->
458
                    <!-- TMPL_ELSE -->
(-)a/opac/opac-detail.pl (-5 / +18 lines)
Lines 44-49 use C4::ShelfBrowser; Link Here
44
use C4::Charset;
44
use C4::Charset;
45
use MARC::Record;
45
use MARC::Record;
46
use MARC::Field;
46
use MARC::Field;
47
use List::MoreUtils qw/any none/;
47
48
48
BEGIN {
49
BEGIN {
49
	if (C4::Context->preference('BakerTaylorEnabled')) {
50
	if (C4::Context->preference('BakerTaylorEnabled')) {
Lines 86-99 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowChec Link Here
86
# change back when ive fixed request.pl
87
# change back when ive fixed request.pl
87
my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
88
my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
88
my @items;
89
my @items;
89
@items = @all_items unless C4::Context->preference('hidelostitems');
90
90
91
if (C4::Context->preference('hidelostitems')) {
91
# Getting items to be hidden
92
    # Hide host items
92
my @hiddenitems = GetHiddenItemnumbers(@all_items);
93
94
# Are there items to hide?
95
my $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
96
97
# Hide items
98
if ($hideitems) {
93
    for my $itm (@all_items) {
99
    for my $itm (@all_items) {
94
        push @items, $itm unless $itm->{itemlost};
100
	if  ( C4::Context->preference('hidelostitems') ) {
101
	    push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
102
	} else {
103
	    push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
95
    }
104
    }
96
}
105
}
106
} else {
107
    # Or not
108
    @items = @all_items;
109
}
110
97
my $dat = &GetBiblioData($biblionumber);
111
my $dat = &GetBiblioData($biblionumber);
98
112
99
my $itemtypes = GetItemTypes();
113
my $itemtypes = GetItemTypes();
100
- 

Return to bug 5984