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 );
24 use Koha::CirculationRules;
25 use Koha::Localizations;
27 use base qw(Koha::Object Koha::Object::Limit::Library);
31 Koha::ItemType - Koha Item type Object class
44 my ( $self, $interface ) = @_;
45 return C4::Koha::getitemtypeimagelocation( $interface, $self->SUPER::imageurl );
48 =head3 translated_description
52 sub translated_description {
53 my ( $self, $lang ) = @_;
54 if ( my $translated_description = eval { $self->get_column('translated_description') } ) {
55 # If the value has already been fetched (eg. from sarch_with_localization),
56 # do not search for it again
57 # Note: This is a bit hacky but should be fast
58 return $translated_description
59 ? $translated_description
62 $lang ||= C4::Languages::getlanguage;
63 my $translated_description = Koha::Localizations->search({
64 code => $self->itemtype,
65 entity => 'itemtypes',
68 return $translated_description
69 ? $translated_description->translation
73 =head3 translated_descriptions
77 sub translated_descriptions {
79 my @translated_descriptions = Koha::Localizations->search(
80 { entity => 'itemtypes',
81 code => $self->itemtype,
87 translation => $_->translation,
89 } @translated_descriptions ];
94 my $can_be_deleted = Koha::ItemType->can_be_deleted();
96 Counts up the number of biblioitems and items with itemtype (code) and hands back the combined number of biblioitems and items with the itemtype
102 my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count;
103 my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count;
104 return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
107 =head3 may_article_request
109 Returns true if it is likely possible to make an article request for
111 Optional parameter: categorycode (for patron).
115 sub may_article_request {
116 my ( $self, $params ) = @_;
117 return q{} if !C4::Context->preference('ArticleRequests');
118 my $itemtype = $self->itemtype;
119 my $category = $params->{categorycode};
121 my $guess = Koha::CirculationRules->guess_article_requestable_itemtypes({
122 $category ? ( categorycode => $category ) : (),
124 return ( $guess->{ $itemtype // q{} } || $guess->{ '*' } ) ? 1 : q{};
127 =head3 _library_limits
129 configure library limits
133 sub _library_limits {
135 class => "ItemtypesBranch",
137 library => "branchcode",
143 Returns the ItemType object of the parent_type or undef.
149 my $parent_rs = $self->_result->parent_type;
150 return unless $parent_rs;
151 return Koha::ItemType->_new_from_dbic( $parent_rs );
155 =head3 children_with_localization
157 Returns the ItemType objects of the children of this type or undef.
161 sub children_with_localization {
163 return Koha::ItemTypes->search_with_localization({ parent_type => $self->itemtype });