1 package Koha::ItemType;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use C4::Koha qw( getitemtypeimagelocation );
24 use Koha::CirculationRules;
25 use Koha::Localizations;
27 use base qw(Koha::Object Koha::Object::Limit::Library);
29 my $cache = Koha::Caches->get_instance();
33 Koha::ItemType - Koha Item type Object class
43 ItemType specific store to ensure relevant caches are flushed on change
52 if ( !$self->in_storage ) {
55 my $self_from_storage = $self->get_from_storage;
56 $flush = 1 if ( $self_from_storage->description ne $self->description );
59 $self = $self->SUPER::store;
62 my $key = "itemtype:description:en";
63 $cache->clear_from_cache($key);
71 ItemType specific C<delete> to clear relevant caches on delete.
77 $cache->clear_from_cache('itemtype:description:en');
78 $self->SUPER::delete(@_);
86 my ( $self, $interface ) = @_;
87 return C4::Koha::getitemtypeimagelocation( $interface, $self->imageurl );
90 =head3 translated_description
94 sub translated_description {
95 my ( $self, $lang ) = @_;
96 if ( my $translated_description = eval { $self->get_column('translated_description') } ) {
98 # If the value has already been fetched (eg. from sarch_with_localization),
99 # do not search for it again
100 # Note: This is a bit hacky but should be fast
101 return $translated_description
102 ? $translated_description
103 : $self->description;
105 $lang ||= C4::Languages::getlanguage;
106 my $translated_description = Koha::Localizations->search(
108 code => $self->itemtype,
109 entity => 'itemtypes',
113 return $translated_description
114 ? $translated_description->translation
115 : $self->description;
118 =head3 translated_descriptions
122 sub translated_descriptions {
124 my @translated_descriptions = Koha::Localizations->search(
126 entity => 'itemtypes',
127 code => $self->itemtype,
134 translation => $_->translation,
136 } @translated_descriptions
140 =head3 can_be_deleted
142 my $can_be_deleted = Koha::ItemType->can_be_deleted();
144 Counts up the number of biblioitems and items with itemtype (code) and hands back the combined number of biblioitems and items with the itemtype
150 my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count;
151 my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count;
152 return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
155 =head3 may_article_request
157 Returns true if it is likely possible to make an article request for
159 Optional parameter: categorycode (for patron).
163 sub may_article_request {
164 my ( $self, $params ) = @_;
165 return q{} if !C4::Context->preference('ArticleRequests');
166 my $itemtype = $self->itemtype;
167 my $category = $params->{categorycode};
169 my $guess = Koha::CirculationRules->guess_article_requestable_itemtypes(
171 $category ? ( categorycode => $category ) : (),
174 return ( $guess->{ $itemtype // q{} } || $guess->{'*'} ) ? 1 : q{};
177 =head3 _library_limits
179 configure library limits
183 sub _library_limits {
185 class => "ItemtypesBranch",
187 library => "branchcode",
193 Returns the ItemType object of the parent_type or undef.
199 my $parent_rs = $self->_result->parent_type;
200 return unless $parent_rs;
201 return Koha::ItemType->_new_from_dbic($parent_rs);
205 =head3 children_with_localization
207 Returns the ItemType objects of the children of this type or undef.
211 sub children_with_localization {
213 return Koha::ItemTypes->search_with_localization( { parent_type => $self->itemtype } );
216 =head3 to_api_mapping
218 This method returns the mapping for representing a Koha::ItemType object
225 checkinmsg => 'checkin_message',
226 checkinmsgtype => 'checkin_message_type',
227 defaultreplacecost => 'default_replacement_cost',
228 hideinopac => 'hide_in_opac',
229 imageurl => 'image_url',
230 itemtype => 'item_type_id',
231 notforloan => 'not_for_loan_status',
232 processfee => 'process_fee',
233 rentalcharge_daily => 'daily_rental_charge',
234 rentalcharge_daily_calendar => 'daily_rental_charge_calendar',
235 rentalcharge_hourly => 'hourly_rental_charge',
236 rentalcharge_hourly_calendar => 'hourly_rental_charge_calendar',
240 =head2 Internal methods