3 # Copyright ByWater Solutions 2014
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
26 use Koha::CirculationRules;
28 use base qw(Koha::Objects);
30 use Koha::SearchEngine::Indexer;
34 Koha::Items - Koha Item object set class
42 =head3 filter_by_for_hold
44 my $filtered_items = $items->filter_by_for_hold;
46 Return the items of the set that are *potentially* holdable.
48 Caller has the responsibility to call C4::Reserves::CanItemBeReserved before
49 placing a hold on one of those items.
53 sub filter_by_for_hold {
56 my @hold_not_allowed_itypes = Koha::CirculationRules->search(
58 rule_name => 'holdallowed',
60 categorycode => undef,
61 rule_value => 'not_allowed',
63 )->get_column('itemtype');
64 push @hold_not_allowed_itypes, Koha::ItemTypes->search({ notforloan => 1 })->get_column('itemtype');
69 notforloan => { '<=' => 0 }, # items with negative or zero notforloan value are holdable
70 ( C4::Context->preference('AllowHoldsOnDamagedItems')? (): ( damaged => 0 ) ),
73 if ( C4::Context->preference("item-level_itypes") ) {
77 itype => { -not_in => \@hold_not_allowed_itypes },
84 'biblioitem.itemtype' => { -not_in => \@hold_not_allowed_itypes },
93 =head3 filter_by_visible_in_opac
95 my $filered_items = $items->filter_by_visible_in_opac(
101 Returns a new resultset, containing those items that are not expected to be hidden in OPAC
102 for the passed I<Koha::Patron> object that is passed.
104 The I<OpacHiddenItems>, I<hidelostitems> and I<OpacHiddenItemsExceptions> system preferences
109 sub filter_by_visible_in_opac {
110 my ($self, $params) = @_;
112 my $patron = $params->{patron};
116 # Filter out OpacHiddenItems unless disabled by OpacHiddenItemsExceptions
117 unless ( $patron and $patron->category->override_hidden_items ) {
118 my $rules = C4::Context->yaml_preference('OpacHiddenItems') // {};
121 foreach my $field ( keys %$rules ) {
122 $rules_params->{$field} =
123 [ { '-not_in' => $rules->{$field} }, undef ];
126 $result = $result->search( $rules_params );
129 if (C4::Context->preference('hidelostitems')) {
130 $result = $result->filter_out_lost;
136 =head3 filter_out_lost
138 my $filered_items = $items->filter_out_lost;
140 Returns a new resultset, containing those items that are not marked as lost.
144 sub filter_out_lost {
147 my $params = { itemlost => 0 };
149 return $self->search( $params );
152 =head3 move_to_biblio
154 $items->move_to_biblio($to_biblio);
156 Move items to a given biblio.
161 my ( $self, $to_biblio ) = @_;
163 my $biblionumbers = { $to_biblio->biblionumber => 1 };
164 while ( my $item = $self->next() ) {
165 $biblionumbers->{ $item->biblionumber } = 1;
166 $item->move_to_biblio( $to_biblio, { skip_record_index => 1 } );
168 my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
169 for my $biblionumber ( keys %{$biblionumbers} ) {
170 $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
175 =head2 Internal methods
195 Kyle M Hall <kyle@bywatersolutions.com>
196 Tomas Cohen Arazi <tomascohen@theke.io>
197 Martin Renvoize <martin.renvoize@ptfs-europe.com>