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