← 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 11:58:52 2013
Reported on Tue Oct 15 12:02:17 2013

Filename/usr/share/koha/lib/C4/Members/Messaging.pm
StatementsExecuted 14 statements in 1.01ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11118µs23µsC4::Members::Messaging::::BEGIN@20C4::Members::Messaging::BEGIN@20
11114µs38µsC4::Members::Messaging::::BEGIN@21C4::Members::Messaging::BEGIN@21
11110µs12µsC4::Members::Messaging::::BEGIN@22C4::Members::Messaging::BEGIN@22
1119µs35µsC4::Members::Messaging::::BEGIN@24C4::Members::Messaging::BEGIN@24
1116µs6µsC4::Members::Messaging::::BEGIN@26C4::Members::Messaging::BEGIN@26
0000s0sC4::Members::Messaging::::GetMessagingOptionsC4::Members::Messaging::GetMessagingOptions
0000s0sC4::Members::Messaging::::GetMessagingPreferencesC4::Members::Messaging::GetMessagingPreferences
0000s0sC4::Members::Messaging::::SetMessagingPreferenceC4::Members::Messaging::SetMessagingPreference
0000s0sC4::Members::Messaging::::SetMessagingPreferencesFromDefaultsC4::Members::Messaging::SetMessagingPreferencesFromDefaults
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package C4::Members::Messaging;
2
3# Copyright (C) 2008 LibLime
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
20335µs228µs
# spent 23µs (18+5) within C4::Members::Messaging::BEGIN@20 which was called: # once (18µs+5µs) by C4::Reserves::BEGIN@34 at line 20
use strict;
# spent 23µs making 1 call to C4::Members::Messaging::BEGIN@20 # spent 5µs making 1 call to strict::import
21331µs262µs
# spent 38µs (14+24) within C4::Members::Messaging::BEGIN@21 which was called: # once (14µs+24µs) by C4::Reserves::BEGIN@34 at line 21
use warnings;
# spent 38µs making 1 call to C4::Members::Messaging::BEGIN@21 # spent 24µs making 1 call to warnings::import
22329µs215µs
# spent 12µs (10+2) within C4::Members::Messaging::BEGIN@22 which was called: # once (10µs+2µs) by C4::Reserves::BEGIN@34 at line 22
use C4::Context;
# spent 12µs making 1 call to C4::Members::Messaging::BEGIN@22 # spent 2µs making 1 call to C4::Context::import
23
24345µs260µs
# spent 35µs (9+26) within C4::Members::Messaging::BEGIN@24 which was called: # once (9µs+26µs) by C4::Reserves::BEGIN@34 at line 24
use vars qw($VERSION);
# spent 35µs making 1 call to C4::Members::Messaging::BEGIN@24 # spent 26µs making 1 call to vars::import
25
26
# spent 6µs within C4::Members::Messaging::BEGIN@26 which was called: # once (6µs+0s) by C4::Reserves::BEGIN@34 at line 29
BEGIN {
27 # set the version for version checking
2816µs $VERSION = 3.07.00.049;
291865µs16µs}
# spent 6µs making 1 call to C4::Members::Messaging::BEGIN@26
30
31=head1 NAME
32
- -
59sub GetMessagingPreferences {
60 my $params = shift;
61
62 return unless exists $params->{message_name};
63 return unless exists $params->{borrowernumber} xor exists $params->{categorycode}; # yes, xor
64 my $sql = <<'END_SQL';
65SELECT borrower_message_preferences.*,
66 borrower_message_transport_preferences.message_transport_type,
67 message_attributes.message_name,
68 message_attributes.takes_days,
69 message_transports.is_digest,
70 message_transports.letter_module,
71 message_transports.letter_code
72FROM borrower_message_preferences
73LEFT JOIN borrower_message_transport_preferences
74ON borrower_message_transport_preferences.borrower_message_preference_id = borrower_message_preferences.borrower_message_preference_id
75LEFT JOIN message_attributes
76ON message_attributes.message_attribute_id = borrower_message_preferences.message_attribute_id
77JOIN message_transports
78ON message_transports.message_attribute_id = message_attributes.message_attribute_id
79AND message_transports.message_transport_type = borrower_message_transport_preferences.message_transport_type
80WHERE message_attributes.message_name = ?
81END_SQL
82
83 my @bind_params = ( $params->{'message_name'} );
84 if ( exists $params->{'borrowernumber'} ) {
85 $sql .= " AND borrower_message_preferences.borrowernumber = ? ";
86 push @bind_params, $params->{borrowernumber};
87 } else {
88 $sql .= " AND borrower_message_preferences.categorycode = ? ";
89 push @bind_params, $params->{categorycode};
90 }
91
92 my $sth = C4::Context->dbh->prepare($sql);
93 $sth->execute(@bind_params);
94 my $return;
95 my %transports; # helps build a list of unique message_transport_types
96 ROW: while ( my $row = $sth->fetchrow_hashref() ) {
97 next ROW unless $row->{'message_attribute_id'};
98 $return->{'days_in_advance'} = $row->{'days_in_advance'} if defined $row->{'days_in_advance'};
99 $return->{'wants_digest'} = $row->{'wants_digest'} if defined $row->{'wants_digest'};
100 $return->{'letter_code'} = $row->{'letter_code'};
101 $return->{'transports'}->{ $row->{'message_transport_type'} } = $row->{'letter_code'};
102 }
103 return $return;
104}
105
106=head2 SetMessagingPreference
107
- -
123sub SetMessagingPreference {
124 my $params = shift;
125
126 unless (exists $params->{borrowernumber} xor exists $params->{categorycode}) { # yes, xor
127 warn "SetMessagingPreference called without exactly one of borrowernumber or categorycode";
128 return;
129 }
130 foreach my $required ( qw( message_attribute_id message_transport_types ) ) {
131 if ( ! exists $params->{ $required } ) {
132 warn "SetMessagingPreference called without required parameter: $required";
133 return;
134 }
135 }
136 $params->{'days_in_advance'} = undef unless exists ( $params->{'days_in_advance'} );
137 $params->{'wants_digest'} = 0 unless exists ( $params->{'wants_digest'} );
138
139 my $dbh = C4::Context->dbh();
140
141 my $delete_sql = <<'END_SQL';
142DELETE FROM borrower_message_preferences
143 WHERE message_attribute_id = ?
144END_SQL
145 my @bind_params = ( $params->{'message_attribute_id'} );
146 if ( exists $params->{'borrowernumber'} ) {
147 $delete_sql .= " AND borrowernumber = ? ";
148 push @bind_params, $params->{borrowernumber};
149 } else {
150 $delete_sql .= " AND categorycode = ? ";
151 push @bind_params, $params->{categorycode};
152 }
153 my $sth = $dbh->prepare( $delete_sql );
154 my $deleted = $sth->execute( @bind_params );
155
156 if ( $params->{'message_transport_types'} ) {
157 my $insert_bmp = <<'END_SQL';
158INSERT INTO borrower_message_preferences
159(borrower_message_preference_id, borrowernumber, categorycode, message_attribute_id, days_in_advance, wants_digest)
160VALUES
161(NULL, ?, ?, ?, ?, ?)
162END_SQL
163
164 $sth = C4::Context->dbh()->prepare($insert_bmp);
165 # set up so that we can easily construct the insert SQL
166 $params->{'borrowernumber'} = undef unless exists ( $params->{'borrowernumber'} );
167 $params->{'categorycode'} = undef unless exists ( $params->{'categorycode'} );
168 my $success = $sth->execute( $params->{'borrowernumber'},
169 $params->{'categorycode'},
170 $params->{'message_attribute_id'},
171 $params->{'days_in_advance'},
172 $params->{'wants_digest'} );
173 # my $borrower_message_preference_id = $dbh->last_insert_id();
174 my $borrower_message_preference_id = $dbh->{'mysql_insertid'};
175
176 my $insert_bmtp = <<'END_SQL';
177INSERT INTO borrower_message_transport_preferences
178(borrower_message_preference_id, message_transport_type)
179VALUES
180(?, ?)
181END_SQL
182 $sth = C4::Context->dbh()->prepare($insert_bmtp);
183 foreach my $transport ( @{$params->{'message_transport_types'}}) {
184 my $success = $sth->execute( $borrower_message_preference_id, $transport );
185 }
186 }
187 return;
188}
189
190=head2 GetMessagingOptions
191
- -
198sub GetMessagingOptions {
199
200 my $sql = <<'END_SQL';
201select message_attributes.message_attribute_id, takes_days, message_name, message_transport_type, is_digest
202 FROM message_attributes
203 LEFT JOIN message_transports
204 ON message_attributes.message_attribute_id = message_transports.message_attribute_id
205END_SQL
206
207 my $sth = C4::Context->dbh->prepare($sql);
208 $sth->execute();
209 my $choices;
210 while ( my $row = $sth->fetchrow_hashref() ) {
211 $choices->{ $row->{'message_name'} }->{'message_attribute_id'} = $row->{'message_attribute_id'};
212 $choices->{ $row->{'message_name'} }->{'message_name'} = $row->{'message_name'};
213 $choices->{ $row->{'message_name'} }->{'takes_days'} = $row->{'takes_days'};
214 $choices->{ $row->{'message_name'} }->{'has_digest'} = 1 if $row->{'is_digest'};
215 $choices->{ $row->{'message_name'} }->{'transport_' . $row->{'message_transport_type'}} = ' ';
216 }
217
218 my @return = values %$choices;
219 # warn( Data::Dumper->Dump( [ \@return ], [ 'return' ] ) );
220 return \@return;
221}
222
223=head2 SetMessagingPreferencesFromDefaults
224
- -
234sub SetMessagingPreferencesFromDefaults {
235 my $params = shift;
236
237 foreach my $required ( qw( borrowernumber categorycode ) ) {
238 unless ( exists $params->{ $required } ) {
239 die "SetMessagingPreferencesFromDefaults called without required parameter: $required";
240 }
241 }
242
243 my $messaging_options = GetMessagingOptions();
244 OPTION: foreach my $option ( @$messaging_options ) {
245 my $default_pref = GetMessagingPreferences( { categorycode => $params->{categorycode},
246 message_name => $option->{'message_name'} } );
247 # FIXME - except for setting the borrowernumber, it really ought to be possible
248 # to have the output of GetMessagingPreferences be able to be the input
249 # to SetMessagingPreference
250 my @message_transport_types = keys %{ $default_pref->{transports} };
251 $default_pref->{message_attribute_id} = $option->{'message_attribute_id'};
252 $default_pref->{message_transport_types} = \@message_transport_types;
253 $default_pref->{borrowernumber} = $params->{borrowernumber};
254 SetMessagingPreference( $default_pref );
255 }
256}
257
258=head1 TABLES
259
- -
31713µs1;