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);
30 my $cache = Koha::Caches->get_instance();
34 Koha::ItemType - Koha Item type Object class
44 ItemType specific store to ensure relevant caches are flushed on change
53 if ( !$self->in_storage ) {
57 my $self_from_storage = $self->get_from_storage;
58 $flush = 1 if ( $self_from_storage->description ne $self->description );
61 $self = $self->SUPER::store;
64 my $key = "itemtype:description:en";
65 $cache->clear_from_cache($key);
73 ItemType specific C<delete> to clear relevant caches on delete.
79 $cache->clear_from_cache('itemtype:description:en');
80 $self->SUPER::delete(@_);
88 my ( $self, $interface ) = @_;
89 return C4::Koha::getitemtypeimagelocation( $interface, $self->SUPER::imageurl );
92 =head3 translated_description
96 sub translated_description {
97 my ( $self, $lang ) = @_;
98 if ( my $translated_description = eval { $self->get_column('translated_description') } ) {
99 # If the value has already been fetched (eg. from sarch_with_localization),
100 # do not search for it again
101 # Note: This is a bit hacky but should be fast
102 return $translated_description
103 ? $translated_description
104 : $self->description;
106 $lang ||= C4::Languages::getlanguage;
107 my $translated_description = Koha::Localizations->search({
108 code => $self->itemtype,
109 entity => 'itemtypes',
112 return $translated_description
113 ? $translated_description->translation
114 : $self->description;
117 =head3 translated_descriptions
121 sub translated_descriptions {
123 my @translated_descriptions = Koha::Localizations->search(
124 { entity => 'itemtypes',
125 code => $self->itemtype,
131 translation => $_->translation,
133 } @translated_descriptions ];
136 =head3 can_be_deleted
138 my $can_be_deleted = Koha::ItemType->can_be_deleted();
140 Counts up the number of biblioitems and items with itemtype (code) and hands back the combined number of biblioitems and items with the itemtype
146 my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count;
147 my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count;
148 return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
151 =head3 may_article_request
153 Returns true if it is likely possible to make an article request for
155 Optional parameter: categorycode (for patron).
159 sub may_article_request {
160 my ( $self, $params ) = @_;
161 return q{} if !C4::Context->preference('ArticleRequests');
162 my $itemtype = $self->itemtype;
163 my $category = $params->{categorycode};
165 my $guess = Koha::CirculationRules->guess_article_requestable_itemtypes({
166 $category ? ( categorycode => $category ) : (),
168 return ( $guess->{ $itemtype // q{} } || $guess->{ '*' } ) ? 1 : q{};
171 =head3 _library_limits
173 configure library limits
177 sub _library_limits {
179 class => "ItemtypesBranch",
181 library => "branchcode",
187 Returns the ItemType object of the parent_type or undef.
193 my $parent_rs = $self->_result->parent_type;
194 return unless $parent_rs;
195 return Koha::ItemType->_new_from_dbic( $parent_rs );
199 =head3 children_with_localization
201 Returns the ItemType objects of the children of this type or undef.
205 sub children_with_localization {
207 return Koha::ItemTypes->search_with_localization({ parent_type => $self->itemtype });