File: | C4/Category.pm |
Coverage: | 37.5% |
line | stmt | bran | cond | sub | time | code |
---|---|---|---|---|---|---|
1 | package C4::Category; | |||||
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 | 15 15 15 | 18295 70 478 | use strict; | |||
19 | 15 15 15 | 118 49 556 | use warnings; | |||
20 | 15 15 15 | 286 46 170 | use C4::Context; | |||
21 | ||||||
22 | our $AUTOLOAD; | |||||
23 | ||||||
24 | ||||||
25 | ||||||
26 | ||||||
27 - 49 | =head1 NAME C4::Category - objects from the categories table =head1 SYNOPSIS use C4::Category; my @categories = C4::Category->all; print join("\n", map { $_->description } @categories), "\n"; =head1 DESCRIPTION Objects of this class represent a row in the C<categories> 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::Category->new(\%opts) Given a hashref, a new (in-memory) C4::Category 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::Category->all This returns all the categories as objects. By default they're ordered by C<description>. =cut | |||||
72 | ||||||
73 | sub all { | |||||
74 | 0 | my $class = shift; | ||||
75 | 0 | map { | ||||
76 | 0 | utf8::encode($_->{description}); | ||||
77 | 0 | $class->new($_); | ||||
78 | 0 | } @{C4::Context->dbh->selectall_arrayref( | ||||
79 | "SELECT * FROM categories ORDER BY description", { Slice => {} } | |||||
80 | )}; | |||||
81 | } | |||||
82 | ||||||
83 | ||||||
84 | ||||||
85 | ||||||
86 - 92 | =head2 Object Methods These are read-only accessors for attributes of a C4::Category object. =head3 $category->categorycode =cut | |||||
93 | ||||||
94 - 96 | =head3 $category->description =cut | |||||
97 | ||||||
98 - 100 | =head3 $category->enrolmentperiod =cut | |||||
101 | ||||||
102 - 104 | =head3 $category->upperagelimit =cut | |||||
105 | ||||||
106 - 108 | =head3 $category->dateofbirthrequired =cut | |||||
109 | ||||||
110 - 112 | =head3 $category->finetype =cut | |||||
113 | ||||||
114 - 116 | =head3 $category->bulk =cut | |||||
117 | ||||||
118 - 120 | =head3 $category->enrolmentfee =cut | |||||
121 | ||||||
122 - 124 | =head3 $category->overduenoticerequired =cut | |||||
125 | ||||||
126 - 128 | =head3 $category->issuelimit =cut | |||||
129 | ||||||
130 - 132 | =head3 $category->reservefee =cut | |||||
133 | ||||||
134 - 136 | =head3 $category->category_type =cut | |||||
137 | ||||||
138 | sub AUTOLOAD { | |||||
139 | 0 | my $self = shift; | ||||
140 | 0 | my $attr = $AUTOLOAD; | ||||
141 | 0 | $attr =~ s/.*://; | ||||
142 | 0 | if (exists $self->{$attr}) { | ||||
143 | 0 | return $self->{$attr}; | ||||
144 | } else { | |||||
145 | 0 | return undef; | ||||
146 | } | |||||
147 | } | |||||
148 | ||||||
149 | 0 | sub DESTROY { } | ||||
150 | ||||||
151 | ||||||
152 | ||||||
153 | ||||||
154 - 165 | =head1 SEE ALSO The following modules make reference to the C<categories> table. L<C4::Members>, L<C4::Overdues>, L<C4::Reserves> =head1 AUTHOR John Beppu <john.beppu@liblime.com> =cut | |||||
166 | ||||||
167 | 1; |