Lines 98-103
use C4::Charset qw(
Link Here
|
98 |
SetUTF8Flag |
98 |
SetUTF8Flag |
99 |
StripNonXmlChars |
99 |
StripNonXmlChars |
100 |
); |
100 |
); |
|
|
101 |
use C4::Languages; |
101 |
use C4::Linker; |
102 |
use C4::Linker; |
102 |
use C4::OAI::Sets; |
103 |
use C4::OAI::Sets; |
103 |
use C4::Items qw( GetHiddenItemnumbers GetMarcItem ); |
104 |
use C4::Items qw( GetHiddenItemnumbers GetMarcItem ); |
Lines 1464-1488
descriptions rather than normal ones when they exist.
Link Here
|
1464 |
sub GetAuthorisedValueDesc { |
1465 |
sub GetAuthorisedValueDesc { |
1465 |
my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_; |
1466 |
my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_; |
1466 |
|
1467 |
|
|
|
1468 |
my $cache = Koha::Caches->get_instance(); |
1469 |
my $cache_key; |
1467 |
if ( !$category ) { |
1470 |
if ( !$category ) { |
1468 |
|
1471 |
|
1469 |
return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'}; |
1472 |
return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'}; |
1470 |
|
1473 |
|
1471 |
#---- branch |
1474 |
#---- branch |
1472 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { |
1475 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { |
1473 |
my $branch = Koha::Libraries->find($value); |
1476 |
$cache_key = "LibraryNames"; |
1474 |
return $branch? $branch->branchname: q{}; |
1477 |
my $libraries = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); |
|
|
1478 |
if ( !$libraries ) { |
1479 |
$libraries = { |
1480 |
map { $_->branchcode => $_->branchname } |
1481 |
Koha::Libraries->search( {}, |
1482 |
{ columns => [ 'branchcode', 'branchname' ] } ) |
1483 |
->as_list |
1484 |
}; |
1485 |
$cache->set_in_cache($cache_key, $libraries); |
1486 |
} |
1487 |
return $libraries->{$value}; |
1475 |
} |
1488 |
} |
1476 |
|
1489 |
|
1477 |
#---- itemtypes |
1490 |
#---- itemtypes |
1478 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) { |
1491 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) { |
1479 |
my $itemtype = Koha::ItemTypes->find( $value ); |
1492 |
my $lang = C4::Languages::getlanguage; |
1480 |
return $itemtype ? $itemtype->translated_description : q||; |
1493 |
$lang //= 'en'; |
|
|
1494 |
$cache_key = $lang . 'ItemTypeDescriptions'; |
1495 |
my $itypes = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); |
1496 |
if ( !$itypes ) { |
1497 |
$itypes = |
1498 |
{ map { $_->itemtype => $_->translated_description } |
1499 |
Koha::ItemTypes->search()->as_list }; |
1500 |
$cache->set_in_cache( $cache_key, $itypes ); |
1501 |
} |
1502 |
return $itypes->{$value}; |
1481 |
} |
1503 |
} |
1482 |
|
1504 |
|
1483 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) { |
1505 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) { |
1484 |
my $source = GetClassSource($value); |
1506 |
$cache_key = "ClassSources"; |
1485 |
return $source ? $source->{description} : q||; |
1507 |
my $cn_sources = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); |
|
|
1508 |
if ( !$cn_sources ) { |
1509 |
$cn_sources = { |
1510 |
map { $_->cn_source => $_->description } |
1511 |
Koha::ClassSources->search( {}, |
1512 |
{ columns => [ 'cn_source', 'description' ] } ) |
1513 |
->as_list |
1514 |
}; |
1515 |
$cache->set_in_cache($cache_key, $cn_sources); |
1516 |
} |
1517 |
return $cn_sources->{$value}; |
1486 |
} |
1518 |
} |
1487 |
|
1519 |
|
1488 |
#---- "true" authorized value |
1520 |
#---- "true" authorized value |
Lines 1491-1500
sub GetAuthorisedValueDesc {
Link Here
|
1491 |
|
1523 |
|
1492 |
my $dbh = C4::Context->dbh; |
1524 |
my $dbh = C4::Context->dbh; |
1493 |
if ( $category ne "" ) { |
1525 |
if ( $category ne "" ) { |
1494 |
my $sth = $dbh->prepare( "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?" ); |
1526 |
$cache_key = "AVDescriptions-" . $category; |
1495 |
$sth->execute( $category, $value ); |
1527 |
my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); |
1496 |
my $data = $sth->fetchrow_hashref; |
1528 |
if ( !$av_descriptions ) { |
1497 |
return ( $opac && $data->{'lib_opac'} ) ? $data->{'lib_opac'} : $data->{'lib'}; |
1529 |
$av_descriptions = { |
|
|
1530 |
map { |
1531 |
$_->authorised_value => |
1532 |
{ lib => $_->lib, lib_opac => $_->lib_opac } |
1533 |
} Koha::AuthorisedValues->search( |
1534 |
{ category => $category }, |
1535 |
{ |
1536 |
columns => [ 'authorised_value', 'lib_opac', 'lib' ] |
1537 |
} |
1538 |
)->as_list |
1539 |
}; |
1540 |
$cache->set_in_cache($cache_key, $av_descriptions); |
1541 |
} |
1542 |
return ( $opac && $av_descriptions->{$value}->{'lib_opac'} ) |
1543 |
? $av_descriptions->{$value}->{'lib_opac'} |
1544 |
: $av_descriptions->{$value}->{'lib'}; |
1498 |
} else { |
1545 |
} else { |
1499 |
return $value; # if nothing is found return the original value |
1546 |
return $value; # if nothing is found return the original value |
1500 |
} |
1547 |
} |