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