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

(-)a/C4/Biblio.pm (-9 / +255 lines)
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;
(-)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 83-89 if (scalar @all_items >= 1) { Link Here
83
    }
83
    }
84
}
84
}
85
85
86
my $record       = GetMarcBiblio($biblionumber);
86
my $record       = GetMarcBiblio( {
87
                                    biblionumber => $biblionumber,
88
                                    interface    => 'opac',
89
                                  } );
87
if ( ! $record ) {
90
if ( ! $record ) {
88
    print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
91
    print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
89
    exit;
92
    exit;
Lines 517-522 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { Link Here
517
}
520
}
518
521
519
my $dat = &GetBiblioData($biblionumber);
522
my $dat = &GetBiblioData($biblionumber);
523
my $HideMARC = ShouldHideMARC( {
524
                                 frameworkcode => $dat->{'frameworkcode'},
525
                                 interface     => 'opac',
526
                               } );
520
527
521
my $itemtypes = GetItemTypes();
528
my $itemtypes = GetItemTypes();
522
# imageurl:
529
# imageurl:
Lines 676-682 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); Link Here
676
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
683
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
677
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
684
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
678
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
685
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
679
my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
686
my ($st_tag,$st_subtag) = GetMarcFromKohaField('bibliosubtitle.subtitle',$dat->{'frameworkcode'});
687
my $subtitle;
688
if ($st_tag && $st_subtag) {
689
    my @subtitles = $record->subfield($st_tag,$st_subtag);
690
    $subtitle = \@subtitles if @subtitles;
691
}
692
if ($subtitle && @$subtitle) {
693
    my @subtitles = map { { subfield => $_ } } @$subtitle;
694
    $subtitle = \@subtitles;
695
}
680
696
681
    $template->param(
697
    $template->param(
682
                     MARCNOTES               => $marcnotesarray,
698
                     MARCNOTES               => $marcnotesarray,
Lines 726-731 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) { Link Here
726
}
742
}
727
743
728
foreach ( keys %{$dat} ) {
744
foreach ( keys %{$dat} ) {
745
    next if ( $HideMARC->{$_} );
729
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
746
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
730
}
747
}
731
748
(-)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 3-9 Link Here
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
5
6
use Test::More tests => 22;
6
use Test::More tests => 23;
7
7
8
BEGIN {
8
BEGIN {
9
        use_ok('C4::Biblio');
9
        use_ok('C4::Biblio');
Lines 12-17 BEGIN { Link Here
12
# test returns if undef record passed
12
# test returns if undef record passed
13
# carp messages appear on stdout
13
# carp messages appear on stdout
14
14
15
my $display1 = {
16
                opac => {
17
                     0 => 1,
18
                    -1 => 1,
19
                    -2 => 1,
20
                    -3 => 1,
21
                    -4 => 1,
22
                    -5 => 1,
23
                    -6 => 1,
24
                    -7 => 1,
25
                },
26
                intranet => {
27
                    -6 => 1,
28
                    -5 => 1,
29
                    -1 => 1,
30
                     0 => 1,
31
                     1 => 1,
32
                     4 => 1,
33
                     6 => 1,
34
                     7 => 1,
35
                },
36
              };
37
my $display2 = ShouldDisplayOnInterface();
38
is_deeply($display2,$display1,'Visibility values confirmed.');
39
15
my @arr = AddBiblio(undef, q{});
40
my @arr = AddBiblio(undef, q{});
16
my $elements = @arr;
41
my $elements = @arr;
17
42
(-)a/t/db_dependent/Biblio.t (-4 / +99 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 3;
20
use Test::More tests => 7;
21
use Test::Warn;
21
use Test::MockModule;
22
use Test::MockModule;
22
23
23
use MARC::Record;
24
use MARC::Record;
Lines 179-184 sub run_tests { Link Here
179
            "(GetMarcISBN) Corretly retrieves ISBN #". ($i + 1));
180
            "(GetMarcISBN) Corretly retrieves ISBN #". ($i + 1));
180
    }
181
    }
181
182
183
    my $unfiltered_record1;
184
    warning_is { $unfiltered_record1 = GetMarcBiblio( $biblionumber ); }
185
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call1.';
186
    my $unfiltered_record2;
187
    warning_is { $unfiltered_record2 = GetMarcBiblio( $biblionumber, 0 ); }
188
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call2.';
189
    my $unfiltered_record3;
190
    warning_is { $unfiltered_record3 =
191
                   GetMarcBiblio( { biblionumber => $biblionumber,
192
                                    debug => 1 } ); }
193
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call3.';
194
    my $unfiltered_record4;
195
    warning_is { $unfiltered_record4 =
196
                   GetMarcBiblio( { biblionumber => $biblionumber,
197
                                    embeditems => 0,
198
                                    debug => 1 } ); }
199
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call4.';
200
201
    is_deeply ( $unfiltered_record2, $unfiltered_record1, '(GetMarcBiblio w/o  items) old implicitly = old explicitly.');
202
    is_deeply ( $unfiltered_record3, $unfiltered_record1, '(GetMarcBiblio w/o  items) old implicitly = new implicitly.');
203
    is_deeply ( $unfiltered_record4, $unfiltered_record1, '(GetMarcBiblio w/o  items) old implicitly = new explicitly.');
204
205
    warning_is { $unfiltered_record1 = GetMarcBiblio( $biblionumber, 1 ); }
206
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call5.';
207
    warning_is { $unfiltered_record2 =
208
                   GetMarcBiblio( { biblionumber => $biblionumber,
209
                                    embeditems   => 1,
210
                                    debug        => 1 } ); }
211
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call6.';
212
213
    is_deeply ( $unfiltered_record2, $unfiltered_record1, '(GetMarcBiblio with items) old explicitly = new explicitly.');
214
215
    # the frameworkcode for the added biblio was not set,
216
    # so the frameworkcode is '' for Default.
217
    my $title_field = ( $marcflavour eq 'UNIMARC' ) ? '200' : '245';
218
    my $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
219
    $sth->execute();
220
    my $hidden = $sth->fetchrow;
221
    if (defined($hidden)) {
222
        ok ( defined($hidden), 'There is a title field entry for the ' . $marcflavour . 'Default framework.');
223
224
        $dbh->do("UPDATE marc_subfield_structure SET hidden=4 WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
225
        $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
226
        $sth->execute();
227
        my $new_hidden = $sth->fetchrow;
228
        ok ( defined($new_hidden) && $new_hidden==4, 'Default framework title field hidden value updated.');
229
230
        my $fail_filter = GetFilteredBiblio();
231
        ok (!defined($fail_filter), 'GetFilteredBiblio properly handles no parameters.');
232
233
        my $filtered_record1 = GetFilteredBiblio( {
234
                                 record => $unfiltered_record1 } );
235
        my $filtered_record2 = GetFilteredBiblio( {
236
                                 record => $unfiltered_record1,
237
                                 frameworkcode => '' } );
238
        my @fields1 = $filtered_record1->fields();
239
        my @fields2 = $filtered_record2->fields();
240
        ok ( scalar @fields1 == scalar @fields2, 'No framework code matches Default framework results.');
241
242
        $title = $unfiltered_record1->subfield($title_field,'a');
243
        my $filtered_title = $filtered_record1->subfield($title_field,'a');
244
        ok ( defined($title) && !defined($filtered_title),
245
             'GetFilteredBiblio filtered title as expected. ' .
246
             "title: " . ($title ? $title : "UNDEF") . " -- " .
247
             "hidden: " . ($filtered_title ? $filtered_title : "UNDEF") );
248
249
        $sth = $dbh->prepare("UPDATE marc_subfield_structure SET hidden=? WHERE tagfield='$title_field' and tagsubfield='a' AND frameworkcode='';");
250
        $sth->execute($hidden);
251
        $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
252
        $sth->execute();
253
        $new_hidden = $sth->fetchrow;
254
        ok ( $new_hidden==$hidden, 'Default framework title field hidden value reset.');
255
    }
256
    else {
257
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
258
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
259
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
260
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
261
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
262
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
263
    }
264
182
}
265
}
183
266
184
sub mock_marcfromkohafield {
267
sub mock_marcfromkohafield {
Lines 240-253 sub create_issn_field { Link Here
240
    return $field;
323
    return $field;
241
}
324
}
242
325
326
my $HideMARC = ShouldHideMARC();
327
my $keycount1 = keys %$HideMARC;
328
ok($keycount1>0,"There are $keycount1 values for the Default framework.");
329
330
$HideMARC = ShouldHideMARC({ frameworkcode => 'YOLO' });
331
my $keycount2 = keys %$HideMARC;
332
ok($keycount2==0,'The YOLO framework does not exist.');
333
334
$HideMARC = ShouldHideMARC({ frameworkcode => '' });
335
my $keycount3 = keys %$HideMARC;
336
ok($keycount1>0,"There are $keycount3 values for the Default framework.");
337
ok($keycount1==$keycount3,'The no parameter and empty parameter counts match.');
338
243
subtest 'MARC21' => sub {
339
subtest 'MARC21' => sub {
244
    plan tests => 25;
340
    plan tests => 41;
245
    run_tests('MARC21');
341
    run_tests('MARC21');
246
    $dbh->rollback;
342
    $dbh->rollback;
247
};
343
};
248
344
249
subtest 'UNIMARC' => sub {
345
subtest 'UNIMARC' => sub {
250
    plan tests => 25;
346
    plan tests => 41;
251
    run_tests('UNIMARC');
347
    run_tests('UNIMARC');
252
    $dbh->rollback;
348
    $dbh->rollback;
253
};
349
};
254
- 

Return to bug 11592