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

(-)a/C4/Branch.pm (-22 lines)
Lines 38-44 BEGIN { Link Here
38
		&ModBranch
38
		&ModBranch
39
		&GetBranchInfo
39
		&GetBranchInfo
40
		&GetBranchesInCategory
40
		&GetBranchesInCategory
41
		&ModBranchCategoryInfo
42
		&mybranch
41
		&mybranch
43
	);
42
	);
44
    @EXPORT_OK = qw( &onlymine &mybranch );
43
    @EXPORT_OK = qw( &onlymine &mybranch );
Lines 381-407 sub GetBranchInfo { Link Here
381
    return \@results;
380
    return \@results;
382
}
381
}
383
382
384
=head2 ModBranchCategoryInfo
385
386
&ModBranchCategoryInfo($data);
387
sets the data from the editbranch form, and writes to the database...
388
389
=cut
390
391
sub ModBranchCategoryInfo {
392
    my ($data) = @_;
393
    my $dbh    = C4::Context->dbh;
394
    if ($data->{'add'}){
395
	# we are doing an insert
396
  my $sth   = $dbh->prepare("INSERT INTO branchcategories (categorycode,categoryname,codedescription,categorytype,show_in_pulldown) VALUES (?,?,?,?,?)");
397
        $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'} );
398
    }
399
    else {
400
	# modifying
401
        my $sth = $dbh->prepare("UPDATE branchcategories SET categoryname=?,codedescription=?,categorytype=?,show_in_pulldown=? WHERE categorycode=?");
402
        $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) );
403
    }
404
}
405
1;
383
1;
406
__END__
384
__END__
407
385
(-)a/t/db_dependent/Branch.t (-16 / +5 lines)
Lines 43-49 can_ok( Link Here
43
      ModBranch
43
      ModBranch
44
      GetBranchInfo
44
      GetBranchInfo
45
      GetBranchesInCategory
45
      GetBranchesInCategory
46
      ModBranchCategoryInfo
47
      mybranch
46
      mybranch
48
      )
47
      )
49
);
48
);
Lines 166-172 is_deeply( $branchdetail, $b1 , "GetBranchDetail gives the details of BRA"); Link Here
166
my $count_cat  = Koha::LibraryCategories->search->count;
165
my $count_cat  = Koha::LibraryCategories->search->count;
167
166
168
my $cat1 = {
167
my $cat1 = {
169
    add              => 1,
170
    categorycode     => 'CAT1',
168
    categorycode     => 'CAT1',
171
    categoryname     => 'catname1',
169
    categoryname     => 'catname1',
172
    codedescription  => 'catdesc1',
170
    codedescription  => 'catdesc1',
Lines 174-180 my $cat1 = { Link Here
174
    show_in_pulldown => 1
172
    show_in_pulldown => 1
175
};
173
};
176
my $cat2 = {
174
my $cat2 = {
177
    add              => 1,
178
    categorycode     => 'CAT2',
175
    categorycode     => 'CAT2',
179
    categoryname     => 'catname2',
176
    categoryname     => 'catname2',
180
    categorytype     => 'catype2',
177
    categorytype     => 'catype2',
Lines 190-208 my %new_category = ( Link Here
190
    show_in_pulldown => 1,
187
    show_in_pulldown => 1,
191
);
188
);
192
189
193
ModBranchCategoryInfo({
190
Koha::LibraryCategory->new(\%new_category)->store;
194
    add => 1,
191
Koha::LibraryCategory->new($cat1)->store;
195
    %new_category,
192
Koha::LibraryCategory->new($cat2)->store;
196
});
197
198
ModBranchCategoryInfo($cat1);
199
ModBranchCategoryInfo($cat2);
200
193
201
my $categories = Koha::LibraryCategories->search;
194
my $categories = Koha::LibraryCategories->search;
202
is( $categories->count, $count_cat + 3, "Two categories added" );
195
is( $categories->count, $count_cat + 3, "Two categories added" );
203
delete $cat1->{add};
204
delete $cat2->{add};
205
delete $new_category{add};
206
196
207
my $del = Koha::LibraryCategories->find( $cat2->{categorycode} )->delete;
197
my $del = Koha::LibraryCategories->find( $cat2->{categorycode} )->delete;
208
is( $del, 1, 'One row affected' );
198
is( $del, 1, 'One row affected' );
Lines 226-233 $b2->{issuing} = undef; Link Here
226
$b2->{categories} = \@cat;
216
$b2->{categories} = \@cat;
227
is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' );
217
is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' );
228
218
229
ModBranchCategoryInfo({add => 1,%$cat2});
219
Koha::LibraryCategory->new($cat2)->store;
230
is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two catgories added" );
220
is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" );
231
$b2 = {
221
$b2 = {
232
    branchcode     => 'BRB',
222
    branchcode     => 'BRB',
233
    branchname     => 'BranchB',
223
    branchname     => 'BranchB',
234
- 

Return to bug 15295