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

(-)a/C4/Branch.pm (-22 lines)
Lines 42-48 BEGIN { Link Here
42
		&GetBranchCategories
42
		&GetBranchCategories
43
		&GetBranchesInCategory
43
		&GetBranchesInCategory
44
		&ModBranchCategoryInfo
44
		&ModBranchCategoryInfo
45
	        &CheckCategoryUnique
46
		&mybranch
45
		&mybranch
47
		&GetBranchesCount
46
		&GetBranchesCount
48
	);
47
	);
Lines 492-518 sub ModBranchCategoryInfo { Link Here
492
    }
491
    }
493
}
492
}
494
493
495
=head2 CheckCategoryUnique
496
497
if (CheckCategoryUnique($categorycode)){
498
  # do something
499
}
500
501
=cut
502
503
sub CheckCategoryUnique {
504
    my $categorycode = shift;
505
    my $dbh    = C4::Context->dbh;
506
    my $sth = $dbh->prepare("SELECT categorycode FROM branchcategories WHERE categorycode = ?");
507
    $sth->execute(uc( $categorycode) );
508
    if (my $data = $sth->fetchrow_hashref){
509
	return 0;
510
    }
511
    else {
512
	return 1;
513
    }
514
}
515
516
=head2 CheckBranchCategorycode
494
=head2 CheckBranchCategorycode
517
495
518
$number_rows_affected = CheckBranchCategorycode($categorycode);
496
$number_rows_affected = CheckBranchCategorycode($categorycode);
(-)a/t/db_dependent/Branch.t (-7 / +1 lines)
Lines 21-27 use Modern::Perl; Link Here
21
use C4::Context;
21
use C4::Context;
22
use Data::Dumper;
22
use Data::Dumper;
23
23
24
use Test::More tests => 36;
24
use Test::More tests => 34;
25
25
26
use C4::Branch;
26
use C4::Branch;
27
use Koha::Libraries;
27
use Koha::Libraries;
Lines 48-54 can_ok( Link Here
48
      GetBranchCategories
48
      GetBranchCategories
49
      GetBranchesInCategory
49
      GetBranchesInCategory
50
      ModBranchCategoryInfo
50
      ModBranchCategoryInfo
51
      CheckCategoryUnique
52
      mybranch
51
      mybranch
53
      GetBranchesCount)
52
      GetBranchesCount)
54
);
53
);
Lines 334-343 is( Link Here
334
    'BRC has been added to CAT1'
333
    'BRC has been added to CAT1'
335
);
334
);
336
335
337
#Test CheckCategoryUnique
338
is( CheckCategoryUnique('CAT2'),          0, 'CAT2 exists' );
339
is( CheckCategoryUnique('CAT_NO_EXISTS'), 1, 'CAT_NO_EXISTS doesnt exist' );
340
341
#Test GetCategoryTypes
336
#Test GetCategoryTypes
342
my @category_types = GetCategoryTypes();
337
my @category_types = GetCategoryTypes();
343
is_deeply(\@category_types, [ 'searchdomain', 'properties' ], 'received expected library category types');
338
is_deeply(\@category_types, [ 'searchdomain', 'properties' ], 'received expected library category types');
344
- 

Return to bug 15295