Bug 12478: (follow-up) Display the correct number of facets
[koha.git] / Koha / ItemType.pm
1 package Koha::ItemType;
2
3 # This represents a single itemtype
4
5 # Copyright 2014 Catalyst IT
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 3 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 use Modern::Perl;
23
24 use Carp;
25
26 use C4::Koha;
27 use C4::Languages;
28 use Koha::Database;
29 use Koha::Localizations;
30
31 use base qw(Koha::Object);
32
33 =head1 NAME
34
35 Koha::ItemType - Koha Item type Object class
36
37 =head1 API
38
39 =head2 Class Methods
40
41 =cut
42
43 =head3 image_location
44
45 =cut
46
47 sub image_location {
48     my ( $self, $interface ) = @_;
49     return C4::Koha::getitemtypeimagelocation( $interface, $self->SUPER::imageurl );
50 }
51
52 =head3 translated_description
53
54 =cut
55
56 sub translated_description {
57     my ( $self, $lang ) = @_;
58     $lang ||= C4::Languages::getlanguage;
59     my $translated_description = Koha::Localizations->search({
60         code => $self->itemtype,
61         entity => 'itemtypes',
62         lang => $lang
63     })->next;
64     return $translated_description
65          ? $translated_description->translation
66          : $self->description;
67 }
68
69 =head3 translated_descriptions
70
71 =cut
72
73 sub translated_descriptions {
74     my ( $self ) = @_;
75     my @translated_descriptions = Koha::Localizations->search(
76         {   entity => 'itemtypes',
77             code   => $self->itemtype,
78         }
79     );
80     return [ map {
81         {
82             lang => $_->lang,
83             translation => $_->translation,
84         }
85     } @translated_descriptions ];
86 }
87
88 =head3 type
89
90 =cut
91
92 sub _type {
93     return 'Itemtype';
94 }
95
96 1;