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

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

Return to bug 32060