Merging katipo changes...

Modified getbranches so you can pass it a branch type and it will only
return branches of that type
This commit is contained in:
bob_lyon 2006-06-06 22:48:00 +00:00
parent 743fb92ee9
commit fa9d8e54c2

View file

@ -36,8 +36,6 @@ C4::Koha - Perl Module containing convenience functions for Koha scripts
use C4::Koha;
$date = slashifyDate("01-01-2002")
=head1 DESCRIPTION
Koha.pm provides many functions for Koha scripts.
@ -120,6 +118,7 @@ foreach my $thisbranch (sort keys %$branches) {
sub getbranches {
# returns a reference to a hash of references to branches...
my ($type) = @_;
my %branches;
my $dbh = C4::Context->dbh;
my $sth;
@ -134,7 +133,12 @@ sub getbranches {
$sth->execute;
while (my $branch=$sth->fetchrow_hashref) {
my $nsth = $dbh->prepare("select categorycode from branchrelations where branchcode = ?");
$nsth->execute($branch->{'branchcode'});
if ($type){
$nsth = $dbh->prepare("select categorycode from branchrelations where branchcode = ? and categorycode = ?");
$nsth->execute($branch->{'branchcode'},$type);
} else {
$nsth->execute($branch->{'branchcode'});
}
while (my ($cat) = $nsth->fetchrow_array) {
# FIXME - This seems wrong. It ought to be
# $branch->{categorycodes}{$cat} = 1;
@ -147,7 +151,13 @@ sub getbranches {
# that aren't fields in the "branches" table.
$branch->{$cat} = 1;
}
$branches{$branch->{'branchcode'}}=$branch;
if ($type) {
$branches{$branch->{'branchcode'}}=$branch;
}
}
if (!$type){
$branches{$branch->{'branchcode'}}=$branch;
}
}
return (\%branches);
}