← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 17:10:45 2013
Reported on Tue Oct 15 17:12:00 2013

Filename/usr/share/koha/lib/C4/ItemCirculationAlertPreference.pm
StatementsExecuted 21 statements in 1.45ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111478µs538µsC4::ItemCirculationAlertPreference::::BEGIN@23C4::ItemCirculationAlertPreference::BEGIN@23
111414µs476µsC4::ItemCirculationAlertPreference::::BEGIN@24C4::ItemCirculationAlertPreference::BEGIN@24
11124µs31µsC4::ItemCirculationAlertPreference::::BEGIN@22C4::ItemCirculationAlertPreference::BEGIN@22
11121µs28µsC4::ItemCirculationAlertPreference::::BEGIN@20C4::ItemCirculationAlertPreference::BEGIN@20
11114µs38µsC4::ItemCirculationAlertPreference::::BEGIN@21C4::ItemCirculationAlertPreference::BEGIN@21
11113µs60µsC4::ItemCirculationAlertPreference::::BEGIN@25C4::ItemCirculationAlertPreference::BEGIN@25
0000s0sC4::ItemCirculationAlertPreference::::AUTOLOADC4::ItemCirculationAlertPreference::AUTOLOAD
0000s0sC4::ItemCirculationAlertPreference::::DESTROYC4::ItemCirculationAlertPreference::DESTROY
0000s0sC4::ItemCirculationAlertPreference::::__ANON__[:35]C4::ItemCirculationAlertPreference::__ANON__[:35]
0000s0sC4::ItemCirculationAlertPreference::::createC4::ItemCirculationAlertPreference::create
0000s0sC4::ItemCirculationAlertPreference::::deleteC4::ItemCirculationAlertPreference::delete
0000s0sC4::ItemCirculationAlertPreference::::findC4::ItemCirculationAlertPreference::find
0000s0sC4::ItemCirculationAlertPreference::::gridC4::ItemCirculationAlertPreference::grid
0000s0sC4::ItemCirculationAlertPreference::::is_disabled_forC4::ItemCirculationAlertPreference::is_disabled_for
0000s0sC4::ItemCirculationAlertPreference::::is_enabled_forC4::ItemCirculationAlertPreference::is_enabled_for
0000s0sC4::ItemCirculationAlertPreference::::newC4::ItemCirculationAlertPreference::new
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package C4::ItemCirculationAlertPreference;
2
3# Copyright Liblime 2009
4#
5# This file is part of Koha.
6#
7# Koha is free software; you can redistribute it and/or modify it under the
8# terms of the GNU General Public License as published by the Free Software
9# Foundation; either version 2 of the License, or (at your option) any later
10# version.
11#
12# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with Koha; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20332µs235µs
# spent 28µs (21+7) within C4::ItemCirculationAlertPreference::BEGIN@20 which was called: # once (21µs+7µs) by C4::Circulation::BEGIN@34 at line 20
use strict;
# spent 28µs making 1 call to C4::ItemCirculationAlertPreference::BEGIN@20 # spent 7µs making 1 call to strict::import
21349µs263µs
# spent 38µs (14+24) within C4::ItemCirculationAlertPreference::BEGIN@21 which was called: # once (14µs+24µs) by C4::Circulation::BEGIN@34 at line 21
use warnings;
# spent 38µs making 1 call to C4::ItemCirculationAlertPreference::BEGIN@21 # spent 24µs making 1 call to warnings::import
22345µs237µs
# spent 31µs (24+6) within C4::ItemCirculationAlertPreference::BEGIN@22 which was called: # once (24µs+6µs) by C4::Circulation::BEGIN@34 at line 22
use C4::Context;
# spent 31µs making 1 call to C4::ItemCirculationAlertPreference::BEGIN@22 # spent 6µs making 1 call to C4::Context::import
233128µs2541µs
# spent 538µs (478+61) within C4::ItemCirculationAlertPreference::BEGIN@23 which was called: # once (478µs+61µs) by C4::Circulation::BEGIN@34 at line 23
use C4::Category;
# spent 538µs making 1 call to C4::ItemCirculationAlertPreference::BEGIN@23 # spent 3µs making 1 call to UNIVERSAL::import
243124µs2479µs
# spent 476µs (414+62) within C4::ItemCirculationAlertPreference::BEGIN@24 which was called: # once (414µs+62µs) by C4::Circulation::BEGIN@34 at line 24
use C4::ItemType;
# spent 476µs making 1 call to C4::ItemCirculationAlertPreference::BEGIN@24 # spent 3µs making 1 call to UNIVERSAL::import
2531.07ms2106µs
# spent 60µs (13+46) within C4::ItemCirculationAlertPreference::BEGIN@25 which was called: # once (13µs+46µs) by C4::Circulation::BEGIN@34 at line 25
use Carp qw(carp croak);
# spent 60µs making 1 call to C4::ItemCirculationAlertPreference::BEGIN@25 # spent 46µs making 1 call to Exporter::import
26
271300nsour $AUTOLOAD;
28
29# helper function for validating \%opts
30our $valid = sub {
31 my $opts = shift;
32 for (qw(branchcode categorycode item_type notification)) {
33 exists($opts->{$_}) || croak("'$_' is a required parameter.");
34 }
3513µs};
36
- -
40=head1 NAME
41
- -
87=head3 C4::ItemCirculationAlertPreference->new(\%opts)
88
- -
94sub new {
95 my ($class, $opts) = @_;
96 bless $opts => $class;
97}
98
- -
102=head3 C4::ItemCirculationAlertPreference->create(\%opts)
103
- -
130sub create {
131 my ($class, $opts) = @_;
132 $valid->($opts);
133 my $dbh = C4::Context->dbh;
134 my $prefs = $dbh->selectall_arrayref(
135 "SELECT id, branchcode, categorycode, item_type
136 FROM item_circulation_alert_preferences
137 WHERE branchcode = ?
138 AND categorycode = ?
139 AND item_type = ?
140 AND notification = ?",
141 { Slice => {} },
142 $opts->{branchcode},
143 $opts->{categorycode},
144 $opts->{item_type},
145 $opts->{notification},
146 );
147 if (@$prefs) {
148 return $class->new($prefs->[0]);
149 } else {
150 my $success = $dbh->do(
151 "INSERT INTO item_circulation_alert_preferences
152 (branchcode, categorycode, item_type, notification) VALUES (?, ?, ?, ?)",
153 {},
154 $opts->{branchcode},
155 $opts->{categorycode},
156 $opts->{item_type},
157 $opts->{notification},
158 );
159 if ($success) {
160 my $self = {
161 id => $dbh->last_insert_id(undef, undef, undef, undef),
162 branchcode => $opts->{branchcode},
163 categorycode => $opts->{categorycode},
164 item_type => $opts->{item_type},
165 notification => $opts->{notification},
166 };
167 return $class->new($self);
168 } else {
169 carp $dbh->errstr;
170 return;
171 }
172 }
173}
174
- -
178=head3 C4::ItemCirculationAlertPreference->delete(\%opts)
179
- -
186sub delete {
187 my ($class, $opts) = @_;
188 my $dbh = C4::Context->dbh;
189 if ($opts->{id}) {
190 $dbh->do(
191 "DELETE FROM item_circulation_alert_preferences WHERE id = ?",
192 {},
193 $opts->{id}
194 );
195 } else {
196 $valid->($opts);
197 my $sql =
198 "DELETE FROM item_circulation_alert_preferences
199 WHERE branchcode = ?
200 AND categorycode = ?
201 AND item_type = ?
202 AND notification = ?";
203 $dbh->do(
204 $sql,
205 {},
206 $opts->{branchcode},
207 $opts->{categorycode},
208 $opts->{item_type},
209 $opts->{notification},
210 );
211 }
212}
213
- -
217=head3 C4::ItemCirculationAlertPreference->is_enabled_for(\%opts)
218
- -
238sub is_disabled_for {
239 my ($class, $opts) = @_;
240 $valid->($opts);
241 my $dbh = C4::Context->dbh;
242
243 # Does a preference exist to block this alert?
244 my $query = qq{
245 SELECT id, branchcode, categorycode, item_type, notification
246 FROM item_circulation_alert_preferences
247 WHERE (branchcode = ? OR branchcode = '*')
248 AND (categorycode = ? OR categorycode = '*')
249 AND (item_type = ? OR item_type = '*')
250 AND (notification = ? OR notification = '*')
251 };
252
253 my $preferences = $dbh->selectall_arrayref(
254 $query,
255 { Slice => {} },
256 $opts->{branchcode},
257 $opts->{categorycode},
258 $opts->{item_type},
259 $opts->{notification},
260 );
261
262 # If any preferences showed up, we are NOT enabled.
263 return @$preferences;
264}
265
266sub is_enabled_for {
267 my ($class, $opts) = @_;
268 return not $class->is_disabled_for($opts);
269}
270
- -
274=head3 C4::ItemCirculationAlertPreference->find({ branchcode => $bc, notification => $type })
275
- -
288sub find {
289 my ($class, $where) = @_;
290 my $dbh = C4::Context->dbh;
291 my $query = qq{
292 SELECT id, branchcode, categorycode, item_type, notification
293 FROM item_circulation_alert_preferences
294 WHERE branchcode = ? AND notification = ?
295 ORDER BY categorycode, item_type
296 };
297 return map { $class->new($_) } @{$dbh->selectall_arrayref(
298 $query,
299 { Slice => {} },
300 $where->{branchcode},
301 $where->{notification},
302 )};
303}
304
- -
308=head3 C4::ItemCirculationAlertPreference->grid({ branchcode => $c, notification => $type })
309
- -
329sub grid {
330 my ($class, $where) = @_;
331 my @branch_prefs = $class->find($where);
332 my @default_prefs = $class->find({ branchcode => '*', notification => $where->{notification} });
333 my @cc = C4::Category->all;
334 my @it = C4::ItemType->all;
335 my $notification = $where->{notification};
336 my %disabled = map {
337 my $key = $_->categorycode . "-" . $_->item_type . "-" . $notification;
338 $key =~ s/\*/_/g;
339 ($key => 1);
340 } @branch_prefs;
341 my %default = map {
342 my $key = $_->categorycode . "-" . $_->item_type . "-" . $notification;
343 $key =~ s/\*/_/g;
344 ($key => 1);
345 } @default_prefs;
346 my @grid;
347 for my $c (@cc) {
348 my $row = { description => $c->description, items => [] };
349 push @grid, $row;
350 for my $i (@it) {
351 my $key = $c->categorycode . "-" . $i->itemtype . "-" . $notification;
352 $key =~ s/\*/_/g;
353 my @classes;
354 my $text = " ";
355 if ($disabled{$key}) {
356 push @classes, 'disabled';
357 $text = "Disabled for $where->{branchcode}";
358 }
359 if ($default{$key}) {
360 push @classes, 'default';
361 $text = "Disabled for all";
362 }
363 push @{$row->{items}}, {
364 class => join(' ', @classes),
365 id => $key,
366 text => $text,
367 };
368 }
369 }
370 return \@grid;
371}
372
- -
376=head2 Object Methods
377
- -
384=head3 $pref->branchcode
385
- -
388=head3 $pref->categorycode
389
- -
392=head3 $pref->item_type
393
- -
396=head3 $pref->notification
397
- -
400sub AUTOLOAD {
401 my $self = shift;
402 my $attr = $AUTOLOAD;
403 $attr =~ s/.*://;
404 if (exists $self->{$attr}) {
405 return $self->{$attr};
406 } else {
407 return;
408 }
409}
410
411sub DESTROY { }
412
- -
415=head1 SEE ALSO
416
- -
42514µs1;