Update release notes for 19.11.18 release
[koha.git] / Koha / Items.pm
1 package Koha::Items;
2
3 # Copyright ByWater Solutions 2014
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use Carp;
23
24 use Koha::Database;
25
26 use Koha::Item;
27
28 use base qw(Koha::Objects);
29
30 =head1 NAME
31
32 Koha::Items - Koha Item object set class
33
34 =head1 API
35
36 =head2 Class methods
37
38 =cut
39
40 =head3 filter_by_visible_in_opac
41
42     my $filered_items = $items->filter_by_visible_in_opac(
43         {
44             [ patron => $patron ]
45         }
46     );
47
48 Returns a new resultset, containing those items that are not expected to be hidden in OPAC
49 for the passed I<Koha::Patron> object that is passed.
50
51 The I<OpacHiddenItems>, I<hidelostitems> and I<OpacHiddenItemsExceptions> system preferences
52 are honoured.
53
54 =cut
55
56 sub filter_by_visible_in_opac {
57     my ($self, $params) = @_;
58
59     my $patron = $params->{patron};
60
61     my $result = $self;
62
63     # Filter out OpacHiddenItems unless disabled by OpacHiddenItemsExceptions
64     unless ( $patron and $patron->category->override_hidden_items ) {
65         my $rules = C4::Context->yaml_preference('OpacHiddenItems') // {};
66
67         my $rules_params;
68         foreach my $field ( keys %$rules ) {
69             $rules_params->{$field} =
70               [ { '-not_in' => $rules->{$field} }, undef ];
71         }
72
73         $result = $result->search( $rules_params );
74     }
75
76     if (C4::Context->preference('hidelostitems')) {
77         $result = $result->filter_out_lost;
78     }
79
80     return $result;
81 }
82
83 =head3 filter_out_lost
84
85     my $filered_items = $items->filter_out_lost;
86
87 Returns a new resultset, containing those items that are not marked as lost.
88
89 =cut
90
91 sub filter_out_lost {
92     my ($self) = @_;
93
94     my $params = { itemlost => 0 };
95
96     return $self->search( $params );
97 }
98
99 =head2 Internal methods
100
101 =head3 _type
102
103 =cut
104
105 sub _type {
106     return 'Item';
107 }
108
109 =head3 object_class
110
111 =cut
112
113 sub object_class {
114     return 'Koha::Item';
115 }
116
117 =head1 AUTHOR
118
119 Kyle M Hall <kyle@bywatersolutions.com>
120 Tomas Cohen Arazi <tomascohen@theke.io>
121 Martin Renvoize <martin.renvoize@ptfs-europe.com>
122
123 =cut
124
125 1;