Filename | /mnt/catalyst/koha/C4/Category.pm |
Statements | Executed 8 statements in 398µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 448µs | 461µs | BEGIN@21 | C4::Category::
1 | 1 | 1 | 8µs | 12µs | BEGIN@22 | C4::Category::
1 | 1 | 1 | 7µs | 8µs | BEGIN@23 | C4::Category::
0 | 0 | 0 | 0s | 0s | AUTOLOAD | C4::Category::
0 | 0 | 0 | 0s | 0s | DESTROY | C4::Category::
0 | 0 | 0 | 0s | 0s | all | C4::Category::
0 | 0 | 0 | 0s | 0s | new | C4::Category::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package C4::Category; | ||||
2 | |||||
3 | # Copyright 2009 Liblime | ||||
4 | # Parts Copyright 2011 Tamil | ||||
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 | 33µs | 2 | 473µs | # spent 461µs (448+12) within C4::Category::BEGIN@21 which was called:
# once (448µs+12µs) by C4::ItemCirculationAlertPreference::BEGIN@23 at line 21 # spent 461µs making 1 call to C4::Category::BEGIN@21
# spent 12µs making 1 call to strict::import |
22 | 2 | 19µs | 2 | 16µs | # spent 12µs (8+4) within C4::Category::BEGIN@22 which was called:
# once (8µs+4µs) by C4::ItemCirculationAlertPreference::BEGIN@23 at line 22 # spent 12µs making 1 call to C4::Category::BEGIN@22
# spent 4µs making 1 call to warnings::import |
23 | 2 | 343µs | 2 | 9µs | # spent 8µs (7+1) within C4::Category::BEGIN@23 which was called:
# once (7µs+1µs) by C4::ItemCirculationAlertPreference::BEGIN@23 at line 23 # spent 8µs making 1 call to C4::Category::BEGIN@23
# spent 1µs making 1 call to C4::Context::import |
24 | |||||
25 | 1 | 100ns | our $AUTOLOAD; | ||
26 | |||||
- - | |||||
30 | =head1 NAME | ||||
31 | |||||
32 | C4::Category - objects from the categories table | ||||
33 | |||||
34 | =head1 SYNOPSIS | ||||
35 | |||||
36 | use C4::Category; | ||||
37 | my @categories = C4::Category->all; | ||||
38 | print join("\n", map { $_->description } @categories), "\n"; | ||||
39 | |||||
40 | =head1 DESCRIPTION | ||||
41 | |||||
42 | Objects of this class represent a row in the C<categories> 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::Category->new(\%opts) | ||||
55 | |||||
56 | Given a hashref, a new (in-memory) C4::Category 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::Category->all | ||||
70 | |||||
71 | This returns all the categories as objects. By default they're ordered by | ||||
72 | C<description>. | ||||
73 | |||||
74 | =cut | ||||
75 | |||||
76 | sub all { | ||||
77 | my ( $class ) = @_; | ||||
78 | my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; | ||||
79 | my $dbh = C4::Context->dbh; | ||||
80 | # The categories table is small enough for | ||||
81 | # `SELECT *` to be harmless. | ||||
82 | my $query = "SELECT categories.* FROM categories"; | ||||
83 | $query .= qq{ | ||||
84 | LEFT JOIN categories_branches ON categories_branches.categorycode = categories.categorycode | ||||
85 | WHERE categories_branches.branchcode = ? OR categories_branches.branchcode IS NULL | ||||
86 | } if $branch_limit; | ||||
87 | $query .= " ORDER BY description"; | ||||
88 | return map { $class->new($_) } @{ | ||||
89 | $dbh->selectall_arrayref( | ||||
90 | $query, | ||||
91 | { Slice => {} }, | ||||
92 | $branch_limit ? $branch_limit : () | ||||
93 | ) | ||||
94 | }; | ||||
95 | } | ||||
96 | |||||
- - | |||||
100 | =head2 Object Methods | ||||
101 | |||||
102 | These are read-only accessors for attributes of a C4::Category object. | ||||
103 | |||||
104 | =head3 $category->categorycode | ||||
105 | |||||
106 | =cut | ||||
107 | |||||
108 | =head3 $category->description | ||||
109 | |||||
110 | =cut | ||||
111 | |||||
112 | =head3 $category->enrolmentperiod | ||||
113 | |||||
114 | =cut | ||||
115 | |||||
116 | =head3 $category->upperagelimit | ||||
117 | |||||
118 | =cut | ||||
119 | |||||
120 | =head3 $category->dateofbirthrequired | ||||
121 | |||||
122 | =cut | ||||
123 | |||||
124 | =head3 $category->finetype | ||||
125 | |||||
126 | =cut | ||||
127 | |||||
128 | =head3 $category->bulk | ||||
129 | |||||
130 | =cut | ||||
131 | |||||
132 | =head3 $category->enrolmentfee | ||||
133 | |||||
134 | =cut | ||||
135 | |||||
136 | =head3 $category->overduenoticerequired | ||||
137 | |||||
138 | =cut | ||||
139 | |||||
140 | =head3 $category->issuelimit | ||||
141 | |||||
142 | =cut | ||||
143 | |||||
144 | =head3 $category->reservefee | ||||
145 | |||||
146 | =cut | ||||
147 | |||||
148 | =head3 $category->category_type | ||||
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 | |||||
- - | |||||
168 | =head1 SEE ALSO | ||||
169 | |||||
170 | The following modules make reference to the C<categories> table. | ||||
171 | |||||
172 | L<C4::Members>, L<C4::Overdues>, L<C4::Reserves> | ||||
173 | |||||
174 | |||||
175 | =head1 AUTHOR | ||||
176 | |||||
177 | John Beppu <john.beppu@liblime.com> | ||||
178 | |||||
179 | =cut | ||||
180 | |||||
181 | 1 | 3µs | 1; |