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