← 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:25 2013

Filename/usr/share/koha/lib/C4/Ratings.pm
StatementsExecuted 28 statements in 738µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11122µs4.08msC4::Ratings::::BEGIN@25C4::Ratings::BEGIN@25
11118µs23µsC4::Ratings::::BEGIN@21C4::Ratings::BEGIN@21
11118µs18µsC4::Ratings::::BEGIN@31C4::Ratings::BEGIN@31
11114µs125µsC4::Ratings::::BEGIN@26C4::Ratings::BEGIN@26
11114µs27µsC4::Ratings::::BEGIN@22C4::Ratings::BEGIN@22
11114µs16µsC4::Ratings::::BEGIN@27C4::Ratings::BEGIN@27
11112µs62µsC4::Ratings::::BEGIN@23C4::Ratings::BEGIN@23
11111µs100µsC4::Ratings::::BEGIN@29C4::Ratings::BEGIN@29
11111µs31µsC4::Ratings::::BEGIN@24C4::Ratings::BEGIN@24
0000s0sC4::Ratings::::AddRatingC4::Ratings::AddRating
0000s0sC4::Ratings::::DelRatingC4::Ratings::DelRating
0000s0sC4::Ratings::::GetRatingC4::Ratings::GetRating
0000s0sC4::Ratings::::ModRatingC4::Ratings::ModRating
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package C4::Ratings;
2
3# Copyright 2011 KohaAloha, NZ
4# Parts copyright 2011, Catalyst IT, NZ.
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
21329µs227µs
# spent 23µs (18+5) within C4::Ratings::BEGIN@21 which was called: # once (18µs+5µs) by main::BEGIN@54 at line 21
use strict;
# spent 23µs making 1 call to C4::Ratings::BEGIN@21 # spent 5µs making 1 call to strict::import
22328µs240µs
# spent 27µs (14+13) within C4::Ratings::BEGIN@22 which was called: # once (14µs+13µs) by main::BEGIN@54 at line 22
use warnings;
# spent 27µs making 1 call to C4::Ratings::BEGIN@22 # spent 13µs making 1 call to warnings::import
23333µs2111µs
# spent 62µs (12+49) within C4::Ratings::BEGIN@23 which was called: # once (12µs+49µs) by main::BEGIN@54 at line 23
use Carp;
# spent 62µs making 1 call to C4::Ratings::BEGIN@23 # spent 49µs making 1 call to Exporter::import
24328µs251µs
# spent 31µs (11+20) within C4::Ratings::BEGIN@24 which was called: # once (11µs+20µs) by main::BEGIN@54 at line 24
use Exporter;
# spent 31µs making 1 call to C4::Ratings::BEGIN@24 # spent 20µs making 1 call to Exporter::import
25365µs28.14ms
# spent 4.08ms (22µs+4.06) within C4::Ratings::BEGIN@25 which was called: # once (22µs+4.06ms) by main::BEGIN@54 at line 25
use POSIX;
# spent 4.08ms making 1 call to C4::Ratings::BEGIN@25 # spent 4.06ms making 1 call to POSIX::import
26337µs2237µs
# spent 125µs (14+111) within C4::Ratings::BEGIN@26 which was called: # once (14µs+111µs) by main::BEGIN@54 at line 26
use C4::Debug;
# spent 125µs making 1 call to C4::Ratings::BEGIN@26 # spent 111µs making 1 call to Exporter::import
27335µs219µs
# spent 16µs (14+2) within C4::Ratings::BEGIN@27 which was called: # once (14µs+2µs) by main::BEGIN@54 at line 27
use C4::Context;
# spent 16µs making 1 call to C4::Ratings::BEGIN@27 # spent 2µs making 1 call to C4::Context::import
28
29368µs2188µs
# spent 100µs (11+89) within C4::Ratings::BEGIN@29 which was called: # once (11µs+89µs) by main::BEGIN@54 at line 29
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
# spent 100µs making 1 call to C4::Ratings::BEGIN@29 # spent 89µs making 1 call to vars::import
30
31
# spent 18µs within C4::Ratings::BEGIN@31 which was called: # once (18µs+0s) by main::BEGIN@54 at line 41
BEGIN {
3211µs $VERSION = 3.07.00.049;
33110µs @ISA = qw(Exporter);
34
3516µs @EXPORT = qw(
36 &GetRating
37 &AddRating
38 &ModRating
39 &DelRating
40 );
411393µs118µs}
# spent 18µs making 1 call to C4::Ratings::BEGIN@31
42
43=head1 NAME
44
- -
148sub GetRating {
149 my ( $biblionumber, $borrowernumber ) = @_;
150 my $query = qq| SELECT COUNT(*) AS total, SUM(rating_value) AS sum
151FROM ratings WHERE biblionumber = ? |;
152
153 my $sth = C4::Context->dbh->prepare($query);
154 $sth->execute($biblionumber);
155 my $res = $sth->fetchrow_hashref();
156
157 my ( $avg, $avg_int ) = 0;
158
159 if ( $res->{sum} and $res->{total} ) {
160 eval { $avg = $res->{sum} / $res->{total} };
161 }
162
163 $avg_int = sprintf( "%.1f", $avg );
164 $avg = sprintf( "%.0f", $avg );
165
166 my %rating_hash;
167 $rating_hash{rating_total} = $res->{total} || 0;
168 $rating_hash{rating_avg} = $avg || 0;
169 $rating_hash{rating_avg_int} = $avg_int ||0;
170
171 if ($borrowernumber) {
172 my $q2 = qq|
173SELECT rating_value FROM ratings WHERE biblionumber = ? AND borrowernumber = ?|;
174 my $sth1 = C4::Context->dbh->prepare($q2);
175 $sth1->execute( $biblionumber, $borrowernumber );
176 my $res1 = $sth1->fetchrow_hashref();
177 $rating_hash{'rating_value'} = $res1->{"rating_value"};
178 }
179 else {
180 $rating_hash{rating_borrowernumber} = undef;
181 $rating_hash{rating_value} = undef;
182 }
183
184#### %rating_hash
185 return \%rating_hash;
186}
187
188=head2 AddRating
189
- -
200sub AddRating {
201 my ( $biblionumber, $borrowernumber, $rating_value ) = @_;
202 my $query =
203 qq| INSERT INTO ratings (borrowernumber,biblionumber,rating_value)
204 VALUES (?,?,?)|;
205 my $sth = C4::Context->dbh->prepare($query);
206 $sth->execute( $borrowernumber, $biblionumber, $rating_value );
207 my $rating = GetRating( $biblionumber, $borrowernumber );
208 return $rating;
209}
210
211=head2 ModRating
212
- -
219sub ModRating {
220 my ( $biblionumber, $borrowernumber, $rating_value ) = @_;
221 my $query =
222qq|UPDATE ratings SET rating_value = ? WHERE borrowernumber = ? AND biblionumber = ?|;
223 my $sth = C4::Context->dbh->prepare($query);
224 $sth->execute( $rating_value, $borrowernumber, $biblionumber );
225 my $rating = GetRating( $biblionumber, $borrowernumber );
226 return $rating;
227}
228
229=head2 DelRating
230
- -
237sub DelRating {
238 my ( $biblionumber, $borrowernumber ) = @_;
239 my $dbh = C4::Context->dbh;
240 my $query =
241 "delete from ratings where borrowernumber = ? and biblionumber = ?";
242 my $sth = C4::Context->dbh->prepare($query);
243 my $rv = $sth->execute( $borrowernumber, $biblionumber );
244 my $rating = GetRating( $biblionumber, undef );
245 return $rating;
246}
247
24816µs1;
249__END__