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>.
25 use Encode
qw( encode );
34 C4::ItemType - objects from the itemtypes table
39 my @itemtypes = C4::ItemType->all;
40 print join("\n", map { $_->description } @itemtypes), "\n";
44 Objects of this class represent a row in the C<itemtypes> table.
46 Currently, the bare minimum for using this as a read-only data source has
47 been implemented. The API was designed to make it easy to transition to
56 =head3 C4::ItemType->new(\%opts)
58 Given a hashref, a new (in-memory) C4::ItemType object will be instantiated.
59 The database is not touched.
64 my ($class, $opts) = @_;
65 bless $opts => $class;
71 =head3 C4::ItemType->all
73 This returns all the itemtypes as objects. By default they're ordered by
80 my $dbh = C4
::Context
->dbh;
82 my $language = C4
::Languages
::getlanguage
();
84 for ( @
{$dbh->selectall_arrayref(q
|
86 COALESCE
( localization
.translation
, itemtypes
.description
) AS translated_description
88 LEFT JOIN localization ON itemtypes
.itemtype
= localization
.code
89 AND localization
.entity
= 'itemtypes'
90 AND localization
.lang
= ?
92 |, { Slice
=> {} }, $language)} )
94 push @itypes, $class->new($_);
102 =head3 C4::ItemType->get
104 Return the itemtype indicated by the itemtype given as argument, as
110 my ($class, $itemtype) = @_;
112 return unless defined $itemtype;
114 my $dbh = C4
::Context
->dbh;
116 my $data = $dbh->selectrow_hashref(
117 "SELECT * FROM itemtypes WHERE itemtype = ?", undef, $itemtype
119 return $class->new($data);
125 =head2 Object Methods
127 These are read-only accessors for attributes of a C4::ItemType object.
129 =head3 $itemtype->itemtype
133 =head3 $itemtype->description
137 =head3 $itemtype->renewalsallowed
141 =head3 $itemtype->rentalcharge
145 =head3 $itemtype->notforloan
149 =head3 $itemtype->imageurl
153 =head3 $itemtype->checkinmsg
157 =head3 $itemtype->summary
163 my $attr = $AUTOLOAD;
165 if (exists $self->{$attr}) {
166 return $self->{$attr};
176 # ack itemtypes | grep '\.pm' | awk '{ print $1 }' | sed 's/:.*$//' | sort | uniq | sed -e 's,/,::,g' -e 's/\.pm//' -e 's/^/L<C4::/' -e 's/$/>,/'
180 The following modules make reference to the C<itemtypes> table.
197 John Beppu <john.beppu@liblime.com>