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