| Filename | /mnt/catalyst/koha/C4/ItemType.pm |
| Statements | Executed 8 statements in 479µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 463µs | 476µs | C4::ItemType::BEGIN@21 |
| 1 | 1 | 1 | 8µs | 9µs | C4::ItemType::BEGIN@23 |
| 1 | 1 | 1 | 7µs | 11µs | C4::ItemType::BEGIN@22 |
| 0 | 0 | 0 | 0s | 0s | C4::ItemType::AUTOLOAD |
| 0 | 0 | 0 | 0s | 0s | C4::ItemType::DESTROY |
| 0 | 0 | 0 | 0s | 0s | C4::ItemType::all |
| 0 | 0 | 0 | 0s | 0s | C4::ItemType::get |
| 0 | 0 | 0 | 0s | 0s | C4::ItemType::new |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package C4::ItemType; | ||||
| 2 | |||||
| 3 | # Copyright Liblime 2009 | ||||
| 4 | # Parts Copyright Tamil 2011 | ||||
| 5 | # | ||||
| 6 | # This file is part of Koha. | ||||
| 7 | # | ||||
| 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. | ||||
| 12 | # | ||||
| 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. | ||||
| 16 | # | ||||
| 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. | ||||
| 20 | |||||
| 21 | 2 | 27µs | 2 | 489µs | # spent 476µs (463+13) within C4::ItemType::BEGIN@21 which was called:
# once (463µs+13µs) by C4::ItemCirculationAlertPreference::BEGIN@24 at line 21 # spent 476µs making 1 call to C4::ItemType::BEGIN@21
# spent 13µs making 1 call to strict::import |
| 22 | 2 | 20µs | 2 | 16µs | # spent 11µs (7+4) within C4::ItemType::BEGIN@22 which was called:
# once (7µs+4µs) by C4::ItemCirculationAlertPreference::BEGIN@24 at line 22 # spent 11µs making 1 call to C4::ItemType::BEGIN@22
# spent 4µs making 1 call to warnings::import |
| 23 | 2 | 430µs | 2 | 11µs | # spent 9µs (8+2) within C4::ItemType::BEGIN@23 which was called:
# once (8µs+2µs) by C4::ItemCirculationAlertPreference::BEGIN@24 at line 23 # spent 9µs making 1 call to C4::ItemType::BEGIN@23
# spent 2µs making 1 call to C4::Context::import |
| 24 | |||||
| 25 | 1 | 100ns | our $AUTOLOAD; | ||
| 26 | |||||
| - - | |||||
| 30 | =head1 NAME | ||||
| 31 | |||||
| 32 | C4::ItemType - objects from the itemtypes table | ||||
| 33 | |||||
| 34 | =head1 SYNOPSIS | ||||
| 35 | |||||
| 36 | use C4::ItemType; | ||||
| 37 | my @itemtypes = C4::ItemType->all; | ||||
| 38 | print join("\n", map { $_->description } @itemtypes), "\n"; | ||||
| 39 | |||||
| 40 | =head1 DESCRIPTION | ||||
| 41 | |||||
| 42 | Objects of this class represent a row in the C<itemtypes> table. | ||||
| 43 | |||||
| 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. | ||||
| 47 | |||||
| 48 | =head1 API | ||||
| 49 | |||||
| 50 | =head2 Class Methods | ||||
| 51 | |||||
| 52 | =cut | ||||
| 53 | |||||
| 54 | =head3 C4::ItemType->new(\%opts) | ||||
| 55 | |||||
| 56 | Given a hashref, a new (in-memory) C4::ItemType object will be instantiated. | ||||
| 57 | The database is not touched. | ||||
| 58 | |||||
| 59 | =cut | ||||
| 60 | |||||
| 61 | sub new { | ||||
| 62 | my ($class, $opts) = @_; | ||||
| 63 | bless $opts => $class; | ||||
| 64 | } | ||||
| 65 | |||||
| - - | |||||
| 69 | =head3 C4::ItemType->all | ||||
| 70 | |||||
| 71 | This returns all the itemtypes as objects. By default they're ordered by | ||||
| 72 | C<description>. | ||||
| 73 | |||||
| 74 | =cut | ||||
| 75 | |||||
| 76 | sub all { | ||||
| 77 | my ($class) = @_; | ||||
| 78 | my $dbh = C4::Context->dbh; | ||||
| 79 | |||||
| 80 | my @itypes; | ||||
| 81 | for ( @{$dbh->selectall_arrayref( | ||||
| 82 | "SELECT * FROM itemtypes ORDER BY description", { Slice => {} })} ) | ||||
| 83 | { | ||||
| 84 | utf8::encode($_->{description}); | ||||
| 85 | push @itypes, $class->new($_); | ||||
| 86 | } | ||||
| 87 | return @itypes; | ||||
| 88 | } | ||||
| 89 | |||||
| - - | |||||
| 93 | =head3 C4::ItemType->get | ||||
| 94 | |||||
| 95 | Return the itemtype indicated by the itemtype given as argument, as | ||||
| 96 | an object. | ||||
| 97 | |||||
| 98 | =cut | ||||
| 99 | |||||
| 100 | sub get { | ||||
| 101 | my ($class, $itemtype) = @_; | ||||
| 102 | my $dbh = C4::Context->dbh; | ||||
| 103 | |||||
| 104 | my $data = $dbh->selectrow_hashref( | ||||
| 105 | "SELECT * FROM itemtypes WHERE itemtype = ?", undef, $itemtype | ||||
| 106 | ); | ||||
| 107 | if ( $data->{description} ) { | ||||
| 108 | utf8::encode($data->{description}); | ||||
| 109 | } | ||||
| 110 | return $class->new($data); | ||||
| 111 | } | ||||
| 112 | |||||
| - - | |||||
| 116 | =head2 Object Methods | ||||
| 117 | |||||
| 118 | These are read-only accessors for attributes of a C4::ItemType object. | ||||
| 119 | |||||
| 120 | =head3 $itemtype->itemtype | ||||
| 121 | |||||
| 122 | =cut | ||||
| 123 | |||||
| 124 | =head3 $itemtype->description | ||||
| 125 | |||||
| 126 | =cut | ||||
| 127 | |||||
| 128 | =head3 $itemtype->renewalsallowed | ||||
| 129 | |||||
| 130 | =cut | ||||
| 131 | |||||
| 132 | =head3 $itemtype->rentalcharge | ||||
| 133 | |||||
| 134 | =cut | ||||
| 135 | |||||
| 136 | =head3 $itemtype->notforloan | ||||
| 137 | |||||
| 138 | =cut | ||||
| 139 | |||||
| 140 | =head3 $itemtype->imageurl | ||||
| 141 | |||||
| 142 | =cut | ||||
| 143 | |||||
| 144 | =head3 $itemtype->checkinmsg | ||||
| 145 | |||||
| 146 | =cut | ||||
| 147 | |||||
| 148 | =head3 $itemtype->summary | ||||
| 149 | |||||
| 150 | =cut | ||||
| 151 | |||||
| 152 | sub AUTOLOAD { | ||||
| 153 | my $self = shift; | ||||
| 154 | my $attr = $AUTOLOAD; | ||||
| 155 | $attr =~ s/.*://; | ||||
| 156 | if (exists $self->{$attr}) { | ||||
| 157 | return $self->{$attr}; | ||||
| 158 | } else { | ||||
| 159 | return undef; | ||||
| 160 | } | ||||
| 161 | } | ||||
| 162 | |||||
| 163 | sub DESTROY { } | ||||
| 164 | |||||
| - - | |||||
| 167 | # ack itemtypes | grep '\.pm' | awk '{ print $1 }' | sed 's/:.*$//' | sort | uniq | sed -e 's,/,::,g' -e 's/\.pm//' -e 's/^/L<C4::/' -e 's/$/>,/' | ||||
| 168 | |||||
| 169 | =head1 SEE ALSO | ||||
| 170 | |||||
| 171 | The following modules make reference to the C<itemtypes> table. | ||||
| 172 | |||||
| 173 | L<C4::Biblio>, | ||||
| 174 | L<C4::Circulation>, | ||||
| 175 | L<C4::Context>, | ||||
| 176 | L<C4::Items>, | ||||
| 177 | L<C4::Koha>, | ||||
| 178 | L<C4::Labels>, | ||||
| 179 | L<C4::Overdues>, | ||||
| 180 | L<C4::Reserves>, | ||||
| 181 | L<C4::Search>, | ||||
| 182 | L<C4::VirtualShelves::Page>, | ||||
| 183 | L<C4::VirtualShelves>, | ||||
| 184 | L<C4::XSLT> | ||||
| 185 | |||||
| - - | |||||
| 188 | =head1 AUTHOR | ||||
| 189 | |||||
| 190 | John Beppu <john.beppu@liblime.com> | ||||
| 191 | |||||
| 192 | =cut | ||||
| 193 | |||||
| 194 | 1 | 3µs | 1; |