Filename | /usr/share/koha/lib/C4/Ratings.pm |
Statements | Executed 28 statements in 738µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 22µs | 4.08ms | BEGIN@25 | C4::Ratings::
1 | 1 | 1 | 18µs | 23µs | BEGIN@21 | C4::Ratings::
1 | 1 | 1 | 18µs | 18µs | BEGIN@31 | C4::Ratings::
1 | 1 | 1 | 14µs | 125µs | BEGIN@26 | C4::Ratings::
1 | 1 | 1 | 14µs | 27µs | BEGIN@22 | C4::Ratings::
1 | 1 | 1 | 14µs | 16µs | BEGIN@27 | C4::Ratings::
1 | 1 | 1 | 12µs | 62µs | BEGIN@23 | C4::Ratings::
1 | 1 | 1 | 11µs | 100µs | BEGIN@29 | C4::Ratings::
1 | 1 | 1 | 11µs | 31µs | BEGIN@24 | 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 | 29µs | 2 | 27µ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 # spent 23µs making 1 call to C4::Ratings::BEGIN@21
# spent 5µs making 1 call to strict::import |
22 | 3 | 28µs | 2 | 40µ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 # spent 27µs making 1 call to C4::Ratings::BEGIN@22
# spent 13µs making 1 call to warnings::import |
23 | 3 | 33µs | 2 | 111µ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 # spent 62µs making 1 call to C4::Ratings::BEGIN@23
# spent 49µs making 1 call to Exporter::import |
24 | 3 | 28µs | 2 | 51µ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 # spent 31µs making 1 call to C4::Ratings::BEGIN@24
# spent 20µs making 1 call to Exporter::import |
25 | 3 | 65µs | 2 | 8.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 # spent 4.08ms making 1 call to C4::Ratings::BEGIN@25
# spent 4.06ms making 1 call to POSIX::import |
26 | 3 | 37µs | 2 | 237µ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 # spent 125µs making 1 call to C4::Ratings::BEGIN@26
# spent 111µs making 1 call to Exporter::import |
27 | 3 | 35µs | 2 | 19µ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 # spent 16µs making 1 call to C4::Ratings::BEGIN@27
# spent 2µs making 1 call to C4::Context::import |
28 | |||||
29 | 3 | 68µs | 2 | 188µ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 # 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 | ||||
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 | 393µ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 | 6µs | 1; | ||
249 | __END__ |