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

(-)a/C4/Koha.pm (-3 / +8 lines)
Lines 486-505 C<$opac> If set to a true value, displays OPAC descriptions rather than normal o Link Here
486
sub GetAuthorisedValues {
486
sub GetAuthorisedValues {
487
    my $category = shift // '';  # optional parameter
487
    my $category = shift // '';  # optional parameter
488
    my $opac = shift ? 1 : 0;  # normalise to be safe
488
    my $opac = shift ? 1 : 0;  # normalise to be safe
489
    my $options = shift // '';
490
    my $no_limit = $options->{'no_limit'} if $options; #optional paramater to ignore branch limitation
489
491
490
    # Is this cached already?
492
    # Is this cached already?
491
    my $branch_limit =
493
    my $branch_limit =
492
      C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
494
      C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
493
    my $cache_key =
495
    my $cache_key =
494
      "AuthorisedValues-$category-$opac-$branch_limit";
496
      "AuthorisedValues-$category-$opac-$branch_limit-$no_limit";
495
    my $cache  = Koha::Caches->get_instance();
497
    my $cache  = Koha::Caches->get_instance();
496
    my $result = $cache->get_from_cache($cache_key);
498
    my $result = $cache->get_from_cache($cache_key);
497
    return $result if $result;
499
    return $result if $result;
498
500
499
    my @results;
501
    my @results;
500
    my $dbh      = C4::Context->dbh;
502
    my $dbh      = C4::Context->dbh;
503
    my $select_clause = 'SELECT av.*';
504
    $select_clause .= ", GROUP_CONCAT( authorised_values_branches.branchcode SEPARATOR '-' ) as restricted_to" if $no_limit;
501
    my $query = qq{
505
    my $query = qq{
502
        SELECT DISTINCT av.*
506
        $select_clause
503
        FROM authorised_values av
507
        FROM authorised_values av
504
    };
508
    };
505
    $query .= qq{
509
    $query .= qq{
Lines 511-523 sub GetAuthorisedValues { Link Here
511
        push @where_strings, "category = ?";
515
        push @where_strings, "category = ?";
512
        push @where_args, $category;
516
        push @where_args, $category;
513
    }
517
    }
514
    if($branch_limit) {
518
    if($branch_limit && !defined $no_limit) {
515
        push @where_strings, "( branchcode = ? OR branchcode IS NULL )";
519
        push @where_strings, "( branchcode = ? OR branchcode IS NULL )";
516
        push @where_args, $branch_limit;
520
        push @where_args, $branch_limit;
517
    }
521
    }
518
    if(@where_strings > 0) {
522
    if(@where_strings > 0) {
519
        $query .= " WHERE " . join(" AND ", @where_strings);
523
        $query .= " WHERE " . join(" AND ", @where_strings);
520
    }
524
    }
525
    $query .= ' GROUP BY av.id ';
521
    $query .= ' ORDER BY category, ' . (
526
    $query .= ' ORDER BY category, ' . (
522
                $opac ? 'COALESCE(lib_opac, lib)'
527
                $opac ? 'COALESCE(lib_opac, lib)'
523
                      : 'lib, lib_opac'
528
                      : 'lib, lib_opac'
(-)a/Koha/UI/Form/Builder/Item.pm (-2 / +8 lines)
Lines 251-261 sub generate_subfield_form { Link Here
251
        }
251
        }
252
        else {
252
        else {
253
            push @authorised_values, qq{};
253
            push @authorised_values, qq{};
254
            my $av = GetAuthorisedValues( $subfield->{authorised_value} );
254
            my $av = GetAuthorisedValues( $subfield->{authorised_value}, undef, { 'no_limit' => 1 } );
255
            my @restricted_av;
255
            for my $r (@$av) {
256
            for my $r (@$av) {
256
                push @authorised_values, $r->{authorised_value};
257
                if ( defined $r->{restricted_to} ) {
258
                    push @restricted_av, {code => $r->{authorised_value}, lib => $r->{lib}, restricted_to => $r->{restricted_to}};
259
                } else {
260
                    push @authorised_values, $r->{authorised_value};
261
                }
257
                $authorised_lib{ $r->{authorised_value} } = $r->{lib};
262
                $authorised_lib{ $r->{authorised_value} } = $r->{lib};
258
            }
263
            }
264
            $subfield_data{restricted_av} = \@restricted_av if scalar(@restricted_av) > 0;
259
        }
265
        }
260
266
261
        if ( $subfield->{hidden} > 4 or $subfield->{hidden} <= -4 ) {
267
        if ( $subfield->{hidden} > 4 or $subfield->{hidden} <= -4 ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc (-2 / +9 lines)
Lines 124-129 Link Here
124
                                [% END %]
124
                                [% END %]
125
                            [% END %]
125
                            [% END %]
126
                        [% END %]
126
                        [% END %]
127
                        [% FOREACH r_av IN subfield.restricted_av %]
128
                            [% SET r_av_lib = r_av.lib %]
129
                            [% SET r_av_code = r_av.code %]
130
                            [% SET r_av_from = r_av.restricted_to %]
131
                            [% IF r_av_code == mv.default %]
132
                                [% SET matched = 1 %]
133
                            [% END %]
134
                            <option value="[%- r_av_lib | html -%]" selected="selected" style="float:right" title="This value ([%- r_av_lib | html -%]) is limited to other branches ([%- r_av_from | html -%])">[%- r_av_lib | html -%]<i class="fa fa-exclamation-triangle" aria-hidden="true"></i></option>
135
                        [% END %]
127
                        [% UNLESS matched || ( ( kohafield == 'items.damaged' || kohafield == 'items.itemlost' || kohafield == 'items.withdrawn' || kohafield == 'items.notforloan' ) && mv.default == '0' ) %]
136
                        [% UNLESS matched || ( ( kohafield == 'items.damaged' || kohafield == 'items.itemlost' || kohafield == 'items.withdrawn' || kohafield == 'items.notforloan' ) && mv.default == '0' ) %]
128
                        [%# If the current value is not in the authorised list  and is not a field where 0 means unset #%]
137
                        [%# If the current value is not in the authorised list  and is not a field where 0 means unset #%]
129
                                <option value="[%- mv.default | html -%]" selected="selected">[%- mv.default | html -%] (Not an authorised value)</option>
138
                                <option value="[%- mv.default | html -%]" selected="selected">[%- mv.default | html -%] (Not an authorised value)</option>
Lines 210-216 Link Here
210
                    [% END %]
219
                    [% END %]
211
220
212
                    <span class="hint" id="hint[% subfield.tag | html %][% subfield.subfield | html %][% subfield.random | html %]"></span>
221
                    <span class="hint" id="hint[% subfield.tag | html %][% subfield.subfield | html %][% subfield.random | html %]"></span>
213
214
                </div>
222
                </div>
215
            </li>
223
            </li>
216
        [% END %]
224
        [% END %]
217
- 

Return to bug 32748