| File: | C4/ItemType.pm |
| Coverage: | 34.3% |
| line | stmt | bran | cond | sub | time | code |
|---|---|---|---|---|---|---|
| 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 | 16 16 16 | 399 114 436 | use strict; | |||
| 19 | 16 16 16 | 118 48 552 | use warnings; | |||
| 20 | 16 16 16 | 287 51 187 | use C4::Context; | |||
| 21 | ||||||
| 22 | our $AUTOLOAD; | |||||
| 23 | ||||||
| 24 | ||||||
| 25 | ||||||
| 26 | ||||||
| 27 - 49 | =head1 NAME
C4::ItemType - objects from the itemtypes table
=head1 SYNOPSIS
use C4::ItemType;
my @itemtypes = C4::ItemType->all;
print join("\n", map { $_->description } @itemtypes), "\n";
=head1 DESCRIPTION
Objects of this class represent a row in the C<itemtypes> table.
Currently, the bare minimum for using this as a read-only data source has
been implemented. The API was designed to make it easy to transition to
an ORM later on.
=head1 API
=head2 Class Methods
=cut | |||||
| 50 | ||||||
| 51 - 56 | =head3 C4::ItemType->new(\%opts) Given a hashref, a new (in-memory) C4::ItemType object will be instantiated. The database is not touched. =cut | |||||
| 57 | ||||||
| 58 | sub new { | |||||
| 59 | 0 | my ($class, $opts) = @_; | ||||
| 60 | 0 | bless $opts => $class; | ||||
| 61 | } | |||||
| 62 | ||||||
| 63 | ||||||
| 64 | ||||||
| 65 | ||||||
| 66 - 71 | =head3 C4::ItemType->all This returns all the itemtypes as objects. By default they're ordered by C<description>. =cut | |||||
| 72 | ||||||
| 73 | sub all { | |||||
| 74 | 0 | my ($class) = @_; | ||||
| 75 | 0 | my $dbh = C4::Context->dbh; | ||||
| 76 | ||||||
| 77 | 0 | my @itypes; | ||||
| 78 | 0 0 | for ( @{$dbh->selectall_arrayref( | ||||
| 79 | "SELECT * FROM itemtypes ORDER BY description", { Slice => {} })} ) | |||||
| 80 | { | |||||
| 81 | 0 | utf8::encode($_->{description}); | ||||
| 82 | 0 | push @itypes, $class->new($_); | ||||
| 83 | } | |||||
| 84 | 0 | return @itypes; | ||||
| 85 | } | |||||
| 86 | ||||||
| 87 | ||||||
| 88 | ||||||
| 89 | ||||||
| 90 - 96 | =head2 Object Methods These are read-only accessors for attributes of a C4::ItemType object. =head3 $itemtype->itemtype =cut | |||||
| 97 | ||||||
| 98 - 100 | =head3 $itemtype->description =cut | |||||
| 101 | ||||||
| 102 - 104 | =head3 $itemtype->renewalsallowed =cut | |||||
| 105 | ||||||
| 106 - 108 | =head3 $itemtype->rentalcharge =cut | |||||
| 109 | ||||||
| 110 - 112 | =head3 $itemtype->notforloan =cut | |||||
| 113 | ||||||
| 114 - 116 | =head3 $itemtype->imageurl =cut | |||||
| 117 | ||||||
| 118 - 120 | =head3 $itemtype->summary =cut | |||||
| 121 | ||||||
| 122 | sub AUTOLOAD { | |||||
| 123 | 0 | my $self = shift; | ||||
| 124 | 0 | my $attr = $AUTOLOAD; | ||||
| 125 | 0 | $attr =~ s/.*://; | ||||
| 126 | 0 | if (exists $self->{$attr}) { | ||||
| 127 | 0 | return $self->{$attr}; | ||||
| 128 | } else { | |||||
| 129 | 0 | return undef; | ||||
| 130 | } | |||||
| 131 | } | |||||
| 132 | ||||||
| 133 | 0 | 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 - 162 | =head1 SEE ALSO The following modules make reference to the C<itemtypes> table. L<C4::Biblio>, L<C4::Circulation>, L<C4::Context>, L<C4::Items>, L<C4::Koha>, L<C4::Labels>, L<C4::Overdues>, L<C4::Reserves>, L<C4::Search>, L<C4::VirtualShelves::Page>, L<C4::VirtualShelves>, L<C4::XSLT> =head1 AUTHOR John Beppu <john.beppu@liblime.com> =cut | |||||
| 163 | ||||||
| 164 | 1; | |||||