Bug 14585: Fixing up online help on main page
[koha.git] / C4 / ItemType.pm
blobca14bef1f5e35830007f13bebe7568e3900a02d9
1 package C4::ItemType;
3 # Copyright Liblime 2009
4 # Parts Copyright Tamil 2011
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use strict;
22 use warnings;
23 use C4::Context;
25 our $AUTOLOAD;
30 =head1 NAME
32 C4::ItemType - objects from the itemtypes table
34 =head1 SYNOPSIS
36 use C4::ItemType;
37 my @itemtypes = C4::ItemType->all;
38 print join("\n", map { $_->description } @itemtypes), "\n";
40 =head1 DESCRIPTION
42 Objects of this class represent a row in the C<itemtypes> table.
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.
48 =head1 API
50 =head2 Class Methods
52 =cut
54 =head3 C4::ItemType->new(\%opts)
56 Given a hashref, a new (in-memory) C4::ItemType object will be instantiated.
57 The database is not touched.
59 =cut
61 sub new {
62 my ($class, $opts) = @_;
63 bless $opts => $class;
69 =head3 C4::ItemType->all
71 This returns all the itemtypes as objects. By default they're ordered by
72 C<description>.
74 =cut
76 sub all {
77 my ($class) = @_;
78 my $dbh = C4::Context->dbh;
80 my @itypes;
81 for ( @{$dbh->selectall_arrayref(
82 "SELECT * FROM itemtypes ORDER BY description", { Slice => {} })} )
84 utf8::encode($_->{description});
85 push @itypes, $class->new($_);
87 return @itypes;
93 =head3 C4::ItemType->get
95 Return the itemtype indicated by the itemtype given as argument, as
96 an object.
98 =cut
100 sub get {
101 my ($class, $itemtype) = @_;
103 return unless defined $itemtype;
105 my $dbh = C4::Context->dbh;
107 my $data = $dbh->selectrow_hashref(
108 "SELECT * FROM itemtypes WHERE itemtype = ?", undef, $itemtype
110 if ( $data->{description} ) {
111 utf8::encode($data->{description});
113 return $class->new($data);
119 =head2 Object Methods
121 These are read-only accessors for attributes of a C4::ItemType object.
123 =head3 $itemtype->itemtype
125 =cut
127 =head3 $itemtype->description
129 =cut
131 =head3 $itemtype->renewalsallowed
133 =cut
135 =head3 $itemtype->rentalcharge
137 =cut
139 =head3 $itemtype->notforloan
141 =cut
143 =head3 $itemtype->imageurl
145 =cut
147 =head3 $itemtype->checkinmsg
149 =cut
151 =head3 $itemtype->summary
153 =cut
155 sub AUTOLOAD {
156 my $self = shift;
157 my $attr = $AUTOLOAD;
158 $attr =~ s/.*://;
159 if (exists $self->{$attr}) {
160 return $self->{$attr};
161 } else {
162 return undef;
166 sub DESTROY { }
170 # ack itemtypes | grep '\.pm' | awk '{ print $1 }' | sed 's/:.*$//' | sort | uniq | sed -e 's,/,::,g' -e 's/\.pm//' -e 's/^/L<C4::/' -e 's/$/>,/'
172 =head1 SEE ALSO
174 The following modules make reference to the C<itemtypes> table.
176 L<C4::Biblio>,
177 L<C4::Circulation>,
178 L<C4::Context>,
179 L<C4::Items>,
180 L<C4::Koha>,
181 L<C4::Labels>,
182 L<C4::Overdues>,
183 L<C4::Reserves>,
184 L<C4::Search>,
185 L<C4::VirtualShelves::Page>,
186 L<C4::VirtualShelves>,
187 L<C4::XSLT>
191 =head1 AUTHOR
193 John Beppu <john.beppu@liblime.com>
195 =cut