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>.
21 use C4::Koha qw( getitemtypeimagelocation );
25 use Koha::CirculationRules;
26 use Koha::Localizations;
28 use base qw(Koha::Object Koha::Object::Limit::Library);
32 Koha::ItemType - Koha Item type Object class
42 ItemType specific store to ensure relevant caches are flushed on change
51 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 $cache = Koha::Caches->get_instance();
63 my $key = "itemtype:description:en";
64 $cache->clear_from_cache($key);
75 my ( $self, $interface ) = @_;
76 return C4::Koha::getitemtypeimagelocation( $interface, $self->SUPER::imageurl );
79 =head3 translated_description
83 sub translated_description {
84 my ( $self, $lang ) = @_;
85 if ( my $translated_description = eval { $self->get_column('translated_description') } ) {
86 # If the value has already been fetched (eg. from sarch_with_localization),
87 # do not search for it again
88 # Note: This is a bit hacky but should be fast
89 return $translated_description
90 ? $translated_description
93 $lang ||= C4::Languages::getlanguage;
94 my $translated_description = Koha::Localizations->search({
95 code => $self->itemtype,
96 entity => 'itemtypes',
99 return $translated_description
100 ? $translated_description->translation
101 : $self->description;
104 =head3 translated_descriptions
108 sub translated_descriptions {
110 my @translated_descriptions = Koha::Localizations->search(
111 { entity => 'itemtypes',
112 code => $self->itemtype,
118 translation => $_->translation,
120 } @translated_descriptions ];
123 =head3 can_be_deleted
125 my $can_be_deleted = Koha::ItemType->can_be_deleted();
127 Counts up the number of biblioitems and items with itemtype (code) and hands back the combined number of biblioitems and items with the itemtype
133 my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count;
134 my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count;
135 return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
138 =head3 may_article_request
140 Returns true if it is likely possible to make an article request for
142 Optional parameter: categorycode (for patron).
146 sub may_article_request {
147 my ( $self, $params ) = @_;
148 return q{} if !C4::Context->preference('ArticleRequests');
149 my $itemtype = $self->itemtype;
150 my $category = $params->{categorycode};
152 my $guess = Koha::CirculationRules->guess_article_requestable_itemtypes({
153 $category ? ( categorycode => $category ) : (),
155 return ( $guess->{ $itemtype // q{} } || $guess->{ '*' } ) ? 1 : q{};
158 =head3 _library_limits
160 configure library limits
164 sub _library_limits {
166 class => "ItemtypesBranch",
168 library => "branchcode",
174 Returns the ItemType object of the parent_type or undef.
180 my $parent_rs = $self->_result->parent_type;
181 return unless $parent_rs;
182 return Koha::ItemType->_new_from_dbic( $parent_rs );
186 =head3 children_with_localization
188 Returns the ItemType objects of the children of this type or undef.
192 sub children_with_localization {
194 return Koha::ItemTypes->search_with_localization({ parent_type => $self->itemtype });