View | Details | Raw Unified | Return to bug 11592
Collapse All | Expand All

(-)a/C4/Biblio.pm (-9 / +255 lines)
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;
(-)a/C4/XSLT.pm (-6 / +11 lines)
Lines 85-96 sub transformMARCXML4XSLT { Link Here
85
                        if $av->{ $tag }->{ $letter };
85
                        if $av->{ $tag }->{ $letter };
86
                    push( @new_subfields, $letter, $value );
86
                    push( @new_subfields, $letter, $value );
87
                } 
87
                } 
88
                $field ->replace_with( MARC::Field->new(
88
                if (@new_subfields) {
89
                    $tag,
89
                    $field ->replace_with( MARC::Field->new(
90
                    $field->indicator(1),
90
                        $tag,
91
                    $field->indicator(2),
91
                        $field->indicator(1),
92
                    @new_subfields
92
                        $field->indicator(2),
93
                ) );
93
                        @new_subfields
94
                    ) );
95
                }
96
                else {
97
                    $record->delete_fields($field);
98
                }
94
            }
99
            }
95
        }
100
        }
96
    }
101
    }
(-)a/opac/opac-ISBDdetail.pl (-1 / +4 lines)
Lines 93-99 if (scalar @items >= 1) { Link Here
93
    }
93
    }
94
}
94
}
95
95
96
my $record = GetMarcBiblio($biblionumber);
96
my $record = GetMarcBiblio( {
97
                              biblionumber => $biblionumber,
98
                              interface    => 'opac',
99
                            } );
97
if ( ! $record ) {
100
if ( ! $record ) {
98
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
101
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
99
    exit;
102
    exit;
(-)a/opac/opac-MARCdetail.pl (-1 / +2 lines)
Lines 98-106 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
98
    }
98
    }
99
);
99
);
100
100
101
my ($bt_tag,$bt_subtag) = GetMarcFromKohaField('biblio.title',$itemtype);
101
$template->param(
102
$template->param(
102
    bibliotitle => $biblio->{title},
103
    bibliotitle => $biblio->{title},
103
);
104
) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0;
104
105
105
# get biblionumbers stored in the cart
106
# get biblionumbers stored in the cart
106
my @cart_list;
107
my @cart_list;
(-)a/opac/opac-detail.pl (-2 / +19 lines)
Lines 84-90 if (scalar @all_items >= 1) { Link Here
84
    }
84
    }
85
}
85
}
86
86
87
my $record       = GetMarcBiblio($biblionumber);
87
my $record       = GetMarcBiblio( {
88
                                    biblionumber => $biblionumber,
89
                                    interface    => 'opac',
90
                                  } );
88
if ( ! $record ) {
91
if ( ! $record ) {
89
    print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
92
    print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
90
    exit;
93
    exit;
Lines 518-523 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { Link Here
518
}
521
}
519
522
520
my $dat = &GetBiblioData($biblionumber);
523
my $dat = &GetBiblioData($biblionumber);
524
my $HideMARC = ShouldHideMARC( {
525
                                 frameworkcode => $dat->{'frameworkcode'},
526
                                 interface     => 'opac',
527
                               } );
521
528
522
my $itemtypes = GetItemTypes();
529
my $itemtypes = GetItemTypes();
523
# imageurl:
530
# imageurl:
Lines 707-713 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); Link Here
707
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
714
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
708
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
715
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
709
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
716
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
710
my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
717
my ($st_tag,$st_subtag) = GetMarcFromKohaField('bibliosubtitle.subtitle',$dat->{'frameworkcode'});
718
my $subtitle;
719
if ($st_tag && $st_subtag) {
720
    my @subtitles = $record->subfield($st_tag,$st_subtag);
721
    $subtitle = \@subtitles if @subtitles;
722
}
723
if ($subtitle && @$subtitle) {
724
    my @subtitles = map { { subfield => $_ } } @$subtitle;
725
    $subtitle = \@subtitles;
726
}
711
727
712
    $template->param(
728
    $template->param(
713
                     MARCNOTES               => $marcnotesarray,
729
                     MARCNOTES               => $marcnotesarray,
Lines 757-762 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) { Link Here
757
}
773
}
758
774
759
foreach ( keys %{$dat} ) {
775
foreach ( keys %{$dat} ) {
776
    next if ( $HideMARC->{$_} );
760
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
777
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
761
}
778
}
762
779
(-)a/opac/opac-export.pl (-3 / +11 lines)
Lines 32-40 my $op=$query->param("op")||''; #op=export is currently the only use Link Here
32
my $format=$query->param("format")||'utf8';
32
my $format=$query->param("format")||'utf8';
33
my $biblionumber = $query->param("bib")||0;
33
my $biblionumber = $query->param("bib")||0;
34
$biblionumber = int($biblionumber);
34
$biblionumber = int($biblionumber);
35
my ($marc, $error)= ('','');
35
my ($marc, $marc_noitems, $error)= ('','','');
36
36
37
$marc = GetMarcBiblio($biblionumber, 1) if $biblionumber;
37
$marc = GetMarcBiblio( {
38
                         biblionumber => $biblionumber,
39
                         embeditems   => 1,
40
                         interface    => 'opac',
41
                       } ) if $biblionumber;
42
$marc_noitems = GetMarcBiblio( {
43
                         biblionumber => $biblionumber,
44
                         interface    => 'opac',
45
                       } ) if $biblionumber;
38
if(!$marc) {
46
if(!$marc) {
39
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
47
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
40
    exit;
48
    exit;
Lines 56-62 elsif ($format =~ /ris/) { Link Here
56
    $format = 'ris';
64
    $format = 'ris';
57
}
65
}
58
elsif ($format =~ /bibtex/) {
66
elsif ($format =~ /bibtex/) {
59
    $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
67
    $marc = marc2bibtex($marc_noitems,$biblionumber);
60
    $format = 'bibtex';
68
    $format = 'bibtex';
61
}
69
}
62
elsif ($format =~ /dc/) {
70
elsif ($format =~ /dc/) {
(-)a/opac/opac-showmarc.pl (-1 / +12 lines)
Lines 43-49 if ($importid) { Link Here
43
    $record = MARC::Record->new_from_usmarc($marc);
43
    $record = MARC::Record->new_from_usmarc($marc);
44
}
44
}
45
else {
45
else {
46
    $record =GetMarcBiblio($biblionumber);
46
    $record =GetMarcBiblio( {
47
                              biblionumber => $biblionumber,
48
                              interface    => 'opac',
49
                            } );
47
}
50
}
48
if(!ref $record) {
51
if(!ref $record) {
49
    print $input->redirect("/cgi-bin/koha/errors/404.pl");
52
    print $input->redirect("/cgi-bin/koha/errors/404.pl");
Lines 52-57 if(!ref $record) { Link Here
52
55
53
if ($view eq 'card' || $view eq 'html') {
56
if ($view eq 'card' || $view eq 'html') {
54
    my $xmlrecord= $importid? $record->as_xml(): GetXmlBiblio($biblionumber);
57
    my $xmlrecord= $importid? $record->as_xml(): GetXmlBiblio($biblionumber);
58
    if (!$importid && $view eq 'html') {
59
        my $filtered_record = MARC::Record->new_from_xml($xmlrecord);
60
        my $frameworkcode = GetFrameworkCode($biblionumber);
61
        $filtered_record = GetFilteredBiblio( {
62
                             record        => $filtered_record,
63
                             frameworkcode => $frameworkcode } );
64
        $xmlrecord = $filtered_record->as_xml();
65
    }
55
    my $xslfile;
66
    my $xslfile;
56
    my $xslfilename;
67
    my $xslfilename;
57
    my $htdocs  = C4::Context->config('opachtdocs');
68
    my $htdocs  = C4::Context->config('opachtdocs');
(-)a/t/Biblio.t (-1 / +26 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 42;
20
use Test::More tests => 43;
21
use Test::Warn;
21
use Test::Warn;
22
22
23
BEGIN {
23
BEGIN {
Lines 27-32 BEGIN { Link Here
27
my @arr;
27
my @arr;
28
my $ret;
28
my $ret;
29
29
30
my $display1 = {
31
                opac => {
32
                     0 => 1,
33
                    -1 => 1,
34
                    -2 => 1,
35
                    -3 => 1,
36
                    -4 => 1,
37
                    -5 => 1,
38
                    -6 => 1,
39
                    -7 => 1,
40
                },
41
                intranet => {
42
                    -6 => 1,
43
                    -5 => 1,
44
                    -1 => 1,
45
                     0 => 1,
46
                     1 => 1,
47
                     4 => 1,
48
                     6 => 1,
49
                     7 => 1,
50
                },
51
              };
52
my $display2 = ShouldDisplayOnInterface();
53
is_deeply($display2,$display1,'Visibility values confirmed.');
54
30
warning_is { @arr = AddBiblio(undef, q{}) }
55
warning_is { @arr = AddBiblio(undef, q{}) }
31
           { carped => 'AddBiblio called with undefined record'},
56
           { carped => 'AddBiblio called with undefined record'},
32
           "AddBiblio returns carped warning on undef record";
57
           "AddBiblio returns carped warning on undef record";
(-)a/t/db_dependent/Biblio.t (-6 / +101 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 4;
20
use Test::More tests => 8;
21
use Test::Warn;
21
use Test::MockModule;
22
use Test::MockModule;
22
23
23
use MARC::Record;
24
use MARC::Record;
Lines 191-199 sub run_tests { Link Here
191
            "(GetMarcISBN) Corretly retrieves ISBN #". ($i + 1));
192
            "(GetMarcISBN) Corretly retrieves ISBN #". ($i + 1));
192
    }
193
    }
193
194
194
195
    is( GetMarcPrice( $record_for_isbn, $marcflavour ), 100,
195
    is( GetMarcPrice( $record_for_isbn, $marcflavour ), 100,
196
        "GetMarcPrice returns the correct value");
196
        "GetMarcPrice returns the correct value");
197
198
    my $unfiltered_record1;
199
    warning_is { $unfiltered_record1 = GetMarcBiblio( $biblionumber ); }
200
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call1.';
201
    my $unfiltered_record2;
202
    warning_is { $unfiltered_record2 = GetMarcBiblio( $biblionumber, 0 ); }
203
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call2.';
204
    my $unfiltered_record3;
205
    warning_is { $unfiltered_record3 =
206
                   GetMarcBiblio( { biblionumber => $biblionumber,
207
                                    debug => 1 } ); }
208
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call3.';
209
    my $unfiltered_record4;
210
    warning_is { $unfiltered_record4 =
211
                   GetMarcBiblio( { biblionumber => $biblionumber,
212
                                    embeditems => 0,
213
                                    debug => 1 } ); }
214
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call4.';
215
216
    is_deeply ( $unfiltered_record2, $unfiltered_record1, '(GetMarcBiblio w/o  items) old implicitly = old explicitly.');
217
    is_deeply ( $unfiltered_record3, $unfiltered_record1, '(GetMarcBiblio w/o  items) old implicitly = new implicitly.');
218
    is_deeply ( $unfiltered_record4, $unfiltered_record1, '(GetMarcBiblio w/o  items) old implicitly = new explicitly.');
219
220
    warning_is { $unfiltered_record1 = GetMarcBiblio( $biblionumber, 1 ); }
221
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call5.';
222
    warning_is { $unfiltered_record2 =
223
                   GetMarcBiblio( { biblionumber => $biblionumber,
224
                                    embeditems   => 1,
225
                                    debug        => 1 } ); }
226
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call6.';
227
228
    is_deeply ( $unfiltered_record2, $unfiltered_record1, '(GetMarcBiblio with items) old explicitly = new explicitly.');
229
230
    # the frameworkcode for the added biblio was not set,
231
    # so the frameworkcode is '' for Default.
232
    my $title_field = ( $marcflavour eq 'UNIMARC' ) ? '200' : '245';
233
    my $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
234
    $sth->execute();
235
    my $hidden = $sth->fetchrow;
236
    if (defined($hidden)) {
237
        ok ( defined($hidden), 'There is a title field entry for the ' . $marcflavour . 'Default framework.');
238
239
        $dbh->do("UPDATE marc_subfield_structure SET hidden=4 WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
240
        $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
241
        $sth->execute();
242
        my $new_hidden = $sth->fetchrow;
243
        ok ( defined($new_hidden) && $new_hidden==4, 'Default framework title field hidden value updated.');
244
245
        my $fail_filter = GetFilteredBiblio();
246
        ok (!defined($fail_filter), 'GetFilteredBiblio properly handles no parameters.');
247
248
        my $filtered_record1 = GetFilteredBiblio( {
249
                                 record => $unfiltered_record1 } );
250
        my $filtered_record2 = GetFilteredBiblio( {
251
                                 record => $unfiltered_record1,
252
                                 frameworkcode => '' } );
253
        my @fields1 = $filtered_record1->fields();
254
        my @fields2 = $filtered_record2->fields();
255
        ok ( scalar @fields1 == scalar @fields2, 'No framework code matches Default framework results.');
256
257
        $title = $unfiltered_record1->subfield($title_field,'a');
258
        my $filtered_title = $filtered_record1->subfield($title_field,'a');
259
        ok ( defined($title) && !defined($filtered_title),
260
             'GetFilteredBiblio filtered title as expected. ' .
261
             "title: " . ($title ? $title : "UNDEF") . " -- " .
262
             "hidden: " . ($filtered_title ? $filtered_title : "UNDEF") );
263
264
        $sth = $dbh->prepare("UPDATE marc_subfield_structure SET hidden=? WHERE tagfield='$title_field' and tagsubfield='a' AND frameworkcode='';");
265
        $sth->execute($hidden);
266
        $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
267
        $sth->execute();
268
        $new_hidden = $sth->fetchrow;
269
        ok ( $new_hidden==$hidden, 'Default framework title field hidden value reset.');
270
    }
271
    else {
272
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
273
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
274
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
275
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
276
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
277
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
278
    }
279
197
}
280
}
198
281
199
sub mock_marcfromkohafield {
282
sub mock_marcfromkohafield {
Lines 259-278 sub create_issn_field { Link Here
259
    return $field;
342
    return $field;
260
}
343
}
261
344
345
my $HideMARC = ShouldHideMARC();
346
my $keycount1 = keys %$HideMARC;
347
ok($keycount1>0,"There are $keycount1 values for the Default framework.");
348
349
$HideMARC = ShouldHideMARC({ frameworkcode => 'YOLO' });
350
my $keycount2 = keys %$HideMARC;
351
ok($keycount2==0,'The YOLO framework does not exist.');
352
353
$HideMARC = ShouldHideMARC({ frameworkcode => '' });
354
my $keycount3 = keys %$HideMARC;
355
ok($keycount1>0,"There are $keycount3 values for the Default framework.");
356
ok($keycount1==$keycount3,'The no parameter and empty parameter counts match.');
357
262
subtest 'MARC21' => sub {
358
subtest 'MARC21' => sub {
263
    plan tests => 27;
359
    plan tests => 43;
264
    run_tests('MARC21');
360
    run_tests('MARC21');
265
    $dbh->rollback;
361
    $dbh->rollback;
266
};
362
};
267
363
268
subtest 'UNIMARC' => sub {
364
subtest 'UNIMARC' => sub {
269
    plan tests => 27;
365
    plan tests => 43;
270
    run_tests('UNIMARC');
366
    run_tests('UNIMARC');
271
    $dbh->rollback;
367
    $dbh->rollback;
272
};
368
};
273
369
274
subtest 'NORMARC' => sub {
370
subtest 'NORMARC' => sub {
275
    plan tests => 27;
371
    plan tests => 43;
276
    run_tests('NORMARC');
372
    run_tests('NORMARC');
277
    $dbh->rollback;
373
    $dbh->rollback;
278
};
374
};
279
- 

Return to bug 11592