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

(-)a/Koha/ItemType.pm (-1 / +15 lines)
Lines 25-31 use Koha::Database; Link Here
25
use Koha::IssuingRules;
25
use Koha::IssuingRules;
26
use Koha::Localizations;
26
use Koha::Localizations;
27
27
28
use base qw(Koha::Object);
28
use base qw(Koha::Object Koha::Object::Limit::Library);
29
29
30
=head1 NAME
30
=head1 NAME
31
31
Lines 125-130 sub may_article_request { Link Here
125
    return ( $guess->{ $itemtype // q{} } || $guess->{ '*' } ) ? 1 : q{};
125
    return ( $guess->{ $itemtype // q{} } || $guess->{ '*' } ) ? 1 : q{};
126
}
126
}
127
127
128
=head3 _library_limits
129
130
 configure library limits
131
132
=cut
133
134
sub _library_limits {
135
    return {
136
        class => "ItemtypesBranch",
137
        id => "itemtype",
138
        library => "branchcode",
139
    };
140
}
141
128
=head3 type
142
=head3 type
129
143
130
=cut
144
=cut
(-)a/Koha/ItemTypes.pm (-1 / +46 lines)
Lines 55-61 sub search_with_localization { Link Here
55
            -as      => 'translated_description'
55
            -as      => 'translated_description'
56
        }
56
        }
57
    ];
57
    ];
58
    $self->SUPER::search( $params, $attributes );
58
    if(defined $params->{branchcode}) {
59
        $self->search_with_library_limits( $params, $attributes );
60
    } else {
61
        $self->SUPER::search( $params, $attributes );
62
    }
63
}
64
65
=head3 search_with_library_limits
66
67
search itemtypes by library
68
69
my @itemtypes = Koha::ItemTypes->search_with_library_limits({branchcode => branchcode});
70
71
=cut
72
73
sub search_with_library_limits {
74
    my ( $self, $params, $attributes ) = @_;
75
76
    my $branchcode = $params->{branchcode};
77
    delete( $params->{branchcode} );
78
79
    return $self->SUPER::search( $params, $attributes ) unless $branchcode;
80
81
    my $where = {
82
        '-or' => [
83
            'itemtypes_branches.branchcode' => undef,
84
            'itemtypes_branches.branchcode' => $branchcode
85
        ]
86
    };
87
88
    $attributes //= {};
89
    if(exists $attributes->{join}) {
90
        if(ref $attributes->{join} eq 'ARRAY') {
91
            push @{$attributes->{join}}, 'itemtypes_branches';
92
        } else {
93
            $attributes->{join} = [ $attributes->{join}, 'itemtypes_branches' ];
94
        }
95
    } else {
96
        $attributes->{join} = 'itemtypes_branches';
97
    }
98
99
    return $self->SUPER::search( { %$params, %$where, }, $attributes );
59
}
100
}
60
101
61
=head3 type
102
=head3 type
Lines 66-71 sub _type { Link Here
66
    return 'Itemtype';
107
    return 'Itemtype';
67
}
108
}
68
109
110
=head3 object_class
111
112
=cut
113
69
sub object_class {
114
sub object_class {
70
    return 'Koha::ItemType';
115
    return 'Koha::ItemType';
71
}
116
}
(-)a/admin/itemtypes.pl (-2 / +23 lines)
Lines 58-63 undef($sip_media_type) if defined($sip_media_type) and $sip_media_type =~ /^\s*$ Link Here
58
58
59
if ( $op eq 'add_form' ) {
59
if ( $op eq 'add_form' ) {
60
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
60
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
61
62
    my $selected_branches = $itemtype->get_library_limits;
63
    my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
64
    my @branches_loop;
65
    foreach my $branch ( @$branches ) {
66
        my $selected = ($selected_branches && grep {$_->branchcode eq $branch->{branchcode}} @{ $selected_branches->as_list } ) ? 1 : 0;
67
        push @branches_loop, {
68
            branchcode => $branch->{branchcode},
69
            branchname => $branch->{branchname},
70
            selected   => $selected,
71
        };
72
    }
73
61
    my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) );
74
    my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) );
62
    my $searchcategory = GetAuthorisedValues("ITEMTYPECAT");
75
    my $searchcategory = GetAuthorisedValues("ITEMTYPECAT");
63
    my $translated_languages = C4::Languages::getTranslatedLanguages( undef , C4::Context->preference('template') );
76
    my $translated_languages = C4::Languages::getTranslatedLanguages( undef , C4::Context->preference('template') );
Lines 66-71 if ( $op eq 'add_form' ) { Link Here
66
        imagesets => $imagesets,
79
        imagesets => $imagesets,
67
        searchcategory => $searchcategory,
80
        searchcategory => $searchcategory,
68
        can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ),
81
        can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ),
82
        branches_loop    => \@branches_loop,
69
    );
83
    );
70
} elsif ( $op eq 'add_validate' ) {
84
} elsif ( $op eq 'add_validate' ) {
71
    my $is_a_modif   = $input->param('is_a_modif');
85
    my $is_a_modif   = $input->param('is_a_modif');
Lines 77-82 if ( $op eq 'add_form' ) { Link Here
77
    my $defaultreplacecost = $input->param('defaultreplacecost');
91
    my $defaultreplacecost = $input->param('defaultreplacecost');
78
    my $processfee = $input->param('processfee');
92
    my $processfee = $input->param('processfee');
79
    my $image = $input->param('image') || q||;
93
    my $image = $input->param('image') || q||;
94
    my @branches = grep { $_ ne q{} } $input->multi_param('branches');
80
95
81
    my $notforloan = $input->param('notforloan') ? 1 : 0;
96
    my $notforloan = $input->param('notforloan') ? 1 : 0;
82
    my $imageurl =
97
    my $imageurl =
Lines 107-113 if ( $op eq 'add_form' ) { Link Here
107
        $itemtype->hideinopac($hideinopac);
122
        $itemtype->hideinopac($hideinopac);
108
        $itemtype->searchcategory($searchcategory);
123
        $itemtype->searchcategory($searchcategory);
109
124
110
        eval { $itemtype->store; };
125
        eval {
126
          $itemtype->store;
127
          $itemtype->replace_library_limits( \@branches );
128
        };
111
129
112
        if ($@) {
130
        if ($@) {
113
            push @messages, { type => 'alert', code => 'error_on_update' };
131
            push @messages, { type => 'alert', code => 'error_on_update' };
Lines 134-140 if ( $op eq 'add_form' ) { Link Here
134
                searchcategory      => $searchcategory,
152
                searchcategory      => $searchcategory,
135
            }
153
            }
136
        );
154
        );
137
        eval { $itemtype->store; };
155
        eval {
156
          $itemtype->store;
157
          $itemtype->replace_library_limits( \@branches );
158
        };
138
159
139
        if ($@) {
160
        if ($@) {
140
            push @messages, { type => 'alert', code => 'error_on_insert' };
161
            push @messages, { type => 'alert', code => 'error_on_insert' };
(-)a/cataloguing/additem.pl (-1 / +7 lines)
Lines 183-189 sub generate_subfield_form { Link Here
183
            }
183
            }
184
            elsif ( $subfieldlib->{authorised_value} eq "itemtypes" ) {
184
            elsif ( $subfieldlib->{authorised_value} eq "itemtypes" ) {
185
                  push @authorised_values, "";
185
                  push @authorised_values, "";
186
                  my $itemtypes = Koha::ItemTypes->search_with_localization;
186
                  my $branch_limit = C4::Context->userenv && C4::Context->userenv->{"branch"};
187
                  my $itemtypes;
188
                  if($branch_limit) {
189
                      $itemtypes = Koha::ItemTypes->search_with_localization({branchcode => $branch_limit});
190
                  } else {
191
                      $itemtypes = Koha::ItemTypes->search_with_localization;
192
                  }
187
                  while ( my $itemtype = $itemtypes->next ) {
193
                  while ( my $itemtype = $itemtypes->next ) {
188
                      push @authorised_values, $itemtype->itemtype;
194
                      push @authorised_values, $itemtype->itemtype;
189
                      $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
195
                      $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-1 / +13 lines)
Lines 283-288 Item types administration Link Here
283
                        [% END %]
283
                        [% END %]
284
                    </select>
284
                    </select>
285
                </li>
285
                </li>
286
                <li><label for="branches">Libraries limitation: </label>
287
                    <select id="branches" name="branches" multiple size="10">
288
                        <option value="">All libraries</option>
289
                        [% FOREACH branch IN branches_loop %]
290
                        [% IF ( branch.selected ) %]
291
                            <option selected="selected" value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option>
292
                        [% ELSE %]
293
                            <option value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option>
294
                        [% END %]
295
                        [% END %]
296
                    </select>
297
                    <span>Select 'All libraries' if this authorized value must be displayed all the time. Otherwise select libraries you want to associate with this value.</span>
298
                </li>
286
                <li>
299
                <li>
287
                    <label for="summary">Summary: </label>
300
                    <label for="summary">Summary: </label>
288
                   <textarea id="summary" name="summary" cols="55" rows="5">[% itemtype.summary | html %]</textarea>
301
                   <textarea id="summary" name="summary" cols="55" rows="5">[% itemtype.summary | html %]</textarea>
289
- 

Return to bug 15497