Merge branch 'bug_7368' into 3.14-master
[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
25 our $AUTOLOAD;
26
27
28
29
30 =head1 NAME
31
32 C4::ItemType - objects from the itemtypes table
33
34 =head1 SYNOPSIS
35
36     use C4::ItemType;
37     my @itemtypes = C4::ItemType->all;
38     print join("\n", map { $_->description } @itemtypes), "\n";
39
40 =head1 DESCRIPTION
41
42 Objects of this class represent a row in the C<itemtypes> table.
43
44 Currently, the bare minimum for using this as a read-only data source has
45 been implemented.  The API was designed to make it easy to transition to
46 an ORM later on.
47
48 =head1 API
49
50 =head2 Class Methods
51
52 =cut
53
54 =head3 C4::ItemType->new(\%opts)
55
56 Given a hashref, a new (in-memory) C4::ItemType object will be instantiated.
57 The database is not touched.
58
59 =cut
60
61 sub new {
62     my ($class, $opts) = @_;
63     bless $opts => $class;
64 }
65
66
67
68
69 =head3 C4::ItemType->all
70
71 This returns all the itemtypes as objects.  By default they're ordered by
72 C<description>.
73
74 =cut
75
76 sub all {
77     my ($class) = @_;
78     my $dbh = C4::Context->dbh;
79
80     my @itypes;
81     for ( @{$dbh->selectall_arrayref(
82         "SELECT * FROM itemtypes ORDER BY description", { Slice => {} })} )
83     {
84 #        utf8::encode($_->{description});
85         push @itypes, $class->new($_);
86     }
87     return @itypes;
88 }
89
90
91
92
93 =head2 Object Methods
94
95 These are read-only accessors for attributes of a C4::ItemType object.
96
97 =head3 $itemtype->itemtype
98
99 =cut
100
101 =head3 $itemtype->description
102
103 =cut
104
105 =head3 $itemtype->renewalsallowed
106
107 =cut
108
109 =head3 $itemtype->rentalcharge
110
111 =cut
112
113 =head3 $itemtype->notforloan
114
115 =cut
116
117 =head3 $itemtype->imageurl
118
119 =cut
120
121 =head3 $itemtype->summary
122
123 =cut
124
125 sub AUTOLOAD {
126     my $self = shift;
127     my $attr = $AUTOLOAD;
128     $attr =~ s/.*://;
129     if (exists $self->{$attr}) {
130         return $self->{$attr};
131     } else {
132         return undef;
133     }
134 }
135
136 sub DESTROY { }
137
138
139
140 # ack itemtypes | grep '\.pm' | awk '{ print $1 }' | sed 's/:.*$//' | sort | uniq | sed -e 's,/,::,g' -e 's/\.pm//' -e 's/^/L<C4::/' -e 's/$/>,/'
141
142 =head1 SEE ALSO
143
144 The following modules make reference to the C<itemtypes> table.
145
146 L<C4::Biblio>,
147 L<C4::Circulation>,
148 L<C4::Context>,
149 L<C4::Items>,
150 L<C4::Koha>,
151 L<C4::Labels>,
152 L<C4::Overdues>,
153 L<C4::Reserves>,
154 L<C4::Search>,
155 L<C4::VirtualShelves::Page>,
156 L<C4::VirtualShelves>,
157 L<C4::XSLT>
158
159
160
161 =head1 AUTHOR
162
163 John Beppu <john.beppu@liblime.com>
164
165 =cut
166
167 1;