Filename | /home/vagrant/kohaclone/C4/Review.pm |
Statements | Executed 20 statements in 940µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 45µs | 289µs | numberofreviews | C4::Review::
1 | 1 | 1 | 25µs | 39µs | BEGIN@20 | C4::Review::
1 | 1 | 1 | 10µs | 44µs | BEGIN@25 | C4::Review::
1 | 1 | 1 | 10µs | 19µs | BEGIN@21 | C4::Review::
1 | 1 | 1 | 10µs | 12µs | BEGIN@23 | C4::Review::
1 | 1 | 1 | 200ns | 200ns | BEGIN@27 | C4::Review::
0 | 0 | 0 | 0s | 0s | approvereview | C4::Review::
0 | 0 | 0 | 0s | 0s | deletereview | C4::Review::
0 | 0 | 0 | 0s | 0s | getallreviews | C4::Review::
0 | 0 | 0 | 0s | 0s | getreview | C4::Review::
0 | 0 | 0 | 0s | 0s | getreviews | C4::Review::
0 | 0 | 0 | 0s | 0s | numberofreviewsbybiblionumber | C4::Review::
0 | 0 | 0 | 0s | 0s | savereview | C4::Review::
0 | 0 | 0 | 0s | 0s | unapprovereview | C4::Review::
0 | 0 | 0 | 0s | 0s | updatereview | C4::Review::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package C4::Review; | ||||
2 | |||||
3 | # Copyright 2000-2002 Katipo Communications | ||||
4 | # | ||||
5 | # This file is part of Koha. | ||||
6 | # | ||||
7 | # Koha is free software; you can redistribute it and/or modify it | ||||
8 | # under the terms of the GNU General Public License as published by | ||||
9 | # the Free Software Foundation; either version 3 of the License, or | ||||
10 | # (at your option) any later version. | ||||
11 | # | ||||
12 | # Koha is distributed in the hope that it will be useful, but | ||||
13 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | # GNU General Public License for more details. | ||||
16 | # | ||||
17 | # You should have received a copy of the GNU General Public License | ||||
18 | # along with Koha; if not, see <http://www.gnu.org/licenses>. | ||||
19 | |||||
20 | 2 | 52µs | 2 | 52µs | # spent 39µs (25+14) within C4::Review::BEGIN@20 which was called:
# once (25µs+14µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@28 at line 20 # spent 39µs making 1 call to C4::Review::BEGIN@20
# spent 14µs making 1 call to strict::import |
21 | 2 | 38µs | 2 | 29µs | # spent 19µs (10+9) within C4::Review::BEGIN@21 which was called:
# once (10µs+9µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@28 at line 21 # spent 19µs making 1 call to C4::Review::BEGIN@21
# spent 9µs making 1 call to warnings::import |
22 | |||||
23 | 2 | 35µs | 2 | 15µs | # spent 12µs (10+3) within C4::Review::BEGIN@23 which was called:
# once (10µs+3µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@28 at line 23 # spent 12µs making 1 call to C4::Review::BEGIN@23
# spent 3µs making 1 call to C4::Context::import |
24 | |||||
25 | 2 | 102µs | 2 | 77µs | # spent 44µs (10+33) within C4::Review::BEGIN@25 which was called:
# once (10µs+33µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@28 at line 25 # spent 44µs making 1 call to C4::Review::BEGIN@25
# spent 33µs making 1 call to vars::import |
26 | |||||
27 | # spent 200ns within C4::Review::BEGIN@27 which was called:
# once (200ns+0s) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@28 at line 34 | ||||
28 | # set the version for version checking | ||||
29 | 1 | 0s | $VERSION = 3.07.00.049; | ||
30 | 1 | 100ns | require Exporter; | ||
31 | 1 | 0s | @ISA = qw(Exporter); | ||
32 | 1 | 100ns | @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber | ||
33 | getreviews getallreviews approvereview unapprovereview deletereview); | ||||
34 | 1 | 592µs | 1 | 200ns | } # spent 200ns making 1 call to C4::Review::BEGIN@27 |
35 | |||||
36 | =head1 NAME | ||||
37 | |||||
38 | C4::Review - Perl Module containing routines for dealing with reviews of items | ||||
39 | |||||
40 | =head1 SYNOPSIS | ||||
41 | |||||
42 | use C4::Review; | ||||
43 | |||||
44 | my $review=getreview($biblionumber,$borrowernumber); | ||||
45 | savereview($biblionumber,$borrowernumber,$review); | ||||
46 | updatereview($biblionumber,$borrowernumber,$review); | ||||
47 | my $count=numberofreviews($status); | ||||
48 | my $count=numberofreviewsbybiblionumber($biblionumber); | ||||
49 | my $reviews=getreviews($biblionumber, $status); | ||||
50 | my $reviews=getallreviews($status, [$offset], [$row_count]); | ||||
51 | |||||
52 | =head1 DESCRIPTION | ||||
53 | |||||
54 | Review.pm provides many routines for manipulating reviews. | ||||
55 | |||||
56 | =head1 FUNCTIONS | ||||
57 | |||||
58 | =head2 getreview | ||||
59 | |||||
60 | $review = getreview($biblionumber,$borrowernumber); | ||||
61 | |||||
62 | Takes a borrowernumber and a biblionumber and returns the review of that biblio | ||||
63 | |||||
64 | =cut | ||||
65 | |||||
66 | sub getreview { | ||||
67 | my ( $biblionumber, $borrowernumber ) = @_; | ||||
68 | my $dbh = C4::Context->dbh; | ||||
69 | my $query = "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?"; | ||||
70 | my $sth = $dbh->prepare($query); | ||||
71 | $sth->execute( $biblionumber, $borrowernumber ); | ||||
72 | return $sth->fetchrow_hashref(); | ||||
73 | } | ||||
74 | |||||
75 | =head2 savereview | ||||
76 | |||||
77 | savereview($biblionumber,$borrowernumber, $review); | ||||
78 | |||||
79 | Save a review in the 'reviews' database | ||||
80 | |||||
81 | =cut | ||||
82 | |||||
83 | sub savereview { | ||||
84 | my ( $biblionumber, $borrowernumber, $review ) = @_; | ||||
85 | my $dbh = C4::Context->dbh; | ||||
86 | my $query = "INSERT INTO reviews (borrowernumber,biblionumber, | ||||
87 | review,approved,datereviewed) VALUES | ||||
88 | (?,?,?,0,now())"; | ||||
89 | my $sth = $dbh->prepare($query); | ||||
90 | $sth->execute( $borrowernumber, $biblionumber, $review ); | ||||
91 | } | ||||
92 | |||||
93 | =head2 updatereview | ||||
94 | |||||
95 | updateview($biblionumber,$borrowernumber, $review); | ||||
96 | |||||
97 | Update the review description in the 'reviews' database | ||||
98 | |||||
99 | =cut | ||||
100 | |||||
101 | sub updatereview { | ||||
102 | my ( $biblionumber, $borrowernumber, $review ) = @_; | ||||
103 | my $dbh = C4::Context->dbh; | ||||
104 | my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0 WHERE borrowernumber=? and biblionumber=?"; | ||||
105 | my $sth = $dbh->prepare($query); | ||||
106 | $sth->execute( $review, $borrowernumber, $biblionumber ); | ||||
107 | } | ||||
108 | |||||
109 | =head2 numberofreviews | ||||
110 | |||||
111 | my $count=numberofreviews( [$status] ); | ||||
112 | |||||
113 | Return the number of reviews where in the 'reviews' database : 'approved' = $status | ||||
114 | (By default $status = 1) | ||||
115 | |||||
116 | =cut | ||||
117 | |||||
118 | # spent 289µs (45+244) within C4::Review::numberofreviews which was called:
# once (45µs+244µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::__ANON__[/home/vagrant/kohaclone/mainpage.pl:107] at line 65 of mainpage.pl | ||||
119 | 1 | 600ns | my ($param) = @_; | ||
120 | 1 | 500ns | my $status = ( defined($param) ? $param : 1 ); | ||
121 | 1 | 10µs | 1 | 126µs | my $dbh = C4::Context->dbh; # spent 126µs making 1 call to C4::Context::dbh |
122 | 1 | 400ns | my $query = "SELECT count(*) FROM reviews WHERE approved=?"; | ||
123 | 1 | 8µs | 2 | 98µs | my $sth = $dbh->prepare($query); # spent 52µs making 1 call to DBI::db::prepare
# spent 47µs making 1 call to DBD::mysql::db::prepare |
124 | 1 | 63µs | 1 | 55µs | $sth->execute($status); # spent 55µs making 1 call to DBI::st::execute |
125 | 1 | 35µs | 1 | 4µs | return $sth->fetchrow; # spent 4µs making 1 call to DBI::st::fetchrow |
126 | } | ||||
127 | |||||
128 | =head2 numberofreviewsbybiblionumber | ||||
129 | |||||
130 | my $count=numberofreviewsbybiblionumber($biblionumber); | ||||
131 | |||||
132 | Return the number of reviews approved for a given biblionumber | ||||
133 | |||||
134 | =cut | ||||
135 | |||||
136 | sub numberofreviewsbybiblionumber { | ||||
137 | my ($biblionumber) = @_; | ||||
138 | my $dbh = C4::Context->dbh; | ||||
139 | my $query = "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?"; | ||||
140 | my $sth = $dbh->prepare($query); | ||||
141 | $sth->execute( $biblionumber, 1 ); | ||||
142 | return $sth->fetchrow; | ||||
143 | } | ||||
144 | |||||
145 | =head2 getreviews | ||||
146 | |||||
147 | my $reviews=getreviews($biblionumber, $status); | ||||
148 | |||||
149 | Return all reviews where in the 'reviews' database : | ||||
150 | 'biblionumber' = $biblionumber and 'approved' = $status | ||||
151 | |||||
152 | =cut | ||||
153 | |||||
154 | sub getreviews { | ||||
155 | my ( $biblionumber, $approved ) = @_; | ||||
156 | my $dbh = C4::Context->dbh; | ||||
157 | my $query = "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc"; | ||||
158 | my $sth = $dbh->prepare($query); | ||||
159 | $sth->execute( $biblionumber, $approved ); | ||||
160 | return $sth->fetchall_arrayref( {} ); | ||||
161 | } | ||||
162 | |||||
163 | =head2 getallreviews | ||||
164 | |||||
165 | my $reviews=getallreviews($status, [$offset], [$row_count]); | ||||
166 | |||||
167 | Return all reviews where in the 'reviews' database : 'approved' = $status | ||||
168 | |||||
169 | If offset and row_count are fiven, it's return all reviews between the | ||||
170 | $offset position and the ($offset + $row_count) position. | ||||
171 | (By default : $offset = 0 and $row_count = 20) | ||||
172 | |||||
173 | =cut | ||||
174 | |||||
175 | sub getallreviews { | ||||
176 | my ( $status, $offset, $row_count ) = @_; | ||||
177 | my @params = ( $status, ( $offset ? $offset : 0 ), ( $row_count ? $row_count : 20 ) ); | ||||
178 | my $dbh = C4::Context->dbh; | ||||
179 | my $query = "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?"; | ||||
180 | my $sth = $dbh->prepare($query); | ||||
181 | $sth->execute(@params); | ||||
182 | return $sth->fetchall_arrayref( {} ); | ||||
183 | } | ||||
184 | |||||
185 | =head2 approvereview | ||||
186 | |||||
187 | approvereview($reviewid); | ||||
188 | |||||
189 | Takes a reviewid and marks that review approved | ||||
190 | |||||
191 | =cut | ||||
192 | |||||
193 | sub approvereview { | ||||
194 | my ($reviewid) = @_; | ||||
195 | my $dbh = C4::Context->dbh(); | ||||
196 | my $query = "UPDATE reviews | ||||
197 | SET approved=? | ||||
198 | WHERE reviewid=?"; | ||||
199 | my $sth = $dbh->prepare($query); | ||||
200 | $sth->execute( 1, $reviewid ); | ||||
201 | } | ||||
202 | |||||
203 | =head2 unapprovereview | ||||
204 | |||||
205 | unapprovereview($reviewid); | ||||
206 | |||||
207 | Takes a reviewid and marks that review as not approved | ||||
208 | |||||
209 | =cut | ||||
210 | |||||
211 | sub unapprovereview { | ||||
212 | my ($reviewid) = @_; | ||||
213 | my $dbh = C4::Context->dbh(); | ||||
214 | my $query = "UPDATE reviews | ||||
215 | SET approved=? | ||||
216 | WHERE reviewid=?"; | ||||
217 | my $sth = $dbh->prepare($query); | ||||
218 | $sth->execute( 0, $reviewid ); | ||||
219 | } | ||||
220 | |||||
221 | =head2 deletereview | ||||
222 | |||||
223 | deletereview($reviewid); | ||||
224 | |||||
225 | Takes a reviewid and deletes it | ||||
226 | |||||
227 | =cut | ||||
228 | |||||
229 | sub deletereview { | ||||
230 | my ($reviewid) = @_; | ||||
231 | my $dbh = C4::Context->dbh(); | ||||
232 | my $query = "DELETE FROM reviews | ||||
233 | WHERE reviewid=?"; | ||||
234 | my $sth = $dbh->prepare($query); | ||||
235 | $sth->execute($reviewid); | ||||
236 | } | ||||
237 | |||||
238 | 1 | 3µs | 1; | ||
239 | __END__ |