View | Details | Raw Unified | Return to bug 11051
Collapse All | Expand All

(-)a/C4/Branch.pm (-27 / +19 lines)
Lines 70-77 The functions in this module deal with branches. Link Here
70
  $branches = &GetBranches();
70
  $branches = &GetBranches();
71
71
72
Returns informations about ALL branches, IndependentBranches Insensitive.
72
Returns informations about ALL branches, IndependentBranches Insensitive.
73
GetBranchInfo() returns the same information without the problems of this function 
73
GetBranchInfo() returns the same information.
74
(namespace collision, mainly).
75
74
76
Create a branch selector with the following code.
75
Create a branch selector with the following code.
77
76
Lines 106-143 Create a branch selector with the following code. Link Here
106
=cut
105
=cut
107
106
108
sub GetBranches {
107
sub GetBranches {
109
    my ($onlymine)=@_;
108
    my ($onlymine) = @_;
109
110
    # returns a reference to a hash of references to ALL branches...
110
    # returns a reference to a hash of references to ALL branches...
111
    my %branches;
111
    my %branches;
112
    my $dbh = C4::Context->dbh;
112
    my $dbh = C4::Context->dbh;
113
    my $sth;
113
    my $sth;
114
    my $query="SELECT * FROM branches";
114
    my $query = "SELECT * FROM branches";
115
    my @bind_parameters;
115
    my @bind_parameters;
116
    if ($onlymine && C4::Context->userenv && C4::Context->userenv->{branch}){
116
    if ( $onlymine && C4::Context->userenv && C4::Context->userenv->{branch} ) {
117
      $query .= ' WHERE branchcode = ? ';
117
        $query .= ' WHERE branchcode = ? ';
118
      push @bind_parameters, C4::Context->userenv->{branch};
118
        push @bind_parameters, C4::Context->userenv->{branch};
119
    }
119
    }
120
        $query.=" ORDER BY branchname";
120
    $query .= " ORDER BY branchname";
121
    $sth = $dbh->prepare($query);
121
    $sth = $dbh->prepare($query);
122
    $sth->execute( @bind_parameters );
122
    $sth->execute(@bind_parameters);
123
123
124
    my $nsth = $dbh->prepare(
124
    my $relations_sth =
125
        "SELECT categorycode FROM branchrelations WHERE branchcode = ?"
125
      $dbh->prepare("SELECT branchcode,categorycode FROM branchrelations");
126
    );  # prepare once, outside while loop
126
    $relations_sth->execute();
127
    my %relations;
128
    while ( my $rel = $relations_sth->fetchrow_hashref ) {
129
        push @{ $relations{ $rel->{branchcode} } }, $rel->{categorycode};
130
    }
127
131
128
    while ( my $branch = $sth->fetchrow_hashref ) {
132
    while ( my $branch = $sth->fetchrow_hashref ) {
129
        $nsth->execute( $branch->{'branchcode'} );
133
        foreach my $cat ( @{ $relations{ $branch->{branchcode} } } ) {
130
        while ( my ($cat) = $nsth->fetchrow_array ) {
131
            # FIXME - This seems wrong. It ought to be
132
            # $branch->{categorycodes}{$cat} = 1;
133
            # otherwise, there's a namespace collision if there's a
134
            # category with the same name as a field in the 'branches'
135
            # table (i.e., don't create a category called "issuing").
136
            # In addition, the current structure doesn't really allow
137
            # you to list the categories that a branch belongs to:
138
            # you'd have to list keys %$branch, and remove those keys
139
            # that aren't fields in the "branches" table.
140
         #   $branch->{$cat} = 1;
141
            $branch->{category}{$cat} = 1;
134
            $branch->{category}{$cat} = 1;
142
        }
135
        }
143
        $branches{ $branch->{'branchcode'} } = $branch;
136
        $branches{ $branch->{'branchcode'} } = $branch;
Lines 146-152 sub GetBranches { Link Here
146
}
139
}
147
140
148
sub onlymine {
141
sub onlymine {
149
    return 
142
    return
150
    C4::Context->preference('IndependentBranches') &&
143
    C4::Context->preference('IndependentBranches') &&
151
    C4::Context->userenv                           &&
144
    C4::Context->userenv                           &&
152
    C4::Context->userenv->{flags} %2 != 1          &&
145
    C4::Context->userenv->{flags} %2 != 1          &&
153
- 

Return to bug 11051