Merging katipo changes...
authorbob_lyon <bob_lyon>
Tue, 6 Jun 2006 22:48:00 +0000 (22:48 +0000)
committerbob_lyon <bob_lyon>
Tue, 6 Jun 2006 22:48:00 +0000 (22:48 +0000)
Modified getbranches so you can pass it a branch type and it will only
return branches of that type

C4/Koha.pm

index 63d1f71..7dd57e8 100644 (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);
 }