Lines 77-82
BEGIN {
Link Here
|
77 |
&GetMarcISBN |
77 |
&GetMarcISBN |
78 |
&GetMarcISSN |
78 |
&GetMarcISSN |
79 |
&GetMarcSubjects |
79 |
&GetMarcSubjects |
|
|
80 |
ShouldDisplayOnInterface |
81 |
ShouldHideMARC |
82 |
GetFilteredBiblio |
80 |
&GetMarcBiblio |
83 |
&GetMarcBiblio |
81 |
&GetMarcAuthors |
84 |
&GetMarcAuthors |
82 |
&GetMarcSeries |
85 |
&GetMarcSeries |
Lines 1247-1268
sub GetMarcSubfieldStructureFromKohaField {
Link Here
|
1247 |
return $result; |
1250 |
return $result; |
1248 |
} |
1251 |
} |
1249 |
|
1252 |
|
|
|
1253 |
sub ShouldDisplayOnInterface { |
1254 |
my $display = { |
1255 |
opac => { |
1256 |
0 => 1, |
1257 |
-1 => 1, |
1258 |
-2 => 1, |
1259 |
-3 => 1, |
1260 |
-4 => 1, |
1261 |
-5 => 1, |
1262 |
-6 => 1, |
1263 |
-7 => 1, |
1264 |
}, |
1265 |
intranet => { |
1266 |
-6 => 1, |
1267 |
-5 => 1, |
1268 |
-1 => 1, |
1269 |
0 => 1, |
1270 |
1 => 1, |
1271 |
4 => 1, |
1272 |
6 => 1, |
1273 |
7 => 1, |
1274 |
}, |
1275 |
}; |
1276 |
return $display; |
1277 |
} |
1278 |
|
1279 |
=head2 ShouldHideMARC |
1280 |
|
1281 |
Return a hash reference of whether a field, built from |
1282 |
kohafield and tag, is hidden (1) or not (0) for a given |
1283 |
interface |
1284 |
|
1285 |
my $OpacHideMARC = |
1286 |
GetOpacHideMARC( { |
1287 |
frameworkcode => $frameworkcode, |
1288 |
interface => 'opac', |
1289 |
} ); |
1290 |
|
1291 |
if ($OpacHideMARC->{'stocknumber'}==1) { |
1292 |
print "Hidden!\n"; |
1293 |
} |
1294 |
|
1295 |
C<$OpacHideMARC> is a ref to a hash which contains a series |
1296 |
of key value pairs indicating if that field (key) is |
1297 |
hidden (value == 1) or not (value == 0). |
1298 |
|
1299 |
C<$frameworkcode> is the framework code. |
1300 |
|
1301 |
C<$interface> is the interface. It defaults to 'opac' if |
1302 |
nothing is passed. Valid values include 'opac' or 'intranet'. |
1303 |
|
1304 |
=cut |
1305 |
|
1306 |
sub ShouldHideMARC { |
1307 |
my ($parms) = @_; |
1308 |
my $frameworkcode = $parms->{frameworkcode} // ''; |
1309 |
my $interface = $parms->{interface} // 'opac'; |
1310 |
my $display = ShouldDisplayOnInterface(); |
1311 |
|
1312 |
my $dbh = C4::Context->dbh; |
1313 |
my $sth = $dbh->prepare("SELECT kohafield AS field, tagfield AS tag, hidden FROM marc_subfield_structure WHERE kohafield>'' AND frameworkcode=? ORDER BY field, tagfield;"); |
1314 |
$sth->execute($frameworkcode); |
1315 |
|
1316 |
my %shouldhidemarc; |
1317 |
my $data = $sth->fetchall_hashref( [ qw(field tag) ] ); |
1318 |
foreach my $fullfield (keys %{$data}) { |
1319 |
my @tmpsplit = split(/\./,$fullfield); |
1320 |
my $field = $tmpsplit[-1]; |
1321 |
foreach my $tag (keys %{$data->{$fullfield}}) { |
1322 |
my $show = $display->{$interface}->{ $data->{$fullfield}->{$tag}->{'hidden'} }; |
1323 |
if (!$show) { |
1324 |
$shouldhidemarc{ $field } = 1; |
1325 |
} |
1326 |
elsif ( !exists($shouldhidemarc{ $field }) ) { |
1327 |
$shouldhidemarc{ $field } = 0; |
1328 |
} |
1329 |
} |
1330 |
} |
1331 |
return \%shouldhidemarc; |
1332 |
} |
1333 |
|
1250 |
=head2 GetMarcBiblio |
1334 |
=head2 GetMarcBiblio |
1251 |
|
1335 |
|
1252 |
my $record = GetMarcBiblio($biblionumber, [$embeditems]); |
1336 |
my $record = GetMarcBiblio( { |
|
|
1337 |
biblionumber => $biblionumber, |
1338 |
embeditems => $embeditems, |
1339 |
interface => 'opac', |
1340 |
frameworkcode => '', |
1341 |
debug => 0, |
1342 |
} ); |
1343 |
|
1344 |
Returns MARC::Record containing biblio data identified by the |
1345 |
parameters passed. |
1346 |
|
1347 |
C<$biblionumber>. If no bib exists, returns undef. This is |
1348 |
required. Otherwise, this returns nothing. |
1253 |
|
1349 |
|
1254 |
Returns MARC::Record representing bib identified by |
|
|
1255 |
C<$biblionumber>. If no bib exists, returns undef. |
1256 |
C<$embeditems>. If set to true, items data are included. |
1350 |
C<$embeditems>. If set to true, items data are included. |
1257 |
The MARC record contains biblio data, and items data if $embeditems is set to true. |
1351 |
It is optional, and assumed false if omitted. |
|
|
1352 |
|
1353 |
C<$interface>. Valid values include 'opac' or 'intranet'. It is |
1354 |
optional. If not passed, no filtering is done. |
1355 |
|
1356 |
C<$framework>. Any valid framework code. By calling this routine |
1357 |
in the hash style, omitting this parameter is |
1358 |
determined by using the biblionumber. If there is |
1359 |
no framework code defined, regardless of calling |
1360 |
convention, the default one is then used. |
1361 |
|
1362 |
C<$debug>. This optional parameter is not defined in the old |
1363 |
calling style, and so it is defaulted to true. |
1364 |
However, if the new hash parameter style is used, |
1365 |
it defaults to false. This was mostly for testing |
1366 |
purposes. See t/db_dependent/Biblio.t and the |
1367 |
warning_is checks. |
1258 |
|
1368 |
|
1259 |
=cut |
1369 |
=cut |
1260 |
|
1370 |
|
1261 |
sub GetMarcBiblio { |
1371 |
sub GetMarcBiblio { |
1262 |
my $biblionumber = shift; |
1372 |
my @catch_parameters = @_; |
1263 |
my $embeditems = shift || 0; |
1373 |
|
1264 |
my $dbh = C4::Context->dbh; |
1374 |
my $biblionumber; |
1265 |
my $sth = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? "); |
1375 |
my $embeditems; |
|
|
1376 |
my $interface; |
1377 |
my $frameworkcode; |
1378 |
my $debug; # This is useful for generating warns for tests. |
1379 |
|
1380 |
# No parameters, return nothing. |
1381 |
if (! @catch_parameters) { |
1382 |
return; |
1383 |
} |
1384 |
# New style means filtering. |
1385 |
elsif (scalar @catch_parameters==1 && ref($catch_parameters[0]) eq 'HASH') { |
1386 |
$biblionumber = $catch_parameters[0]->{biblionumber}; |
1387 |
$embeditems = $catch_parameters[0]->{embeditems}; |
1388 |
$interface = $catch_parameters[0]->{interface}; |
1389 |
$frameworkcode = $catch_parameters[0]->{frameworkcode}; |
1390 |
if (!$frameworkcode && $interface) { |
1391 |
$frameworkcode = GetFrameworkCode($biblionumber); |
1392 |
} |
1393 |
$debug = $catch_parameters[0]->{debug} // 0; |
1394 |
} |
1395 |
# Old style means no filtering. |
1396 |
else { |
1397 |
$biblionumber = shift @catch_parameters if @catch_parameters; |
1398 |
$embeditems = shift @catch_parameters if @catch_parameters; |
1399 |
} |
1400 |
if (! $biblionumber ) { |
1401 |
return; |
1402 |
} |
1403 |
$embeditems //= 0; # No items by default. |
1404 |
$interface //= 'unfiltered'; # unfiltered if no interface passed. |
1405 |
$frameworkcode //= ''; # Default framework if undefined. |
1406 |
$debug //= 1; # Give message for old style calls. |
1407 |
|
1408 |
my $dbh = C4::Context->dbh; |
1409 |
my $sth = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? "); |
1266 |
$sth->execute($biblionumber); |
1410 |
$sth->execute($biblionumber); |
1267 |
my $row = $sth->fetchrow_hashref; |
1411 |
my $row = $sth->fetchrow_hashref; |
1268 |
my $marcxml = StripNonXmlChars( $row->{'marcxml'} ); |
1412 |
my $marcxml = StripNonXmlChars( $row->{'marcxml'} ); |
Lines 1277-1288
sub GetMarcBiblio {
Link Here
|
1277 |
C4::Biblio::_koha_marc_update_bib_ids($record, '', $biblionumber, $biblionumber); |
1421 |
C4::Biblio::_koha_marc_update_bib_ids($record, '', $biblionumber, $biblionumber); |
1278 |
C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems); |
1422 |
C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems); |
1279 |
|
1423 |
|
|
|
1424 |
# only 'opac' and 'intranet' keys exist, so 'unfiltered' |
1425 |
# won't change anything. |
1426 |
if ($interface ne 'unfiltered') { |
1427 |
$record = GetFilteredBiblio( { |
1428 |
record => $record, |
1429 |
interface => $interface, |
1430 |
frameworkcode => $frameworkcode, |
1431 |
} ); |
1432 |
warn "INTERNAL FILTERING PROCESSED!" if $debug; |
1433 |
|
1434 |
} |
1435 |
else { |
1436 |
warn "INTERNAL FILTERING NOT PROCESSED!" if $debug; |
1437 |
} |
1280 |
return $record; |
1438 |
return $record; |
1281 |
} else { |
1439 |
} else { |
1282 |
return; |
1440 |
return; |
1283 |
} |
1441 |
} |
1284 |
} |
1442 |
} |
1285 |
|
1443 |
|
|
|
1444 |
=head2 GetFilteredBiblio |
1445 |
|
1446 |
Return a MARC::Record which has been filtered based on the |
1447 |
corresponding marc_subfield_structure records for the given |
1448 |
framework and interface ('opac' or 'intranet') |
1449 |
|
1450 |
my $filtered_record = GetFilteredBiblio( { |
1451 |
record => $record, |
1452 |
frameworkcode => $frameworkcode, |
1453 |
interface => 'opac', |
1454 |
} ); |
1455 |
|
1456 |
C<$record> is a MARC::Record. |
1457 |
|
1458 |
C<$frameworkcode> is the framework code. If this is not passed, |
1459 |
the default framework is used. |
1460 |
|
1461 |
C<$interface> is the interface. Valid values include 'opac' and |
1462 |
'intranet' as defined by the hash in ShowDisplayOnInterface. If |
1463 |
this is not passed, 'opac' is used. |
1464 |
|
1465 |
=cut |
1466 |
|
1467 |
sub GetFilteredBiblio { |
1468 |
my ($parms) = @_; |
1469 |
|
1470 |
my $precord = $parms->{record}; |
1471 |
if (!$precord) { |
1472 |
return $precord; |
1473 |
} |
1474 |
my $record = $precord->clone(); |
1475 |
my $interface = $parms->{interface} // 'opac'; |
1476 |
my $frameworkcode = $parms->{frameworkcode} // ''; |
1477 |
my $display = ShouldDisplayOnInterface(); |
1478 |
|
1479 |
my $marcsubfieldstructure = GetMarcStructure(0,$frameworkcode); |
1480 |
#if ($marcsubfieldstructure->{'000'}->{'@'}->{hidden}>0) { |
1481 |
# LDR field is excluded from $record->fields(). |
1482 |
# if we hide it here, the MARCXML->MARC::Record->MARCXML |
1483 |
# transformation blows up. |
1484 |
#} |
1485 |
foreach my $field ($record->fields()) { |
1486 |
my $tag = $field->tag(); |
1487 |
if ($tag>=10) { |
1488 |
foreach my $subpairs ($field->subfields()) { |
1489 |
my ($subtag,$value) = @$subpairs; |
1490 |
# visibility is a "level" (-7 to +7), default to 0 |
1491 |
my $visibility = $marcsubfieldstructure->{$tag}->{$subtag}->{hidden}; |
1492 |
$visibility //= 0; |
1493 |
my $hidden; |
1494 |
if ($display->{$interface}->{$visibility}) { |
1495 |
$hidden = 0; |
1496 |
} |
1497 |
else { |
1498 |
$hidden = 1; |
1499 |
} |
1500 |
if ($hidden) { |
1501 |
# deleting last subfield doesn't delete field, so |
1502 |
# this detects that case to delete the field. |
1503 |
if (scalar $field->subfields() <= 1) { |
1504 |
$record->delete_fields($field); |
1505 |
} |
1506 |
else { |
1507 |
$field->delete_subfield( code => $subtag ); |
1508 |
} |
1509 |
} |
1510 |
} |
1511 |
} |
1512 |
# tags less than 10 don't have subfields, use @ trick. |
1513 |
else { |
1514 |
# visibility is a "level" (-7 to +7), default to 0 |
1515 |
my $visibility = $marcsubfieldstructure->{$tag}->{'@'}->{hidden}; |
1516 |
$visibility //= 0; |
1517 |
my $hidden; |
1518 |
if ($display->{$interface}->{$visibility}) { |
1519 |
$hidden = 0; |
1520 |
} |
1521 |
else { |
1522 |
$hidden = 1; |
1523 |
} |
1524 |
if ($hidden) { |
1525 |
$record->delete_fields($field); |
1526 |
} |
1527 |
} |
1528 |
} |
1529 |
return $record; |
1530 |
} |
1531 |
|
1286 |
=head2 GetXmlBiblio |
1532 |
=head2 GetXmlBiblio |
1287 |
|
1533 |
|
1288 |
my $marcxml = GetXmlBiblio($biblionumber); |
1534 |
my $marcxml = GetXmlBiblio($biblionumber); |
Lines 1867-1873
sub GetMarcSubjects {
Link Here
|
1867 |
push @marcsubjects, { |
2113 |
push @marcsubjects, { |
1868 |
MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop, |
2114 |
MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop, |
1869 |
authoritylink => $authoritylink, |
2115 |
authoritylink => $authoritylink, |
1870 |
}; |
2116 |
} if $authoritylink || @subfields_loop; |
1871 |
|
2117 |
|
1872 |
} |
2118 |
} |
1873 |
return \@marcsubjects; |
2119 |
return \@marcsubjects; |