Lines 94-99
use C4::Charset qw(
Link Here
|
94 |
SetMarcUnicodeFlag |
94 |
SetMarcUnicodeFlag |
95 |
SetUTF8Flag |
95 |
SetUTF8Flag |
96 |
); |
96 |
); |
|
|
97 |
use C4::Languages; |
97 |
use C4::Linker; |
98 |
use C4::Linker; |
98 |
use C4::OAI::Sets; |
99 |
use C4::OAI::Sets; |
99 |
use C4::Items qw( GetMarcItem ); |
100 |
use C4::Items qw( GetMarcItem ); |
Lines 1373-1397
descriptions rather than normal ones when they exist.
Link Here
|
1373 |
sub GetAuthorisedValueDesc { |
1374 |
sub GetAuthorisedValueDesc { |
1374 |
my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_; |
1375 |
my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_; |
1375 |
|
1376 |
|
|
|
1377 |
my $cache = Koha::Caches->get_instance(); |
1378 |
my $cache_key; |
1376 |
if ( !$category ) { |
1379 |
if ( !$category ) { |
1377 |
|
1380 |
|
1378 |
return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'}; |
1381 |
return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'}; |
1379 |
|
1382 |
|
1380 |
#---- branch |
1383 |
#---- branch |
1381 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { |
1384 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { |
1382 |
my $branch = Koha::Libraries->find($value); |
1385 |
$cache_key = "LibraryNames"; |
1383 |
return $branch? $branch->branchname: q{}; |
1386 |
my $libraries = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); |
|
|
1387 |
if ( !$libraries ) { |
1388 |
$libraries = { |
1389 |
map { $_->branchcode => $_->branchname } |
1390 |
Koha::Libraries->search( {}, |
1391 |
{ columns => [ 'branchcode', 'branchname' ] } ) |
1392 |
->as_list |
1393 |
}; |
1394 |
$cache->set_in_cache($cache_key, $libraries); |
1395 |
} |
1396 |
return $libraries->{$value}; |
1384 |
} |
1397 |
} |
1385 |
|
1398 |
|
1386 |
#---- itemtypes |
1399 |
#---- itemtypes |
1387 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) { |
1400 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) { |
1388 |
my $itemtype = Koha::ItemTypes->find( $value ); |
1401 |
my $lang = C4::Languages::getlanguage; |
1389 |
return $itemtype ? $itemtype->translated_description : q||; |
1402 |
$lang //= 'en'; |
|
|
1403 |
$cache_key = $lang . 'ItemTypeDescriptions'; |
1404 |
my $itypes = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); |
1405 |
if ( !$itypes ) { |
1406 |
$itypes = |
1407 |
{ map { $_->itemtype => $_->translated_description } |
1408 |
Koha::ItemTypes->search()->as_list }; |
1409 |
$cache->set_in_cache( $cache_key, $itypes ); |
1410 |
} |
1411 |
return $itypes->{$value}; |
1390 |
} |
1412 |
} |
1391 |
|
1413 |
|
1392 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) { |
1414 |
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) { |
1393 |
my $source = GetClassSource($value); |
1415 |
$cache_key = "ClassSources"; |
1394 |
return $source ? $source->{description} : q||; |
1416 |
my $cn_sources = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); |
|
|
1417 |
if ( !$cn_sources ) { |
1418 |
$cn_sources = { |
1419 |
map { $_->cn_source => $_->description } |
1420 |
Koha::ClassSources->search( {}, |
1421 |
{ columns => [ 'cn_source', 'description' ] } ) |
1422 |
->as_list |
1423 |
}; |
1424 |
$cache->set_in_cache($cache_key, $cn_sources); |
1425 |
} |
1426 |
return $cn_sources->{$value}; |
1395 |
} |
1427 |
} |
1396 |
|
1428 |
|
1397 |
#---- "true" authorized value |
1429 |
#---- "true" authorized value |
Lines 1400-1409
sub GetAuthorisedValueDesc {
Link Here
|
1400 |
|
1432 |
|
1401 |
my $dbh = C4::Context->dbh; |
1433 |
my $dbh = C4::Context->dbh; |
1402 |
if ( $category ne "" ) { |
1434 |
if ( $category ne "" ) { |
1403 |
my $sth = $dbh->prepare( "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?" ); |
1435 |
$cache_key = "AVDescriptions-" . $category; |
1404 |
$sth->execute( $category, $value ); |
1436 |
my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); |
1405 |
my $data = $sth->fetchrow_hashref; |
1437 |
if ( !$av_descriptions ) { |
1406 |
return ( $opac && $data->{'lib_opac'} ) ? $data->{'lib_opac'} : $data->{'lib'}; |
1438 |
$av_descriptions = { |
|
|
1439 |
map { |
1440 |
$_->authorised_value => |
1441 |
{ lib => $_->lib, lib_opac => $_->lib_opac } |
1442 |
} Koha::AuthorisedValues->search( |
1443 |
{ category => $category }, |
1444 |
{ |
1445 |
columns => [ 'authorised_value', 'lib_opac', 'lib' ] |
1446 |
} |
1447 |
)->as_list |
1448 |
}; |
1449 |
$cache->set_in_cache($cache_key, $av_descriptions); |
1450 |
} |
1451 |
return ( $opac && $av_descriptions->{$value}->{'lib_opac'} ) |
1452 |
? $av_descriptions->{$value}->{'lib_opac'} |
1453 |
: $av_descriptions->{$value}->{'lib'}; |
1407 |
} else { |
1454 |
} else { |
1408 |
return $value; # if nothing is found return the original value |
1455 |
return $value; # if nothing is found return the original value |
1409 |
} |
1456 |
} |