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

(-)a/Koha/AuthorisedValueCategories.pm (-22 lines)
Lines 36-63 Koha::AuthorisedValueCategories - Koha AuthorisedValueCategory Object set class Link Here
36
36
37
=cut
37
=cut
38
38
39
=head3 find_by_koha_field
40
41
    my $category = Koha::AuthorisedValueCategories->find_by_koha_field($kohafield, [$frameworkcode]);
42
43
Returns the authorised value category linked to the given koha field
44
45
=cut
46
47
sub find_by_koha_field {
48
    my ($class, $kohafield, $frameworkcode) = @_;
49
50
    $frameworkcode //= '';
51
52
    my ($subfield) = Koha::MarcSubfieldStructures->search({
53
        frameworkcode => $frameworkcode,
54
        kohafield => $kohafield,
55
        authorised_value => { not => undef },
56
    });
57
58
    return $subfield ? $class->find($subfield->authorised_value) : undef;
59
}
60
61
=head3 type
39
=head3 type
62
40
63
=cut
41
=cut
(-)a/Koha/Template/Plugin/AuthorisedValues.pm (+12 lines)
Lines 84-89 sub GetDescriptionByKohaField { Link Here
84
    return $description ? $description->{lib} : $authorised_value;
84
    return $description ? $description->{lib} : $authorised_value;
85
}
85
}
86
86
87
sub GetDescriptionsByKohaField {
88
    my ( $self, $params ) = @_;
89
90
    my $frameworkcode    = $params->{frameworkcode} || '';
91
    my $kohafield        = $params->{kohafield};
92
93
    return Koha::AuthorisedValues->get_descriptions_by_koha_field({
94
        frameworkcode => $frameworkcode,
95
        kohafield     => $kohafield,
96
    });
97
}
98
87
1;
99
1;
88
100
89
=head1 NAME
101
=head1 NAME
(-)a/catalogue/itemsearch.pl (-10 / +5 lines)
Lines 27-33 use C4::Items; Link Here
27
use C4::Biblio;
27
use C4::Biblio;
28
use C4::Koha;
28
use C4::Koha;
29
29
30
use Koha::AuthorisedValueCategories;
30
use Koha::AuthorisedValues;
31
use Koha::Item::Search::Field qw(GetItemSearchFields);
31
use Koha::Item::Search::Field qw(GetItemSearchFields);
32
use Koha::ItemTypes;
32
use Koha::ItemTypes;
33
use Koha::Libraries;
33
use Koha::Libraries;
Lines 247-261 foreach my $itemtype ( Koha::ItemTypes->search ) { Link Here
247
    };
247
    };
248
}
248
}
249
249
250
my $ccode_avcategory = Koha::AuthorisedValueCategories->find_by_koha_field('items.ccode');
250
my @ccodes = Koha::AuthorisedValues->get_descriptions_by_koha_field({ kohafield => 'items.ccode' });
251
my $ccode_avcode = $ccode_avcategory ? $ccode_avcategory->category_name : 'CCODE';
251
foreach my $ccode (@ccodes) {
252
my $ccodes = GetAuthorisedValues($ccode_avcode);
252
    $ccode->{value} = $ccode->{authorised_value},
253
my @ccodes;
253
    $ccode->{label} = $ccode->{lib},
254
foreach my $ccode (@$ccodes) {
255
    push @ccodes, {
256
        value => $ccode->{authorised_value},
257
        label => $ccode->{lib},
258
    };
259
}
254
}
260
255
261
my @items_search_fields = GetItemSearchFields();
256
my @items_search_fields = GetItemSearchFields();
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.csv.inc (-3 / +1 lines)
Lines 3-8 Link Here
3
[%- USE AuthorisedValues -%]
3
[%- USE AuthorisedValues -%]
4
[%- biblio = item.biblio -%]
4
[%- biblio = item.biblio -%]
5
[%- biblioitem = item.biblioitem -%]
5
[%- biblioitem = item.biblioitem -%]
6
[%- notforloan_avcategory = AuthorisedValues.GetCategoryByKohaField('items.notforloan') -%]
6
"[% biblio.title |html %] [% IF ( Koha.Preference( 'marcflavour' ) == 'UNIMARC' && biblio.author ) %]by [% END %][% biblio.author |html %]", "[% (biblioitem.publicationyear || biblio.copyrightdate) |html %]", "[% biblioitem.publishercode |html %]", "[% biblioitem.collectiontitle |html %]", "[% item.barcode |html %]", "[% item.itemcallnumber |html %]", "[% Branches.GetName(item.homebranch) |html %]", "[% Branches.GetName(item.holdingbranch) |html %]", "[% AuthorisedValues.GetDescriptionByKohaField( frameworkcode => biblio.frameworkcode, kohafield => 'items.location', authorised_value => item.location) |html %]", "[% item.stocknumber |html %]", "[% AuthorisedValues.GetDescriptionByKohaField(frameworkcode => biblio.frameworkcode, kohafield => 'items.notforloan', authorised_value => item.notforloan) |html %]", "[% (item.issues || 0) |html %]"
7
[%- location_avcategory = AuthorisedValues.GetCategoryByKohaField('items.location') -%]
8
"[% biblio.title |html %] [% IF ( Koha.Preference( 'marcflavour' ) == 'UNIMARC' && biblio.author ) %]by [% END %][% biblio.author |html %]", "[% (biblioitem.publicationyear || biblio.copyrightdate) |html %]", "[% biblioitem.publishercode |html %]", "[% biblioitem.collectiontitle |html %]", "[% item.barcode |html %]", "[% item.itemcallnumber |html %]", "[% Branches.GetName(item.homebranch) |html %]", "[% Branches.GetName(item.holdingbranch) |html %]", "[% IF location_avcategory %][% AuthorisedValues.GetByCode(location_avcategory, item.location) |html %][% ELSE %][% item.location |html %][% END %]", "[% item.stocknumber |html %]", "[% IF notforloan_avcategory %][% AuthorisedValues.GetByCode(notforloan_avcategory, item.notforloan) |html %][% ELSE %][% item.notforloan |html %][% END %]", "[% (item.issues || 0) |html %]"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt (-14 / +8 lines)
Lines 156-177 Link Here
156
  </div>
156
  </div>
157
[% END %]
157
[% END %]
158
158
159
[% notforloan_avcategory = AuthorisedValues.GetCategoryByKohaField('items.notforloan') %]
159
[% notforloans = AuthorisedValues.GetDescriptionsByKohaField({ kohafield = 'items.notforloan' }) %]
160
[% IF notforloan_avcategory %]
160
[% FOREACH nfl IN notforloans %]
161
    [% notforloans = AuthorisedValues.Get(notforloan_avcategory) %]
161
    [% nfl.value = nfl.authorised_value %]
162
    [% FOREACH nfl IN notforloans %]
162
    [% nfl.label = nfl.lib %]
163
        [% nfl.value = nfl.authorised_value %]
164
        [% nfl.label = nfl.lib %]
165
    [% END %]
166
[% END %]
163
[% END %]
167
164
168
[% location_avcategory = AuthorisedValues.GetCategoryByKohaField('items.location') %]
165
[% locations = AuthorisedValues.GetDescriptionsByKohaField({ kohafield = 'items.location' }) %]
169
[% IF location_avcategory %]
166
[% FOREACH loc IN locations %]
170
    [% locations = AuthorisedValues.Get(location_avcategory) %]
167
    [% loc.value = loc.authorised_value %]
171
    [% FOREACH loc IN locations %]
168
    [% loc.label = loc.lib %]
172
        [% loc.value = loc.authorised_value %]
173
        [% loc.label = loc.lib %]
174
    [% END %]
175
[% END %]
169
[% END %]
176
170
177
[%# Page starts here %]
171
[%# Page starts here %]
(-)a/t/db_dependent/Koha/AuthorisedValueCategories.t (-60 lines)
Lines 1-59 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2017 BibLibre
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 3;
23
24
use Koha::MarcSubfieldStructures;
25
use Koha::Database;
26
27
use t::lib::TestBuilder;
28
29
BEGIN {
30
    use_ok('Koha::AuthorisedValueCategories');
31
}
32
33
my $schema = Koha::Database->new->schema;
34
$schema->storage->txn_begin;
35
36
my $category = Koha::AuthorisedValueCategories->find_or_create({
37
    category_name => 'TEST',
38
});
39
40
Koha::MarcSubfieldStructures->search({
41
    frameworkcode => '',
42
    kohafield => 'items.notforloan',
43
})->delete();
44
45
my $subfield = Koha::MarcSubfieldStructures->find_or_create({
46
    frameworkcode => '',
47
    tagfield => 999,
48
    tagsubfield => 9,
49
});
50
$subfield->authorised_value($category->category_name)
51
    ->kohafield('items.notforloan')
52
    ->store();
53
54
my $result = Koha::AuthorisedValueCategories->find_by_koha_field('items.notforloan');
55
56
isa_ok($result, 'Koha::AuthorisedValueCategory', 'Result found');
57
is($result->category_name, $category->category_name, 'Result is correct');
58
59
$schema->storage->txn_rollback;
60
- 

Return to bug 18433