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

(-)a/C4/Branch.pm (-50 lines)
Lines 33-39 BEGIN { Link Here
33
		&GetBranch
33
		&GetBranch
34
		&GetBranches
34
		&GetBranches
35
		&GetBranchesLoop
35
		&GetBranchesLoop
36
		&GetBranchInfo
37
		&mybranch
36
		&mybranch
38
	);
37
	);
39
    @EXPORT_OK = qw( &onlymine &mybranch );
38
    @EXPORT_OK = qw( &onlymine &mybranch );
Lines 58-64 The functions in this module deal with branches. Link Here
58
  $branches = &GetBranches();
57
  $branches = &GetBranches();
59
58
60
Returns informations about ALL branches, IndependentBranches Insensitive.
59
Returns informations about ALL branches, IndependentBranches Insensitive.
61
GetBranchInfo() returns the same information.
62
60
63
Create a branch selector with the following code.
61
Create a branch selector with the following code.
64
62
Lines 185-238 sub GetBranch { Link Here
185
    return $branch;
183
    return $branch;
186
}
184
}
187
185
188
=head2 GetBranchInfo
189
190
$results = GetBranchInfo($branchcode);
191
192
returns C<$results>, a reference to an array of hashes containing branches.
193
if $branchcode, just this branch, with associated categories.
194
if ! $branchcode && $categorytype, all branches in the category.
195
196
=cut
197
198
sub GetBranchInfo {
199
    my ($branchcode,$categorytype) = @_;
200
    my $dbh = C4::Context->dbh;
201
    my $sth;
202
203
204
	if ($branchcode) {
205
        $sth =
206
          $dbh->prepare(
207
            "Select * from branches where branchcode = ? order by branchcode");
208
        $sth->execute($branchcode);
209
    }
210
    else {
211
        $sth = $dbh->prepare("Select * from branches order by branchcode");
212
        $sth->execute();
213
    }
214
    my @results;
215
    while ( my $data = $sth->fetchrow_hashref ) {
216
		my @bind = ($data->{'branchcode'});
217
        my $query= "select r.categorycode from branchrelations r";
218
		$query .= ", branchcategories c " if($categorytype);
219
		$query .= " where  branchcode=? ";
220
		if($categorytype) { 
221
			$query .= " and c.categorytype=? and r.categorycode=c.categorycode";
222
			push @bind, $categorytype;
223
		}
224
        my $nsth=$dbh->prepare($query);
225
		$nsth->execute( @bind );
226
        my @cats = ();
227
        while ( my ($cat) = $nsth->fetchrow_array ) {
228
            push( @cats, $cat );
229
        }
230
        $data->{'categories'} = \@cats;
231
        push( @results, $data );
232
    }
233
    return \@results;
234
}
235
236
1;
186
1;
237
__END__
187
__END__
238
188
(-)a/opac/opac-suggestions.pl (-1 / +2 lines)
Lines 28-33 use C4::Output; Link Here
28
use C4::Suggestions;
28
use C4::Suggestions;
29
use C4::Koha;
29
use C4::Koha;
30
use C4::Scrubber;
30
use C4::Scrubber;
31
use Koha::Libraries;
31
32
32
use Koha::DateUtils qw( dt_from_string );
33
use Koha::DateUtils qw( dt_from_string );
33
34
Lines 149-155 if ( $op eq "delete_confirm" ) { Link Here
149
    print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
150
    print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
150
    exit;
151
    exit;
151
}
152
}
152
map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop;
153
map{ $_->{'branchcodesuggestedby'} = Koha::Libraries->find($_->{'branchcodesuggestedby'})->branchname} @$suggestions_loop;
153
154
154
foreach my $suggestion(@$suggestions_loop) {
155
foreach my $suggestion(@$suggestions_loop) {
155
    if($suggestion->{'suggestedby'} == $borrowernumber) {
156
    if($suggestion->{'suggestedby'} == $borrowernumber) {
(-)a/t/db_dependent/Branch.t (-14 / +5 lines)
Lines 40-46 can_ok( Link Here
40
      GetBranch
40
      GetBranch
41
      GetBranches
41
      GetBranches
42
      GetBranchesLoop
42
      GetBranchesLoop
43
      GetBranchInfo
44
      mybranch
43
      mybranch
45
      )
44
      )
46
);
45
);
Lines 192-209 my $CAT1 = Koha::LibraryCategories->find('CAT1'); Link Here
192
$b2_stored->add_to_categories([$CAT1]);
191
$b2_stored->add_to_categories([$CAT1]);
193
is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
192
is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
194
193
195
#Test GetBranchInfo
194
my $b1info = Koha::Libraries->find( $b1->{branchcode} );
196
my $b1info = GetBranchInfo( $b1->{branchcode} );
195
is_deeply( $b1info->categories->count, 0, 'BRA has no categories' );
197
$b1->{categories} = [];
196
198
is_deeply( @$b1info[0], $b1, 'BRA has no categories' );
197
my $b2info = Koha::Libraries->find( $b2->{branchcode} );
199
198
is_deeply( $b2->categories->count, 1, 'BRB has the category CAT1' );
200
my $b2info = GetBranchInfo( $b2->{branchcode} );
201
my @cat    = ( $cat1->{categorycode} );
202
delete $b2->{add};
203
delete $b2->{CAT1};
204
$b2->{issuing}    = undef;
205
$b2->{categories} = \@cat;
206
is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' );
207
199
208
Koha::LibraryCategory->new($cat2)->store;
200
Koha::LibraryCategory->new($cat2)->store;
209
is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" );
201
is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" );
210
- 

Return to bug 15629