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

Filename/usr/share/koha/lib/C4/Ratings.pm
StatementsExecuted 28 statements in 960µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11131µs43µsC4::Ratings::::BEGIN@21C4::Ratings::BEGIN@21
11131µs57µsC4::Ratings::::BEGIN@22C4::Ratings::BEGIN@22
11130µs4.02msC4::Ratings::::BEGIN@25C4::Ratings::BEGIN@25
11121µs100µsC4::Ratings::::BEGIN@23C4::Ratings::BEGIN@23
11118µs153µsC4::Ratings::::BEGIN@26C4::Ratings::BEGIN@26
11118µs18µsC4::Ratings::::BEGIN@31C4::Ratings::BEGIN@31
11116µs20µsC4::Ratings::::BEGIN@27C4::Ratings::BEGIN@27
11114µs37µsC4::Ratings::::BEGIN@24C4::Ratings::BEGIN@24
11112µs100µsC4::Ratings::::BEGIN@29C4::Ratings::BEGIN@29
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
21394µs256µs
# spent 43µs (31+12) within C4::Ratings::BEGIN@21 which was called: # once (31µs+12µs) by main::BEGIN@54 at line 21
use strict;
# spent 43µs making 1 call to C4::Ratings::BEGIN@21 # spent 12µs making 1 call to strict::import
22356µs284µs
# spent 57µs (31+27) within C4::Ratings::BEGIN@22 which was called: # once (31µs+27µs) by main::BEGIN@54 at line 22
use warnings;
# spent 57µs making 1 call to C4::Ratings::BEGIN@22 # spent 27µs making 1 call to warnings::import
23370µs2178µs
# spent 100µs (21+79) within C4::Ratings::BEGIN@23 which was called: # once (21µs+79µs) by main::BEGIN@54 at line 23
use Carp;
# spent 100µs making 1 call to C4::Ratings::BEGIN@23 # spent 79µs making 1 call to Exporter::import
24346µs260µs
# spent 37µs (14+23) within C4::Ratings::BEGIN@24 which was called: # once (14µs+23µs) by main::BEGIN@54 at line 24
use Exporter;
# spent 37µs making 1 call to C4::Ratings::BEGIN@24 # spent 23µs making 1 call to Exporter::import
25397µs28.01ms
# spent 4.02ms (30µs+3.99) within C4::Ratings::BEGIN@25 which was called: # once (30µs+3.99ms) by main::BEGIN@54 at line 25
use POSIX;
# spent 4.02ms making 1 call to C4::Ratings::BEGIN@25 # spent 3.99ms making 1 call to POSIX::import
26339µs2287µs
# spent 153µs (18+134) within C4::Ratings::BEGIN@26 which was called: # once (18µs+134µs) by main::BEGIN@54 at line 26
use C4::Debug;
# spent 153µs making 1 call to C4::Ratings::BEGIN@26 # spent 134µs making 1 call to Exporter::import
27341µs224µs
# spent 20µs (16+4) within C4::Ratings::BEGIN@27 which was called: # once (16µs+4µs) by main::BEGIN@54 at line 27
use C4::Context;
# spent 20µs making 1 call to C4::Ratings::BEGIN@27 # spent 4µs making 1 call to C4::Context::import
28
29372µs2188µs
# spent 100µs (12+88) within C4::Ratings::BEGIN@29 which was called: # once (12µs+88µ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 88µ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 );
411420µ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
24818µs1;
249__END__