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 |
|