Bug 13748: Acquisition wizard: some strings not translatable
[koha.git] / C4 / ItemType.pm
blob3a15287c85977e2dbb1e5e4cb1486b58d3a2d2de
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 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.
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.
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.
21 use strict;
22 use warnings;
23 use C4::Context;
24 use Encode qw( encode );
26 our $AUTOLOAD;
31 =head1 NAME
33 C4::ItemType - objects from the itemtypes table
35 =head1 SYNOPSIS
37 use C4::ItemType;
38 my @itemtypes = C4::ItemType->all;
39 print join("\n", map { $_->description } @itemtypes), "\n";
41 =head1 DESCRIPTION
43 Objects of this class represent a row in the C<itemtypes> table.
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.
49 =head1 API
51 =head2 Class Methods
53 =cut
55 =head3 C4::ItemType->new(\%opts)
57 Given a hashref, a new (in-memory) C4::ItemType object will be instantiated.
58 The database is not touched.
60 =cut
62 sub new {
63 my ($class, $opts) = @_;
64 bless $opts => $class;
70 =head3 C4::ItemType->all
72 This returns all the itemtypes as objects. By default they're ordered by
73 C<description>.
75 =cut
77 sub all {
78 my ($class) = @_;
79 my $dbh = C4::Context->dbh;
81 my @itypes;
82 for ( @{$dbh->selectall_arrayref(
83 "SELECT * FROM itemtypes ORDER BY description", { Slice => {} })} )
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) = @_;
102 my $dbh = C4::Context->dbh;
104 my $data = $dbh->selectrow_hashref(
105 "SELECT * FROM itemtypes WHERE itemtype = ?", undef, $itemtype
107 return $class->new($data);
113 =head2 Object Methods
115 These are read-only accessors for attributes of a C4::ItemType object.
117 =head3 $itemtype->itemtype
119 =cut
121 =head3 $itemtype->description
123 =cut
125 =head3 $itemtype->renewalsallowed
127 =cut
129 =head3 $itemtype->rentalcharge
131 =cut
133 =head3 $itemtype->notforloan
135 =cut
137 =head3 $itemtype->imageurl
139 =cut
141 =head3 $itemtype->checkinmsg
143 =cut
145 =head3 $itemtype->summary
147 =cut
149 sub AUTOLOAD {
150 my $self = shift;
151 my $attr = $AUTOLOAD;
152 $attr =~ s/.*://;
153 if (exists $self->{$attr}) {
154 return $self->{$attr};
155 } else {
156 return undef;
160 sub DESTROY { }
164 # ack itemtypes | grep '\.pm' | awk '{ print $1 }' | sed 's/:.*$//' | sort | uniq | sed -e 's,/,::,g' -e 's/\.pm//' -e 's/^/L<C4::/' -e 's/$/>,/'
166 =head1 SEE ALSO
168 The following modules make reference to the C<itemtypes> table.
170 L<C4::Biblio>,
171 L<C4::Circulation>,
172 L<C4::Context>,
173 L<C4::Items>,
174 L<C4::Koha>,
175 L<C4::Labels>,
176 L<C4::Overdues>,
177 L<C4::Reserves>,
178 L<C4::Search>,
179 L<C4::VirtualShelves::Page>,
180 L<C4::VirtualShelves>,
181 L<C4::XSLT>
185 =head1 AUTHOR
187 John Beppu <john.beppu@liblime.com>
189 =cut