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

(-)a/admin/authorised_values.pl (-11 / +12 lines)
Lines 20-25 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use List::MoreUtils qw(any);
24
23
use C4::Auth;
25
use C4::Auth;
24
use C4::Context;
26
use C4::Context;
25
use C4::Koha;
27
use C4::Koha;
Lines 49-70 our ($template, $borrowernumber, $cookie)= get_template_and_user({ Link Here
49
################## ADD_FORM ##################################
51
################## ADD_FORM ##################################
50
# called by default. Used to create form to add or  modify a record
52
# called by default. Used to create form to add or  modify a record
51
if ($op eq 'add_form') {
53
if ($op eq 'add_form') {
52
    my ( $selected_branches, $category, $av );
54
    my ( @selected_branches, $category, $av );
53
    if ($id) {
55
    if ($id) {
54
        $av = Koha::AuthorisedValues->new->find( $id );
56
        $av = Koha::AuthorisedValues->new->find( $id );
55
        $selected_branches = $av->branch_limitations;
57
        @selected_branches = $av->library_limits->as_list;
56
    } else {
58
    } else {
57
        $category = $input->param('category');
59
        $category = $input->param('category');
58
    }
60
    }
59
61
60
    my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
62
    my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } );
61
    my @branches_loop;
63
    my @branches_loop;
62
    foreach my $branch ( @$branches ) {
64
    while ( my $branch = $branches->next ) {
63
        my $selected = ( grep {$_ eq $branch->{branchcode}} @$selected_branches ) ? 1 : 0;
64
        push @branches_loop, {
65
        push @branches_loop, {
65
            branchcode => $branch->{branchcode},
66
            branchcode => $branch->branchcode,
66
            branchname => $branch->{branchname},
67
            branchname => $branch->branchname,
67
            selected   => $selected,
68
            selected   => any {$_->branchcode eq $branch->branchcode} @selected_branches,
68
        };
69
        };
69
    }
70
    }
70
71
Lines 126-132 if ($op eq 'add_form') { Link Here
126
        $av->imageurl( $imageurl );
127
        $av->imageurl( $imageurl );
127
        eval{
128
        eval{
128
            $av->store;
129
            $av->store;
129
            $av->replace_branch_limitations( \@branches );
130
            $av->replace_library_limits( \@branches );
130
        };
131
        };
131
        if ( $@ ) {
132
        if ( $@ ) {
132
            push @messages, {type => 'error', code => 'error_on_update' };
133
            push @messages, {type => 'error', code => 'error_on_update' };
Lines 145-151 if ($op eq 'add_form') { Link Here
145
146
146
        eval {
147
        eval {
147
            $av->store;
148
            $av->store;
148
            $av->replace_branch_limitations( \@branches );
149
            $av->replace_library_limits( \@branches );
149
        };
150
        };
150
151
151
        if ( $@ ) {
152
        if ( $@ ) {
Lines 230-236 if ( $op eq 'list' ) { Link Here
230
        $row_data{lib}                   = $av->lib;
231
        $row_data{lib}                   = $av->lib;
231
        $row_data{lib_opac}              = $av->lib_opac;
232
        $row_data{lib_opac}              = $av->lib_opac;
232
        $row_data{imageurl}              = getitemtypeimagelocation( 'intranet', $av->imageurl );
233
        $row_data{imageurl}              = getitemtypeimagelocation( 'intranet', $av->imageurl );
233
        $row_data{branches}              = $av->branch_limitations;
234
        $row_data{branches}              = $av->library_limits->as_list;
234
        $row_data{id}                    = $av->id;
235
        $row_data{id}                    = $av->id;
235
        push(@loop_data, \%row_data);
236
        push(@loop_data, \%row_data);
236
    }
237
    }
(-)a/t/db_dependent/AuthorisedValues.t (-7 / +6 lines)
Lines 95-101 is( @authorised_values, 3, "Get correct number of values" ); Link Here
95
my $branchcode1 = $builder->build({ source => 'Branch' })->{branchcode};
95
my $branchcode1 = $builder->build({ source => 'Branch' })->{branchcode};
96
my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode};
96
my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode};
97
97
98
$av1->add_branch_limitation( $branchcode1 );
98
$av1->add_library_limit( $branchcode1 );
99
99
100
@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode1 } );
100
@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode1 } );
101
is( @authorised_values, 3, "Search including value with a branch limit ( branch can use the limited value ) gives correct number of results" );
101
is( @authorised_values, 3, "Search including value with a branch limit ( branch can use the limited value ) gives correct number of results" );
Lines 103-117 is( @authorised_values, 3, "Search including value with a branch limit ( branch Link Here
103
@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
103
@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
104
is( @authorised_values, 2, "Search including value with a branch limit ( branch *cannot* use the limited value ) gives correct number of results" );
104
is( @authorised_values, 2, "Search including value with a branch limit ( branch *cannot* use the limited value ) gives correct number of results" );
105
105
106
$av1->del_branch_limitation( $branchcode1 );
106
$av1->del_library_limit( $branchcode1 );
107
@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
107
@authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
108
is( @authorised_values, 3, "Branch limitation deleted successfully" );
108
is( @authorised_values, 3, "Branch limitation deleted successfully" );
109
109
110
$av1->add_branch_limitation( $branchcode1 );
110
$av1->add_library_limit( $branchcode1 );
111
$av1->branch_limitations( [ $branchcode1, $branchcode2 ] );
111
$av1->library_limits( [ $branchcode1, $branchcode2 ] );
112
112
113
my $limits = $av1->branch_limitations;
113
my $limits = $av1->library_limits->as_list;
114
is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' );
114
is( @$limits, 2, 'library_limits functions correctly both as setter and getter' );
115
115
116
my @categories = Koha::AuthorisedValues->new->categories;
116
my @categories = Koha::AuthorisedValues->new->categories;
117
is( @categories, 3, 'There should have 2 categories inserted' );
117
is( @categories, 3, 'There should have 2 categories inserted' );
118
- 

Return to bug 23272