Bug 11944: replace use of utf8 with Encode
[koha.git] / C4 / ItemType.pm
1 package C4::ItemType;
2
3 # Copyright Liblime 2009
4 # Parts Copyright Tamil 2011
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use strict;
22 use warnings;
23 use C4::Context;
24 use Encode qw( encode );
25
26 our $AUTOLOAD;
27
28
29
30
31 =head1 NAME
32
33 C4::ItemType - objects from the itemtypes table
34
35 =head1 SYNOPSIS
36
37     use C4::ItemType;
38     my @itemtypes = C4::ItemType->all;
39     print join("\n", map { $_->description } @itemtypes), "\n";
40
41 =head1 DESCRIPTION
42
43 Objects of this class represent a row in the C<itemtypes> table.
44
45 Currently, the bare minimum for using this as a read-only data source has
46 been implemented.  The API was designed to make it easy to transition to
47 an ORM later on.
48
49 =head1 API
50
51 =head2 Class Methods
52
53 =cut
54
55 =head3 C4::ItemType->new(\%opts)
56
57 Given a hashref, a new (in-memory) C4::ItemType object will be instantiated.
58 The database is not touched.
59
60 =cut
61
62 sub new {
63     my ($class, $opts) = @_;
64     bless $opts => $class;
65 }
66
67
68
69
70 =head3 C4::ItemType->all
71
72 This returns all the itemtypes as objects.  By default they're ordered by
73 C<description>.
74
75 =cut
76
77 sub all {
78     my ($class) = @_;
79     my $dbh = C4::Context->dbh;
80
81     my @itypes;
82     for ( @{$dbh->selectall_arrayref(
83         "SELECT * FROM itemtypes ORDER BY description", { Slice => {} })} )
84     {
85         $_->{description} = Encode::encode('UTF-8', $_->{description});
86         push @itypes, $class->new($_);
87     }
88     return @itypes;
89 }
90
91
92
93
94 =head3 C4::ItemType->get
95
96 Return the itemtype indicated by the itemtype given as argument, as
97 an object.
98
99 =cut
100
101 sub get {
102     my ($class, $itemtype) = @_;
103     my $dbh = C4::Context->dbh;
104
105     my $data = $dbh->selectrow_hashref(
106         "SELECT * FROM itemtypes WHERE itemtype = ?", undef, $itemtype
107     );
108     if ( $data->{description} ) {
109         $data->{description} = Encode::encode('UTF-8', $data->{description});
110     }
111     return $class->new($data);
112 }
113
114
115
116
117 =head2 Object Methods
118
119 These are read-only accessors for attributes of a C4::ItemType object.
120
121 =head3 $itemtype->itemtype
122
123 =cut
124
125 =head3 $itemtype->description
126
127 =cut
128
129 =head3 $itemtype->renewalsallowed
130
131 =cut
132
133 =head3 $itemtype->rentalcharge
134
135 =cut
136
137 =head3 $itemtype->notforloan
138
139 =cut
140
141 =head3 $itemtype->imageurl
142
143 =cut
144
145 =head3 $itemtype->checkinmsg
146
147 =cut
148
149 =head3 $itemtype->summary
150
151 =cut
152
153 sub AUTOLOAD {
154     my $self = shift;
155     my $attr = $AUTOLOAD;
156     $attr =~ s/.*://;
157     if (exists $self->{$attr}) {
158         return $self->{$attr};
159     } else {
160         return undef;
161     }
162 }
163
164 sub DESTROY { }
165
166
167
168 # ack itemtypes | grep '\.pm' | awk '{ print $1 }' | sed 's/:.*$//' | sort | uniq | sed -e 's,/,::,g' -e 's/\.pm//' -e 's/^/L<C4::/' -e 's/$/>,/'
169
170 =head1 SEE ALSO
171
172 The following modules make reference to the C<itemtypes> table.
173
174 L<C4::Biblio>,
175 L<C4::Circulation>,
176 L<C4::Context>,
177 L<C4::Items>,
178 L<C4::Koha>,
179 L<C4::Labels>,
180 L<C4::Overdues>,
181 L<C4::Reserves>,
182 L<C4::Search>,
183 L<C4::VirtualShelves::Page>,
184 L<C4::VirtualShelves>,
185 L<C4::XSLT>
186
187
188
189 =head1 AUTHOR
190
191 John Beppu <john.beppu@liblime.com>
192
193 =cut
194
195 1;