Filename | /usr/share/koha/lib/C4/Ratings.pm |
Statements | Executed 28 statements in 960µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 31µs | 43µs | BEGIN@21 | C4::Ratings::
1 | 1 | 1 | 31µs | 57µs | BEGIN@22 | C4::Ratings::
1 | 1 | 1 | 30µs | 4.02ms | BEGIN@25 | C4::Ratings::
1 | 1 | 1 | 21µs | 100µs | BEGIN@23 | C4::Ratings::
1 | 1 | 1 | 18µs | 153µs | BEGIN@26 | C4::Ratings::
1 | 1 | 1 | 18µs | 18µs | BEGIN@31 | C4::Ratings::
1 | 1 | 1 | 16µs | 20µs | BEGIN@27 | C4::Ratings::
1 | 1 | 1 | 14µs | 37µs | BEGIN@24 | C4::Ratings::
1 | 1 | 1 | 12µs | 100µs | BEGIN@29 | C4::Ratings::
0 | 0 | 0 | 0s | 0s | AddRating | C4::Ratings::
0 | 0 | 0 | 0s | 0s | DelRating | C4::Ratings::
0 | 0 | 0 | 0s | 0s | GetRating | C4::Ratings::
0 | 0 | 0 | 0s | 0s | ModRating | C4::Ratings::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package 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 | |||||
21 | 3 | 94µs | 2 | 56µ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 # spent 43µs making 1 call to C4::Ratings::BEGIN@21
# spent 12µs making 1 call to strict::import |
22 | 3 | 56µs | 2 | 84µ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 # spent 57µs making 1 call to C4::Ratings::BEGIN@22
# spent 27µs making 1 call to warnings::import |
23 | 3 | 70µs | 2 | 178µ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 # spent 100µs making 1 call to C4::Ratings::BEGIN@23
# spent 79µs making 1 call to Exporter::import |
24 | 3 | 46µs | 2 | 60µ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 # spent 37µs making 1 call to C4::Ratings::BEGIN@24
# spent 23µs making 1 call to Exporter::import |
25 | 3 | 97µs | 2 | 8.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 # spent 4.02ms making 1 call to C4::Ratings::BEGIN@25
# spent 3.99ms making 1 call to POSIX::import |
26 | 3 | 39µs | 2 | 287µ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 # spent 153µs making 1 call to C4::Ratings::BEGIN@26
# spent 134µs making 1 call to Exporter::import |
27 | 3 | 41µs | 2 | 24µ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 # spent 20µs making 1 call to C4::Ratings::BEGIN@27
# spent 4µs making 1 call to C4::Context::import |
28 | |||||
29 | 3 | 72µs | 2 | 188µ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 # 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 | ||||
32 | 3 | 17µs | $VERSION = 3.07.00.049; | ||
33 | @ISA = qw(Exporter); | ||||
34 | |||||
35 | @EXPORT = qw( | ||||
36 | &GetRating | ||||
37 | &AddRating | ||||
38 | &ModRating | ||||
39 | &DelRating | ||||
40 | ); | ||||
41 | 1 | 420µs | 1 | 18µs | } # spent 18µs making 1 call to C4::Ratings::BEGIN@31 |
42 | |||||
43 | =head1 NAME | ||||
44 | |||||
- - | |||||
148 | sub GetRating { | ||||
149 | my ( $biblionumber, $borrowernumber ) = @_; | ||||
150 | my $query = qq| SELECT COUNT(*) AS total, SUM(rating_value) AS sum | ||||
151 | FROM 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| | ||||
173 | SELECT 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 | |||||
- - | |||||
200 | sub 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 | |||||
- - | |||||
219 | sub ModRating { | ||||
220 | my ( $biblionumber, $borrowernumber, $rating_value ) = @_; | ||||
221 | my $query = | ||||
222 | qq|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 | |||||
- - | |||||
237 | sub 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 | |||||
248 | 1 | 8µs | 1; | ||
249 | __END__ |