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

(-)a/C4/Biblio.pm (-18 / +11 lines)
Lines 1502-1526 sub GetAuthorisedValueDesc { Link Here
1502
1502
1503
    my $dbh = C4::Context->dbh;
1503
    my $dbh = C4::Context->dbh;
1504
    if ( $category ne "" ) {
1504
    if ( $category ne "" ) {
1505
        $cache_key = "AV_descriptions:" . $category;
1505
        my $memory_cache = Koha::Cache::Memory::Lite->get_instance();
1506
        my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1506
        my $cache_key = 'GetAuthorisedValueDesc:authorised_values';
1507
        if ( !$av_descriptions ) {
1507
        my $authorised_values = $memory_cache->get_from_cache($cache_key);
1508
            $av_descriptions = {
1508
        unless ($authorised_values) {
1509
                map {
1509
            $authorised_values = { map { $_->authorised_value => $_ } Koha::AuthorisedValues->as_list };
1510
                    $_->authorised_value =>
1510
            $memory_cache->set_in_cache($cache_key, $authorised_values);
1511
                      { lib => $_->lib, lib_opac => $_->lib_opac }
1512
                } Koha::AuthorisedValues->search(
1513
                    { category => $category },
1514
                    {
1515
                        columns => [ 'authorised_value', 'lib_opac', 'lib' ]
1516
                    }
1517
                )->as_list
1518
            };
1519
            $cache->set_in_cache($cache_key, $av_descriptions);
1520
        }
1511
        }
1521
        return ( $opac && $av_descriptions->{$value}->{'lib_opac'} )
1512
        my $av = $authorised_values->{$value};
1522
          ? $av_descriptions->{$value}->{'lib_opac'}
1513
        return unless $av;
1523
          : $av_descriptions->{$value}->{'lib'};
1514
1515
        my $lang = C4::Languages::getlanguage();
1516
        return $opac ? $av->opac_translated_description($lang) : $av->localization('lib', $lang);
1524
    } else {
1517
    } else {
1525
        return $value;    # if nothing is found return the original value
1518
        return $value;    # if nothing is found return the original value
1526
    }
1519
    }
(-)a/Koha/AuthorisedValue.pm (+12 lines)
Lines 103-108 sub opac_description { Link Here
103
    return $self->lib_opac() || $self->lib();
103
    return $self->lib_opac() || $self->lib();
104
}
104
}
105
105
106
=head3 opac_translated_description
107
108
my $description = $av->opac_translated_description($lang);
109
110
=cut
111
112
sub opac_translated_description {
113
    my ($self, $lang) = @_;
114
115
    return $self->localization('lib_opac', $lang) || $self->localization('lib', $lang);
116
}
117
106
=head3 to_api_mapping
118
=head3 to_api_mapping
107
119
108
This method returns the mapping for representing a Koha::AuthorisedValue object
120
This method returns the mapping for representing a Koha::AuthorisedValue object
(-)a/Koha/Schema/Result/AuthorisedValue.pm (-2 / +24 lines)
Lines 142-147 __PACKAGE__->has_many( Link Here
142
  { cascade_copy => 0, cascade_delete => 0 },
142
  { cascade_copy => 0, cascade_delete => 0 },
143
);
143
);
144
144
145
=head2 authorised_values_localizations
146
147
Type: has_many
148
149
Related object: L<Koha::Schema::Result::AuthorisedValuesLocalization>
150
151
=cut
152
153
__PACKAGE__->has_many(
154
  "authorised_values_localizations",
155
  "Koha::Schema::Result::AuthorisedValuesLocalization",
156
  { "foreign.authorised_value_id" => "self.id" },
157
  { cascade_copy => 0, cascade_delete => 0 },
158
);
159
145
=head2 category
160
=head2 category
146
161
147
Type: belongs_to
162
Type: belongs_to
Lines 173-181 __PACKAGE__->has_many( Link Here
173
);
188
);
174
189
175
190
176
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
191
# Created by DBIx::Class::Schema::Loader v0.07052 @ 2024-11-15 16:11:15
177
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LH9dpEEzlVVsjNVv/jnONg
192
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:mlwkraQyS4N5mlE7J5g7qQ
178
193
194
__PACKAGE__->load_components('+Koha::Schema::Component::Localization');
195
__PACKAGE__->localization_add_relationships(
196
    'authorised_values_localizations',
197
    'authorised_value_id' => 'id',
198
    'lib',
199
    'lib_opac',
200
);
179
201
180
# You can replace this text with custom code or comments, and it will be preserved on regeneration
202
# You can replace this text with custom code or comments, and it will be preserved on regeneration
181
1;
203
1;
(-)a/Koha/Template/Plugin/AuthorisedValues.pm (-2 / +4 lines)
Lines 22-36 use Template::Plugin; Link Here
22
use base qw( Template::Plugin );
22
use base qw( Template::Plugin );
23
23
24
use C4::Koha qw( GetAuthorisedValues );
24
use C4::Koha qw( GetAuthorisedValues );
25
use C4::Languages;
25
use Koha::AuthorisedValues;
26
use Koha::AuthorisedValues;
26
27
27
sub GetByCode {
28
sub GetByCode {
28
    my ( $self, $category, $code, $opac ) = @_;
29
    my ( $self, $category, $code, $opac ) = @_;
29
    my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
30
    my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
31
    my $lang = C4::Languages::getlanguage();
30
    return $av->count
32
    return $av->count
31
            ? $opac
33
            ? $opac
32
                ? $av->next->opac_description
34
                ? $av->next->opac_translated_description($lang)
33
                : $av->next->lib
35
                : $av->next->localization('lib', $lang)
34
            : $code;
36
            : $code;
35
}
37
}
36
38
(-)a/installer/data/mysql/atomicupdate/bug-38460.pl (+28 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => '38460',
6
    description => 'Add authorised_values_localizations table',
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        unless ( TableExists('authorised_values_localizations') ) {
12
            $dbh->do( "
13
                CREATE TABLE `authorised_values_localizations` (
14
                  `authorised_values_localizations_id` int(11) NOT NULL AUTO_INCREMENT,
15
                  `authorised_value_id` int(11) NOT NULL,
16
                  `property` varchar(100) NOT NULL,
17
                  `lang` varchar(25) NOT NULL,
18
                  `translation` mediumtext DEFAULT NULL,
19
                  PRIMARY KEY (`authorised_values_localizations_id`),
20
                  UNIQUE KEY `authorised_value_id_property_lang` (`authorised_value_id`, `property`, `lang`),
21
                  CONSTRAINT `authorised_values_localizations_authorised_value_id_fk`
22
                    FOREIGN KEY (`authorised_value_id`) REFERENCES `authorised_values` (`id`)
23
                    ON DELETE CASCADE ON UPDATE CASCADE
24
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
25
            " );
26
        }
27
    },
28
};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (-1 / +3 lines)
Lines 180-189 Link Here
180
                                    <li>
180
                                    <li>
181
                                        <label for="lib">Description: </label>
181
                                        <label for="lib">Description: </label>
182
                                        <input type="text" name="lib" id="lib" value="[% av.lib | html %]" maxlength="200" />
182
                                        <input type="text" name="lib" id="lib" value="[% av.lib | html %]" maxlength="200" />
183
                                        [% INCLUDE 'localization-link.inc' source='AuthorisedValue' object_id=av.id property='lib' %]
183
                                    </li>
184
                                    </li>
184
                                    <li>
185
                                    <li>
185
                                        <label for="lib_opac">Description (OPAC): </label>
186
                                        <label for="lib_opac">Description (OPAC): </label>
186
                                        <input type="text" name="lib_opac" id="lib_opac" value="[% av.lib_opac | html %]" maxlength="200" />
187
                                        <input type="text" name="lib_opac" id="lib_opac" value="[% av.lib_opac | html %]" maxlength="200" />
188
                                        [% INCLUDE 'localization-link.inc' source='AuthorisedValue' object_id=av.id property='lib_opac' %]
187
                                    </li>
189
                                    </li>
188
                                    <li><label for="branches">Library limitations: </label>
190
                                    <li><label for="branches">Library limitations: </label>
189
                                        <select id="branches" name="branches" multiple size="10">
191
                                        <select id="branches" name="branches" multiple size="10">
Lines 403-408 Link Here
403
    [% Asset.js("js/admin-menu.js") | $raw %]
405
    [% Asset.js("js/admin-menu.js") | $raw %]
404
    [% INCLUDE 'datatables.inc' %]
406
    [% INCLUDE 'datatables.inc' %]
405
    [% INCLUDE 'columns_settings.inc' %]
407
    [% INCLUDE 'columns_settings.inc' %]
408
    [% INCLUDE 'greybox.inc' %]
406
    <script>
409
    <script>
407
        $(document).ready(function() {
410
        $(document).ready(function() {
408
411
409
- 

Return to bug 38460