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

(-)a/C4/Biblio.pm (-16 / +45 lines)
Lines 1374-1412 descriptions rather than normal ones when they exist. Link Here
1374
sub GetAuthorisedValueDesc {
1374
sub GetAuthorisedValueDesc {
1375
    my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_;
1375
    my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_;
1376
1376
1377
    my $cache = Koha::Cache::Memory::Lite->get_instance();
1378
1377
    if ( !$category ) {
1379
    if ( !$category ) {
1378
1380
1379
        return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1381
        return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1380
1382
1381
        #---- branch
1383
        #---- branch
1382
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1384
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1383
            my $branch = Koha::Libraries->find($value);
1385
            my $cache_key = "GetAuthorisedValueDesc_branchname:$value";
1384
            return $branch? $branch->branchname: q{};
1386
            my $branchname = $cache->get_from_cache($cache_key);
1387
            unless ( defined $branchname ) {
1388
                my $branch = Koha::Libraries->find($value);
1389
                $branchname = $branch ? $branch->branchname: '';
1390
                $cache->set_in_cache($cache_key, $branchname);
1391
            }
1392
            return $branchname;
1385
        }
1393
        }
1386
1394
1387
        #---- itemtypes
1395
        #---- itemtypes
1388
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1396
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1389
            my $itemtype = Koha::ItemTypes->find( $value );
1397
            my $cache_key = "GetAuthorisedValueDesc_translated_description:$value";
1390
            return $itemtype ? $itemtype->translated_description : q||;
1398
            my $translated_description = $cache->get_from_cache($cache_key);
1399
            unless( defined $translated_description ) {
1400
                my $itemtype = Koha::ItemTypes->find( $value );
1401
                $translated_description = $itemtype ? $itemtype->translated_description : '';
1402
                $cache->set_in_cache($cache_key, $translated_description);
1403
            }
1404
            return $translated_description;
1391
        }
1405
        }
1392
1393
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) {
1406
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) {
1394
            my $source = GetClassSource($value);
1407
            my $cache_key = "GetAuthorisedValueDesc_source_description:$value";
1395
            return $source ? $source->{description} : q||;
1408
            my $source_description = $cache->get_from_cache($cache_key);
1409
            unless( defined $source_description ) {
1410
                my $source = GetClassSource($value);
1411
                $source_description = $source ? $source->{description} : '';
1412
                $cache->set_in_cache($cache_key, $source_description);
1413
            }
1414
            return $source_description;
1396
        }
1415
        }
1397
1398
        #---- "true" authorized value
1416
        #---- "true" authorized value
1399
        $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1417
        $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1400
    }
1418
    }
1401
1419
    if ( defined $category && $category ne '' ) {
1402
    my $dbh = C4::Context->dbh;
1420
        #TODO: Later replace with call to cached function in Koha/AuthorizedValues.pm
1403
    if ( $category ne "" ) {
1421
        # defined in Bug 31856 when/if this is merged
1404
        my $sth = $dbh->prepare( "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?" );
1422
        my $opac_key = defined $opac && $opac ? '1': '0';
1405
        $sth->execute( $category, $value );
1423
        my $cache_key = "GetAuthorisedValueDesc_authorized_value_description:$category:$value:$opac_key";
1406
        my $data = $sth->fetchrow_hashref;
1424
        my $description = $cache->get_from_cache($cache_key);
1407
        return ( $opac && $data->{'lib_opac'} ) ? $data->{'lib_opac'} : $data->{'lib'};
1425
        unless ( defined $description ) {
1426
            my $dbh = C4::Context->dbh;
1427
            my $sth = $dbh->prepare( "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?" );
1428
            $sth->execute( $category, $value );
1429
            my $data = $sth->fetchrow_hashref;
1430
            my $description;
1431
            if ($data) {
1432
                $description = $opac && $data->{'lib_opac'} ? $data->{'lib_opac'} : $data->{'lib'};
1433
            }
1434
            $cache->set_in_cache($cache_key, $description // '');
1435
        }
1436
        return $description;
1408
    } else {
1437
    } else {
1409
        return $value;    # if nothing is found return the original value
1438
        return $value; # if nothing is found return the original value
1410
    }
1439
    }
1411
}
1440
}
1412
1441
(-)a/Koha/Item.pm (-4 / +9 lines)
Lines 1048-1056 This is meant to be used for display purpose only. Link Here
1048
1048
1049
sub columns_to_str {
1049
sub columns_to_str {
1050
    my ( $self ) = @_;
1050
    my ( $self ) = @_;
1051
    my $cache = Koha::Cache::Memory::Lite->get_instance();
1052
    my $cache_key = 'Item_columns_to_str_frameworkcode:' . $self->biblionumber;
1051
1053
1052
    my $frameworkcode = $self->biblio->frameworkcode;
1054
    my $frameworkcode = $cache->get_from_cache($cache_key);
1053
    my $tagslib = C4::Biblio::GetMarcStructure(1, $frameworkcode);
1055
    unless ( defined $frameworkcode ) {
1056
        $frameworkcode = $self->biblio->frameworkcode;
1057
        $cache->set_in_cache($cache_key, $frameworkcode);
1058
    }
1059
    my $tagslib = C4::Biblio::GetMarcStructure( 1, $frameworkcode, { unsafe => 1 } );
1054
    my ( $itemtagfield, $itemtagsubfield) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
1060
    my ( $itemtagfield, $itemtagsubfield) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
1055
1061
1056
    my $columns_info = $self->_result->result_source->columns_info;
1062
    my $columns_info = $self->_result->result_source->columns_info;
Lines 1061-1067 sub columns_to_str { Link Here
1061
1067
1062
        next if $column eq 'more_subfields_xml';
1068
        next if $column eq 'more_subfields_xml';
1063
1069
1064
        my $value = $self->$column;
1070
        my $value = $self->_result()->get_column($column);
1065
        # Maybe we need to deal with datetime columns here, but so far we have damaged_on, itemlost_on and withdrawn_on, and they are not linked with kohafield
1071
        # Maybe we need to deal with datetime columns here, but so far we have damaged_on, itemlost_on and withdrawn_on, and they are not linked with kohafield
1066
1072
1067
        if ( not defined $value or $value eq "" ) {
1073
        if ( not defined $value or $value eq "" ) {
1068
- 

Return to bug 32060