Filename | /usr/share/koha/lib/C4/Branch.pm |
Statements | Executed 1745 statements in 419ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
27 | 3 | 3 | 13.5ms | 372ms | GetBranches | C4::Branch::
64 | 1 | 1 | 4.99ms | 141ms | GetBranchName | C4::Branch::
2 | 2 | 2 | 217µs | 4.22ms | GetBranchCategories | C4::Branch::
1 | 1 | 1 | 149µs | 22.3ms | GetBranchesLoop | C4::Branch::
1 | 1 | 1 | 65µs | 2.05ms | GetBranchesCount | C4::Branch::
1 | 1 | 1 | 46µs | 46µs | CORE:sort (opcode) | C4::Branch::
1 | 1 | 1 | 34µs | 45µs | BEGIN@19 | C4::Branch::
1 | 1 | 1 | 20µs | 20µs | BEGIN@26 | C4::Branch::
1 | 1 | 1 | 18µs | 2.34ms | onlymine | C4::Branch::
1 | 1 | 1 | 12µs | 107µs | BEGIN@24 | C4::Branch::
1 | 1 | 1 | 12µs | 14µs | BEGIN@22 | C4::Branch::
0 | 0 | 0 | 0s | 0s | CheckBranchCategorycode | C4::Branch::
0 | 0 | 0 | 0s | 0s | CheckCategoryUnique | C4::Branch::
0 | 0 | 0 | 0s | 0s | DelBranch | C4::Branch::
0 | 0 | 0 | 0s | 0s | DelBranchCategory | C4::Branch::
0 | 0 | 0 | 0s | 0s | GetBranch | C4::Branch::
0 | 0 | 0 | 0s | 0s | GetBranchCategory | C4::Branch::
0 | 0 | 0 | 0s | 0s | GetBranchDetail | C4::Branch::
0 | 0 | 0 | 0s | 0s | GetBranchInfo | C4::Branch::
0 | 0 | 0 | 0s | 0s | GetBranchesInCategory | C4::Branch::
0 | 0 | 0 | 0s | 0s | GetCategoryTypes | C4::Branch::
0 | 0 | 0 | 0s | 0s | ModBranch | C4::Branch::
0 | 0 | 0 | 0s | 0s | ModBranchCategoryInfo | C4::Branch::
0 | 0 | 0 | 0s | 0s | get_branch_code_from_name | C4::Branch::
0 | 0 | 0 | 0s | 0s | mybranch | C4::Branch::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package C4::Branch; | ||||
2 | |||||
3 | # This file is part of Koha. | ||||
4 | # | ||||
5 | # Koha is free software; you can redistribute it and/or modify it under the | ||||
6 | # terms of the GNU General Public License as published by the Free Software | ||||
7 | # Foundation; either version 2 of the License, or (at your option) any later | ||||
8 | # version. | ||||
9 | # | ||||
10 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
11 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||||
12 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||
13 | # | ||||
14 | # You should have received a copy of the GNU General Public License along with | ||||
15 | # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, | ||||
16 | # Suite 330, Boston, MA 02111-1307 USA | ||||
17 | |||||
18 | |||||
19 | 3 | 47µs | 2 | 57µs | # spent 45µs (34+12) within C4::Branch::BEGIN@19 which was called:
# once (34µs+12µs) by C4::Auth::BEGIN@30 at line 19 # spent 45µs making 1 call to C4::Branch::BEGIN@19
# spent 12µs making 1 call to strict::import |
20 | #use warnings; FIXME - Bug 2505 | ||||
21 | 1 | 2µs | require Exporter; | ||
22 | 3 | 33µs | 2 | 16µs | # spent 14µs (12+2) within C4::Branch::BEGIN@22 which was called:
# once (12µs+2µs) by C4::Auth::BEGIN@30 at line 22 # spent 14µs making 1 call to C4::Branch::BEGIN@22
# spent 2µs making 1 call to C4::Context::import |
23 | |||||
24 | 3 | 92µs | 2 | 201µs | # spent 107µs (12+94) within C4::Branch::BEGIN@24 which was called:
# once (12µs+94µs) by C4::Auth::BEGIN@30 at line 24 # spent 107µs making 1 call to C4::Branch::BEGIN@24
# spent 94µs making 1 call to vars::import |
25 | |||||
26 | # spent 20µs within C4::Branch::BEGIN@26 which was called:
# once (20µs+0s) by C4::Auth::BEGIN@30 at line 52 | ||||
27 | # set the version for version checking | ||||
28 | 4 | 143µs | $VERSION = 3.07.00.049; | ||
29 | @ISA = qw(Exporter); | ||||
30 | @EXPORT = qw( | ||||
31 | &GetBranchCategory | ||||
32 | &GetBranchName | ||||
33 | &GetBranch | ||||
34 | &GetBranches | ||||
35 | &GetBranchesLoop | ||||
36 | &GetBranchDetail | ||||
37 | &get_branchinfos_of | ||||
38 | &ModBranch | ||||
39 | &CheckBranchCategorycode | ||||
40 | &GetBranchInfo | ||||
41 | &GetCategoryTypes | ||||
42 | &GetBranchCategories | ||||
43 | &GetBranchesInCategory | ||||
44 | &ModBranchCategoryInfo | ||||
45 | &DelBranch | ||||
46 | &DelBranchCategory | ||||
47 | &CheckCategoryUnique | ||||
48 | &mybranch | ||||
49 | &GetBranchesCount | ||||
50 | ); | ||||
51 | @EXPORT_OK = qw( &onlymine &mybranch get_branch_code_from_name ); | ||||
52 | 1 | 2.10ms | 1 | 20µs | } # spent 20µs making 1 call to C4::Branch::BEGIN@26 |
53 | |||||
54 | =head1 NAME | ||||
55 | |||||
- - | |||||
104 | # spent 372ms (13.5+358) within C4::Branch::GetBranches which was called 27 times, avg 13.8ms/call:
# 25 times (12.2ms+328ms) by C4::XSLT::buildKohaItemsNamespace at line 257 of /usr/share/koha/lib/C4/XSLT.pm, avg 13.6ms/call
# once (735µs+19.0ms) by C4::Branch::GetBranchesLoop at line 161
# once (515µs+11.6ms) by main::RUNTIME at line 195 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
105 | 1161 | 341ms | my ($onlymine)=@_; | ||
106 | # returns a reference to a hash of references to ALL branches... | ||||
107 | my %branches; | ||||
108 | 27 | 25.9ms | my $dbh = C4::Context->dbh; # spent 25.9ms making 27 calls to C4::Context::dbh, avg 958µs/call | ||
109 | my $sth; | ||||
110 | my $query="SELECT * FROM branches"; | ||||
111 | my @bind_parameters; | ||||
112 | if ($onlymine && C4::Context->userenv && C4::Context->userenv->{branch}){ | ||||
113 | $query .= ' WHERE branchcode = ? '; | ||||
114 | push @bind_parameters, C4::Context->userenv->{branch}; | ||||
115 | } | ||||
116 | $query.=" ORDER BY branchname"; | ||||
117 | 1 | 178µs | 54 | 4.76ms | $sth = $dbh->prepare($query); # spent 2.60ms making 27 calls to DBI::db::prepare, avg 96µs/call
# spent 2.16ms making 27 calls to DBD::mysql::db::prepare, avg 80µs/call |
118 | 27 | 29.5ms | $sth->execute( @bind_parameters ); # spent 29.5ms making 27 calls to DBI::st::execute, avg 1.09ms/call | ||
119 | |||||
120 | 1 | 279µs | 54 | 4.80ms | my $nsth = $dbh->prepare( # spent 2.59ms making 27 calls to DBI::db::prepare, avg 96µs/call
# spent 2.21ms making 27 calls to DBD::mysql::db::prepare, avg 82µs/call |
121 | "SELECT categorycode FROM branchrelations WHERE branchcode = ?" | ||||
122 | ); # prepare once, outside while loop | ||||
123 | |||||
124 | 891 | 24.4ms | while ( my $branch = $sth->fetchrow_hashref ) { # spent 18.0ms making 297 calls to DBI::st::fetchrow_hashref, avg 61µs/call
# spent 3.76ms making 297 calls to DBI::st::fetch, avg 13µs/call
# spent 2.65ms making 297 calls to DBI::common::FETCH, avg 9µs/call | ||
125 | 270 | 275ms | $nsth->execute( $branch->{'branchcode'} ); # spent 275ms making 270 calls to DBI::st::execute, avg 1.02ms/call | ||
126 | 270 | 3.84ms | while ( my ($cat) = $nsth->fetchrow_array ) { # spent 3.84ms making 270 calls to DBI::st::fetchrow_array, avg 14µs/call | ||
127 | # FIXME - This seems wrong. It ought to be | ||||
128 | # $branch->{categorycodes}{$cat} = 1; | ||||
129 | # otherwise, there's a namespace collision if there's a | ||||
130 | # category with the same name as a field in the 'branches' | ||||
131 | # table (i.e., don't create a category called "issuing"). | ||||
132 | # In addition, the current structure doesn't really allow | ||||
133 | # you to list the categories that a branch belongs to: | ||||
134 | # you'd have to list keys %$branch, and remove those keys | ||||
135 | # that aren't fields in the "branches" table. | ||||
136 | # $branch->{$cat} = 1; | ||||
137 | $branch->{category}{$cat} = 1; | ||||
138 | } | ||||
139 | $branches{ $branch->{'branchcode'} } = $branch; | ||||
140 | } | ||||
141 | return ( \%branches ); | ||||
142 | } | ||||
143 | |||||
144 | # spent 2.34ms (18µs+2.32) within C4::Branch::onlymine which was called:
# once (18µs+2.32ms) by C4::Branch::GetBranchesLoop at line 160 | ||||
145 | return | ||||
146 | 1 | 15µs | 1 | 2.32ms | C4::Context->preference('IndependantBranches') && # spent 2.32ms making 1 call to C4::Context::preference |
147 | C4::Context->userenv && | ||||
148 | C4::Context->userenv->{flags} %2 != 1 && | ||||
149 | C4::Context->userenv->{branch} ; | ||||
150 | } | ||||
151 | |||||
152 | # always returns a string for OK comparison via "eq" or "ne" | ||||
153 | sub mybranch { | ||||
154 | C4::Context->userenv or return ''; | ||||
155 | return C4::Context->userenv->{branch} || ''; | ||||
156 | } | ||||
157 | |||||
158 | # spent 22.3ms (149µs+22.1) within C4::Branch::GetBranchesLoop which was called:
# once (149µs+22.1ms) by C4::Auth::get_template_and_user at line 381 of /usr/share/koha/lib/C4/Auth.pm | ||||
159 | 16 | 227µs | my $branch = @_ ? shift : mybranch(); # optional first argument is branchcode of "my branch", if preselection is wanted. | ||
160 | 1 | 2.34ms | my $onlymine = @_ ? shift : onlymine(); # spent 2.34ms making 1 call to C4::Branch::onlymine | ||
161 | 7 | 19.8ms | my $branches = GetBranches($onlymine); # spent 19.7ms making 1 call to C4::Branch::GetBranches
# spent 20µs making 4 calls to DBI::common::DESTROY, avg 5µs/call
# spent 18µs making 2 calls to DBD::_mem::common::DESTROY, avg 9µs/call | ||
162 | my @loop; | ||||
163 | 1 | 46µs | foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) { # spent 46µs making 1 call to C4::Branch::CORE:sort | ||
164 | push @loop, { | ||||
165 | value => $branchcode, | ||||
166 | branchcode => $branchcode, | ||||
167 | selected => ($branchcode eq $branch) ? 1 : 0, | ||||
168 | branchname => $branches->{$branchcode}->{branchname}, | ||||
169 | }; | ||||
170 | } | ||||
171 | return \@loop; | ||||
172 | } | ||||
173 | |||||
174 | =head2 GetBranchName | ||||
175 | |||||
- - | |||||
178 | # spent 141ms (4.99+136) within C4::Branch::GetBranchName which was called 64 times, avg 2.20ms/call:
# 64 times (4.99ms+136ms) by C4::Biblio::GetAuthorisedValueDesc at line 1580 of /usr/share/koha/lib/C4/Biblio.pm, avg 2.20ms/call | ||||
179 | 512 | 70.8ms | my ($branchcode) = @_; | ||
180 | 64 | 63.5ms | my $dbh = C4::Context->dbh; # spent 63.5ms making 64 calls to C4::Context::dbh, avg 993µs/call | ||
181 | my $sth; | ||||
182 | 1 | 404µs | 128 | 11.7ms | $sth = $dbh->prepare("Select branchname from branches where branchcode=?"); # spent 6.32ms making 64 calls to DBI::db::prepare, avg 99µs/call
# spent 5.41ms making 64 calls to DBD::mysql::db::prepare, avg 85µs/call |
183 | 64 | 63.1ms | $sth->execute($branchcode); # spent 63.1ms making 64 calls to DBI::st::execute, avg 986µs/call | ||
184 | 64 | 1.11ms | my $branchname = $sth->fetchrow_array; # spent 1.11ms making 64 calls to DBI::st::fetchrow_array, avg 17µs/call | ||
185 | 64 | 535µs | $sth->finish; # spent 535µs making 64 calls to DBI::st::finish, avg 8µs/call | ||
186 | return ($branchname); | ||||
187 | } | ||||
188 | |||||
189 | =head2 ModBranch | ||||
190 | |||||
- - | |||||
199 | sub ModBranch { | ||||
200 | my ($data) = @_; | ||||
201 | |||||
202 | my $dbh = C4::Context->dbh; | ||||
203 | if ($data->{add}) { | ||||
204 | my $query = " | ||||
205 | INSERT INTO branches | ||||
206 | (branchcode,branchname,branchaddress1, | ||||
207 | branchaddress2,branchaddress3,branchzip,branchcity,branchstate, | ||||
208 | branchcountry,branchphone,branchfax,branchemail, | ||||
209 | branchurl,branchip,branchprinter,branchnotes,opac_info) | ||||
210 | VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) | ||||
211 | "; | ||||
212 | my $sth = $dbh->prepare($query); | ||||
213 | $sth->execute( | ||||
214 | $data->{'branchcode'}, $data->{'branchname'}, | ||||
215 | $data->{'branchaddress1'}, $data->{'branchaddress2'}, | ||||
216 | $data->{'branchaddress3'}, $data->{'branchzip'}, | ||||
217 | $data->{'branchcity'}, $data->{'branchstate'}, | ||||
218 | $data->{'branchcountry'}, | ||||
219 | $data->{'branchphone'}, $data->{'branchfax'}, | ||||
220 | $data->{'branchemail'}, $data->{'branchurl'}, | ||||
221 | $data->{'branchip'}, $data->{'branchprinter'}, | ||||
222 | $data->{'branchnotes'}, $data->{opac_info}, | ||||
223 | ); | ||||
224 | return 1 if $dbh->err; | ||||
225 | } else { | ||||
226 | my $query = " | ||||
227 | UPDATE branches | ||||
228 | SET branchname=?,branchaddress1=?, | ||||
229 | branchaddress2=?,branchaddress3=?,branchzip=?, | ||||
230 | branchcity=?,branchstate=?,branchcountry=?,branchphone=?, | ||||
231 | branchfax=?,branchemail=?,branchurl=?,branchip=?, | ||||
232 | branchprinter=?,branchnotes=?,opac_info=? | ||||
233 | WHERE branchcode=? | ||||
234 | "; | ||||
235 | my $sth = $dbh->prepare($query); | ||||
236 | $sth->execute( | ||||
237 | $data->{'branchname'}, | ||||
238 | $data->{'branchaddress1'}, $data->{'branchaddress2'}, | ||||
239 | $data->{'branchaddress3'}, $data->{'branchzip'}, | ||||
240 | $data->{'branchcity'}, $data->{'branchstate'}, | ||||
241 | $data->{'branchcountry'}, | ||||
242 | $data->{'branchphone'}, $data->{'branchfax'}, | ||||
243 | $data->{'branchemail'}, $data->{'branchurl'}, | ||||
244 | $data->{'branchip'}, $data->{'branchprinter'}, | ||||
245 | $data->{'branchnotes'}, $data->{opac_info}, | ||||
246 | $data->{'branchcode'}, | ||||
247 | ); | ||||
248 | } | ||||
249 | # sort out the categories.... | ||||
250 | my @checkedcats; | ||||
251 | my $cats = GetBranchCategory(); | ||||
252 | foreach my $cat (@$cats) { | ||||
253 | my $code = $cat->{'categorycode'}; | ||||
254 | if ( $data->{$code} ) { | ||||
255 | push( @checkedcats, $code ); | ||||
256 | } | ||||
257 | } | ||||
258 | my $branchcode = uc( $data->{'branchcode'} ); | ||||
259 | my $branch = GetBranchInfo($branchcode); | ||||
260 | $branch = $branch->[0]; | ||||
261 | my $branchcats = $branch->{'categories'}; | ||||
262 | my @addcats; | ||||
263 | my @removecats; | ||||
264 | foreach my $bcat (@$branchcats) { | ||||
265 | |||||
266 | unless ( grep { /^$bcat$/ } @checkedcats ) { | ||||
267 | push( @removecats, $bcat ); | ||||
268 | } | ||||
269 | } | ||||
270 | foreach my $ccat (@checkedcats) { | ||||
271 | unless ( grep { /^$ccat$/ } @$branchcats ) { | ||||
272 | push( @addcats, $ccat ); | ||||
273 | } | ||||
274 | } | ||||
275 | foreach my $cat (@addcats) { | ||||
276 | my $sth = | ||||
277 | $dbh->prepare( | ||||
278 | "insert into branchrelations (branchcode, categorycode) values(?, ?)" | ||||
279 | ); | ||||
280 | $sth->execute( $branchcode, $cat ); | ||||
281 | $sth->finish; | ||||
282 | } | ||||
283 | foreach my $cat (@removecats) { | ||||
284 | my $sth = | ||||
285 | $dbh->prepare( | ||||
286 | "delete from branchrelations where branchcode=? and categorycode=?" | ||||
287 | ); | ||||
288 | $sth->execute( $branchcode, $cat ); | ||||
289 | $sth->finish; | ||||
290 | } | ||||
291 | } | ||||
292 | |||||
293 | =head2 GetBranchCategory | ||||
294 | |||||
- - | |||||
301 | sub GetBranchCategory { | ||||
302 | |||||
303 | # returns a reference to an array of hashes containing branches, | ||||
304 | my ($catcode) = @_; | ||||
305 | my $dbh = C4::Context->dbh; | ||||
306 | my $sth; | ||||
307 | |||||
308 | # print DEBUG "GetBranchCategory: entry: catcode=".cvs($catcode)."\n"; | ||||
309 | if ($catcode) { | ||||
310 | $sth = | ||||
311 | $dbh->prepare( | ||||
312 | "select * from branchcategories where categorycode = ?"); | ||||
313 | $sth->execute($catcode); | ||||
314 | } | ||||
315 | else { | ||||
316 | $sth = $dbh->prepare("Select * from branchcategories"); | ||||
317 | $sth->execute(); | ||||
318 | } | ||||
319 | my @results; | ||||
320 | while ( my $data = $sth->fetchrow_hashref ) { | ||||
321 | push( @results, $data ); | ||||
322 | } | ||||
323 | $sth->finish; | ||||
324 | |||||
325 | # print DEBUG "GetBranchCategory: exit: returning ".cvs(\@results)."\n"; | ||||
326 | return \@results; | ||||
327 | } | ||||
328 | |||||
329 | =head2 GetBranchCategories | ||||
330 | |||||
- - | |||||
340 | # spent 4.22ms (217µs+4.00) within C4::Branch::GetBranchCategories which was called 2 times, avg 2.11ms/call:
# once (127µs+2.12ms) by C4::Auth::get_template_and_user at line 381 of /usr/share/koha/lib/C4/Auth.pm
# once (91µs+1.88ms) by main::RUNTIME at line 196 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
341 | 34 | 2.41ms | my ( $branchcode, $categorytype, $show_in_pulldown, $selected_in_pulldown ) = @_; | ||
342 | 2 | 1.44ms | my $dbh = C4::Context->dbh(); # spent 1.44ms making 2 calls to C4::Context::dbh, avg 722µs/call | ||
343 | |||||
344 | my $query = "SELECT c.* FROM branchcategories c"; | ||||
345 | my ( @where, @bind ); | ||||
346 | |||||
347 | if( $branchcode ) { | ||||
348 | $query .= ",branchrelations r, branches b "; | ||||
349 | push @where, "c.categorycode = r.categorycode AND r.branchcode = ? "; | ||||
350 | push @bind , $branchcode; | ||||
351 | } | ||||
352 | |||||
353 | if ( $categorytype ) { | ||||
354 | push @where, " c.categorytype = ? "; | ||||
355 | push @bind, $categorytype; | ||||
356 | } | ||||
357 | |||||
358 | if ( defined( $show_in_pulldown ) ) { | ||||
359 | push( @where, " c.show_in_pulldown = ? " ); | ||||
360 | push( @bind, $show_in_pulldown ); | ||||
361 | } | ||||
362 | |||||
363 | $query .= " WHERE " . join(" AND ", @where) if(@where); | ||||
364 | $query .= " ORDER BY categorytype,c.categorycode"; | ||||
365 | 1 | 11µs | 4 | 358µs | my $sth=$dbh->prepare( $query); # spent 192µs making 2 calls to DBI::db::prepare, avg 96µs/call
# spent 166µs making 2 calls to DBD::mysql::db::prepare, avg 83µs/call |
366 | 2 | 2.07ms | $sth->execute(@bind); # spent 2.07ms making 2 calls to DBI::st::execute, avg 1.04ms/call | ||
367 | |||||
368 | 1 | 43µs | 4 | 456µs | my $branchcats = $sth->fetchall_arrayref({}); # spent 255µs making 2 calls to DBI::st::fetchall_arrayref, avg 127µs/call
# spent 202µs making 2 calls to DBD::_::st::fetchall_arrayref, avg 101µs/call |
369 | 2 | 14µs | $sth->finish(); # spent 14µs making 2 calls to DBI::st::finish, avg 7µs/call | ||
370 | |||||
371 | if ( $selected_in_pulldown ) { | ||||
372 | foreach my $bc ( @$branchcats ) { | ||||
373 | $bc->{'selected'} = 1 if ( $bc->{'categorycode'} eq $selected_in_pulldown ); | ||||
374 | } | ||||
375 | } | ||||
376 | |||||
377 | return( $branchcats ); | ||||
378 | } | ||||
379 | |||||
380 | =head2 GetCategoryTypes | ||||
381 | |||||
- - | |||||
392 | #TODO manage category types. rename possibly to 'agency domains' ? as borrowergroups are called categories. | ||||
393 | sub GetCategoryTypes { | ||||
394 | return ( 'searchdomain','properties'); | ||||
395 | } | ||||
396 | |||||
397 | =head2 GetBranch | ||||
398 | |||||
- - | |||||
403 | sub GetBranch { | ||||
404 | my ( $query, $branches ) = @_; # get branch for this query from branches | ||||
405 | my $branch = $query->param('branch'); | ||||
406 | my %cookie = $query->cookie('userenv'); | ||||
407 | ($branch) || ($branch = $cookie{'branchname'}); | ||||
408 | ( $branches->{$branch} ) || ( $branch = ( keys %$branches )[0] ); | ||||
409 | return $branch; | ||||
410 | } | ||||
411 | |||||
412 | =head2 GetBranchDetail | ||||
413 | |||||
- - | |||||
421 | sub GetBranchDetail { | ||||
422 | my ($branchcode) = shift or return; | ||||
423 | my $sth = C4::Context->dbh->prepare("SELECT * FROM branches WHERE branchcode = ?"); | ||||
424 | $sth->execute($branchcode); | ||||
425 | return $sth->fetchrow_hashref(); | ||||
426 | } | ||||
427 | |||||
428 | =head2 GetBranchesInCategory | ||||
429 | |||||
- - | |||||
436 | sub GetBranchesInCategory { | ||||
437 | my ($categorycode) = @_; | ||||
438 | my @branches; | ||||
439 | my $dbh = C4::Context->dbh(); | ||||
440 | my $sth=$dbh->prepare( "SELECT b.branchcode FROM branchrelations r, branches b | ||||
441 | where r.branchcode=b.branchcode and r.categorycode=?"); | ||||
442 | $sth->execute($categorycode); | ||||
443 | while (my $branch = $sth->fetchrow) { | ||||
444 | push @branches, $branch; | ||||
445 | } | ||||
446 | $sth->finish(); | ||||
447 | return( \@branches ); | ||||
448 | } | ||||
449 | |||||
450 | =head2 GetBranchInfo | ||||
451 | |||||
- - | |||||
459 | sub GetBranchInfo { | ||||
460 | my ($branchcode,$categorytype) = @_; | ||||
461 | my $dbh = C4::Context->dbh; | ||||
462 | my $sth; | ||||
463 | |||||
464 | |||||
465 | if ($branchcode) { | ||||
466 | $sth = | ||||
467 | $dbh->prepare( | ||||
468 | "Select * from branches where branchcode = ? order by branchcode"); | ||||
469 | $sth->execute($branchcode); | ||||
470 | } | ||||
471 | else { | ||||
472 | $sth = $dbh->prepare("Select * from branches order by branchcode"); | ||||
473 | $sth->execute(); | ||||
474 | } | ||||
475 | my @results; | ||||
476 | while ( my $data = $sth->fetchrow_hashref ) { | ||||
477 | my @bind = ($data->{'branchcode'}); | ||||
478 | my $query= "select r.categorycode from branchrelations r"; | ||||
479 | $query .= ", branchcategories c " if($categorytype); | ||||
480 | $query .= " where branchcode=? "; | ||||
481 | if($categorytype) { | ||||
482 | $query .= " and c.categorytype=? and r.categorycode=c.categorycode"; | ||||
483 | push @bind, $categorytype; | ||||
484 | } | ||||
485 | my $nsth=$dbh->prepare($query); | ||||
486 | $nsth->execute( @bind ); | ||||
487 | my @cats = (); | ||||
488 | while ( my ($cat) = $nsth->fetchrow_array ) { | ||||
489 | push( @cats, $cat ); | ||||
490 | } | ||||
491 | $nsth->finish; | ||||
492 | $data->{'categories'} = \@cats; | ||||
493 | push( @results, $data ); | ||||
494 | } | ||||
495 | $sth->finish; | ||||
496 | return \@results; | ||||
497 | } | ||||
498 | |||||
499 | =head2 DelBranch | ||||
500 | |||||
- - | |||||
505 | sub DelBranch { | ||||
506 | my ($branchcode) = @_; | ||||
507 | my $dbh = C4::Context->dbh; | ||||
508 | my $sth = $dbh->prepare("delete from branches where branchcode = ?"); | ||||
509 | $sth->execute($branchcode); | ||||
510 | $sth->finish; | ||||
511 | } | ||||
512 | |||||
513 | =head2 ModBranchCategoryInfo | ||||
514 | |||||
- - | |||||
520 | sub ModBranchCategoryInfo { | ||||
521 | my ($data) = @_; | ||||
522 | my $dbh = C4::Context->dbh; | ||||
523 | if ($data->{'add'}){ | ||||
524 | # we are doing an insert | ||||
525 | my $sth = $dbh->prepare("INSERT INTO branchcategories (categorycode,categoryname,codedescription,categorytype,show_in_pulldown) VALUES (?,?,?,?,?)"); | ||||
526 | $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'} ); | ||||
527 | $sth->finish(); | ||||
528 | } | ||||
529 | else { | ||||
530 | # modifying | ||||
531 | my $sth = $dbh->prepare("UPDATE branchcategories SET categoryname=?,codedescription=?,categorytype=?,show_in_pulldown=? WHERE categorycode=?"); | ||||
532 | $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) ); | ||||
533 | $sth->finish(); | ||||
534 | } | ||||
535 | } | ||||
536 | |||||
537 | =head2 CheckCategoryUnique | ||||
538 | |||||
- - | |||||
545 | sub CheckCategoryUnique { | ||||
546 | my $categorycode = shift; | ||||
547 | my $dbh = C4::Context->dbh; | ||||
548 | my $sth = $dbh->prepare("SELECT categorycode FROM branchcategories WHERE categorycode = ?"); | ||||
549 | $sth->execute(uc( $categorycode) ); | ||||
550 | if (my $data = $sth->fetchrow_hashref){ | ||||
551 | return 0; | ||||
552 | } | ||||
553 | else { | ||||
554 | return 1; | ||||
555 | } | ||||
556 | } | ||||
557 | |||||
558 | |||||
559 | =head2 DeleteBranchCategory | ||||
560 | |||||
- - | |||||
565 | sub DelBranchCategory { | ||||
566 | my ($categorycode) = @_; | ||||
567 | my $dbh = C4::Context->dbh; | ||||
568 | my $sth = $dbh->prepare("delete from branchcategories where categorycode = ?"); | ||||
569 | $sth->execute($categorycode); | ||||
570 | $sth->finish; | ||||
571 | } | ||||
572 | |||||
573 | =head2 CheckBranchCategorycode | ||||
574 | |||||
- - | |||||
579 | sub CheckBranchCategorycode { | ||||
580 | |||||
581 | # check to see if the branchcode is being used in the database somewhere.... | ||||
582 | my ($categorycode) = @_; | ||||
583 | my $dbh = C4::Context->dbh; | ||||
584 | my $sth = | ||||
585 | $dbh->prepare( | ||||
586 | "select count(*) from branchrelations where categorycode=?"); | ||||
587 | $sth->execute($categorycode); | ||||
588 | my ($total) = $sth->fetchrow_array; | ||||
589 | return $total; | ||||
590 | } | ||||
591 | |||||
592 | sub get_branch_code_from_name { | ||||
593 | my @branch_name = @_; | ||||
594 | my $query = "SELECT branchcode FROM branches WHERE branchname=?;"; | ||||
595 | my $dbh = C4::Context->dbh(); | ||||
596 | my $sth = $dbh->prepare($query); | ||||
597 | $sth->execute(@branch_name); | ||||
598 | return $sth->fetchrow_array; | ||||
599 | } | ||||
600 | |||||
601 | # spent 2.05ms (65µs+1.99) within C4::Branch::GetBranchesCount which was called:
# once (65µs+1.99ms) by C4::Koha::getFacets at line 786 of /usr/share/koha/lib/C4/Koha.pm | ||||
602 | 6 | 1.01ms | 1 | 973µs | my $dbh = C4::Context->dbh(); # spent 973µs making 1 call to C4::Context::dbh |
603 | my $query = "SELECT COUNT(*) AS branches_count FROM branches"; | ||||
604 | 1 | 5µs | 2 | 134µs | my $sth = $dbh->prepare( $query ); # spent 73µs making 1 call to DBI::db::prepare
# spent 61µs making 1 call to DBD::mysql::db::prepare |
605 | 1 | 892µs | $sth->execute(); # spent 892µs making 1 call to DBI::st::execute | ||
606 | 3 | 54µs | my $row = $sth->fetchrow_hashref(); # spent 40µs making 1 call to DBI::st::fetchrow_hashref
# spent 9µs making 1 call to DBI::common::FETCH
# spent 6µs making 1 call to DBI::st::fetch | ||
607 | return $row->{'branches_count'}; | ||||
608 | } | ||||
609 | |||||
610 | 1 | 5µs | 1; | ||
611 | __END__ | ||||
# spent 46µs within C4::Branch::CORE:sort which was called:
# once (46µs+0s) by C4::Branch::GetBranchesLoop at line 163 |