Lines 17-23
package Koha::ItemType;
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
|
|
|
21 |
use C4::Koha qw( getitemtypeimagelocation ); |
20 |
use C4::Koha qw( getitemtypeimagelocation ); |
22 |
use C4::Languages; |
21 |
use C4::Languages; |
23 |
use Koha::Caches; |
22 |
use Koha::Caches; |
Lines 52-59
sub store {
Link Here
|
52 |
|
51 |
|
53 |
if ( !$self->in_storage ) { |
52 |
if ( !$self->in_storage ) { |
54 |
$flush = 1; |
53 |
$flush = 1; |
55 |
} |
54 |
} else { |
56 |
else { |
|
|
57 |
my $self_from_storage = $self->get_from_storage; |
55 |
my $self_from_storage = $self->get_from_storage; |
58 |
$flush = 1 if ( $self_from_storage->description ne $self->description ); |
56 |
$flush = 1 if ( $self_from_storage->description ne $self->description ); |
59 |
} |
57 |
} |
Lines 96-117
sub image_location {
Link Here
|
96 |
sub translated_description { |
94 |
sub translated_description { |
97 |
my ( $self, $lang ) = @_; |
95 |
my ( $self, $lang ) = @_; |
98 |
if ( my $translated_description = eval { $self->get_column('translated_description') } ) { |
96 |
if ( my $translated_description = eval { $self->get_column('translated_description') } ) { |
|
|
97 |
|
99 |
# If the value has already been fetched (eg. from sarch_with_localization), |
98 |
# If the value has already been fetched (eg. from sarch_with_localization), |
100 |
# do not search for it again |
99 |
# do not search for it again |
101 |
# Note: This is a bit hacky but should be fast |
100 |
# Note: This is a bit hacky but should be fast |
102 |
return $translated_description |
101 |
return $translated_description |
103 |
? $translated_description |
102 |
? $translated_description |
104 |
: $self->description; |
103 |
: $self->description; |
105 |
} |
104 |
} |
106 |
$lang ||= C4::Languages::getlanguage; |
105 |
$lang ||= C4::Languages::getlanguage; |
107 |
my $translated_description = Koha::Localizations->search({ |
106 |
my $translated_description = Koha::Localizations->search( |
108 |
code => $self->itemtype, |
107 |
{ |
109 |
entity => 'itemtypes', |
108 |
code => $self->itemtype, |
110 |
lang => $lang |
109 |
entity => 'itemtypes', |
111 |
})->next; |
110 |
lang => $lang |
|
|
111 |
} |
112 |
)->next; |
112 |
return $translated_description |
113 |
return $translated_description |
113 |
? $translated_description->translation |
114 |
? $translated_description->translation |
114 |
: $self->description; |
115 |
: $self->description; |
115 |
} |
116 |
} |
116 |
|
117 |
|
117 |
=head3 translated_descriptions |
118 |
=head3 translated_descriptions |
Lines 119-136
sub translated_description {
Link Here
|
119 |
=cut |
120 |
=cut |
120 |
|
121 |
|
121 |
sub translated_descriptions { |
122 |
sub translated_descriptions { |
122 |
my ( $self ) = @_; |
123 |
my ($self) = @_; |
123 |
my @translated_descriptions = Koha::Localizations->search( |
124 |
my @translated_descriptions = Koha::Localizations->search( |
124 |
{ entity => 'itemtypes', |
125 |
{ |
|
|
126 |
entity => 'itemtypes', |
125 |
code => $self->itemtype, |
127 |
code => $self->itemtype, |
126 |
} |
128 |
} |
127 |
)->as_list; |
129 |
)->as_list; |
128 |
return [ map { |
130 |
return [ |
129 |
{ |
131 |
map { |
130 |
lang => $_->lang, |
132 |
{ |
131 |
translation => $_->translation, |
133 |
lang => $_->lang, |
132 |
} |
134 |
translation => $_->translation, |
133 |
} @translated_descriptions ]; |
135 |
} |
|
|
136 |
} @translated_descriptions |
137 |
]; |
134 |
} |
138 |
} |
135 |
|
139 |
|
136 |
=head3 can_be_deleted |
140 |
=head3 can_be_deleted |
Lines 142-149
Counts up the number of biblioitems and items with itemtype (code) and hands bac
Link Here
|
142 |
=cut |
146 |
=cut |
143 |
|
147 |
|
144 |
sub can_be_deleted { |
148 |
sub can_be_deleted { |
145 |
my ($self) = @_; |
149 |
my ($self) = @_; |
146 |
my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count; |
150 |
my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count; |
147 |
my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count; |
151 |
my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count; |
148 |
return $nb_items + $nb_biblioitems == 0 ? 1 : 0; |
152 |
return $nb_items + $nb_biblioitems == 0 ? 1 : 0; |
149 |
} |
153 |
} |
Lines 162-171
sub may_article_request {
Link Here
|
162 |
my $itemtype = $self->itemtype; |
166 |
my $itemtype = $self->itemtype; |
163 |
my $category = $params->{categorycode}; |
167 |
my $category = $params->{categorycode}; |
164 |
|
168 |
|
165 |
my $guess = Koha::CirculationRules->guess_article_requestable_itemtypes({ |
169 |
my $guess = Koha::CirculationRules->guess_article_requestable_itemtypes( |
166 |
$category ? ( categorycode => $category ) : (), |
170 |
{ |
167 |
}); |
171 |
$category ? ( categorycode => $category ) : (), |
168 |
return ( $guess->{ $itemtype // q{} } || $guess->{ '*' } ) ? 1 : q{}; |
172 |
} |
|
|
173 |
); |
174 |
return ( $guess->{ $itemtype // q{} } || $guess->{'*'} ) ? 1 : q{}; |
169 |
} |
175 |
} |
170 |
|
176 |
|
171 |
=head3 _library_limits |
177 |
=head3 _library_limits |
Lines 176-183
sub may_article_request {
Link Here
|
176 |
|
182 |
|
177 |
sub _library_limits { |
183 |
sub _library_limits { |
178 |
return { |
184 |
return { |
179 |
class => "ItemtypesBranch", |
185 |
class => "ItemtypesBranch", |
180 |
id => "itemtype", |
186 |
id => "itemtype", |
181 |
library => "branchcode", |
187 |
library => "branchcode", |
182 |
}; |
188 |
}; |
183 |
} |
189 |
} |
Lines 189-198
sub _library_limits {
Link Here
|
189 |
=cut |
195 |
=cut |
190 |
|
196 |
|
191 |
sub parent { |
197 |
sub parent { |
192 |
my ( $self ) = @_; |
198 |
my ($self) = @_; |
193 |
my $parent_rs = $self->_result->parent_type; |
199 |
my $parent_rs = $self->_result->parent_type; |
194 |
return unless $parent_rs; |
200 |
return unless $parent_rs; |
195 |
return Koha::ItemType->_new_from_dbic( $parent_rs ); |
201 |
return Koha::ItemType->_new_from_dbic($parent_rs); |
196 |
|
202 |
|
197 |
} |
203 |
} |
198 |
|
204 |
|
Lines 203-210
sub parent {
Link Here
|
203 |
=cut |
209 |
=cut |
204 |
|
210 |
|
205 |
sub children_with_localization { |
211 |
sub children_with_localization { |
206 |
my ( $self ) = @_; |
212 |
my ($self) = @_; |
207 |
return Koha::ItemTypes->search_with_localization({ parent_type => $self->itemtype }); |
213 |
return Koha::ItemTypes->search_with_localization( { parent_type => $self->itemtype } ); |
|
|
214 |
} |
215 |
|
216 |
=head3 to_api_mapping |
217 |
|
218 |
This method returns the mapping for representing a Koha::ItemType object |
219 |
on the API. |
220 |
|
221 |
=cut |
222 |
|
223 |
sub to_api_mapping { |
224 |
return { 'itemtype' => 'item_type' }; |
225 |
} |
226 |
|
227 |
sub from_api_mapping { |
228 |
return { 'item_type' => 'itemtype' }; |
208 |
} |
229 |
} |
209 |
|
230 |
|
210 |
=head3 type |
231 |
=head3 type |