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

(-)a/C4/Biblio.pm (-10 / +254 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
    my $rv = $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 || $show==0) {
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 $fields ($record->fields()) {
1498
        my $tag = $fields->tag();
1499
        my $hidden;
1500
        if ($tag>=10) {
1501
            foreach my $subpairs ($fields->subfields()) {
1502
                my ($subtag,$value) = @$subpairs;
1503
                my $visibility = $marcsubfieldstructure->{$tag}->{$subtag}->{hidden};
1504
                $visibility //= 0;
1505
                if ($display->{$interface}->{$visibility}) {
1506
                    $hidden = 0;
1507
                }
1508
                else {
1509
                    $hidden = 1;
1510
                }
1511
                if ($hidden) {
1512
                    # deleting last subfield doesn't delete field, so
1513
                    # this detects that case to delete the field.
1514
                    if (scalar $fields->subfields() <= 1) {
1515
                        $record->delete_fields($fields);
1516
                    }
1517
                    else {
1518
                        $fields->delete_subfield( code => $subtag );
1519
                    }
1520
                }
1521
            }
1522
        }
1523
        # tags less than 10 don't have subfields, use @ trick.
1524
        else {
1525
            my $visibility = $marcsubfieldstructure->{$tag}->{'@'}->{hidden};
1526
            $visibility //= 0;
1527
            if ($display->{$interface}->{$visibility}) {
1528
                $hidden = 0;
1529
            }
1530
            else {
1531
                $hidden = 1;
1532
            }
1533
            if ($hidden) {
1534
                $record->delete_fields($fields);
1535
            }
1536
        }
1537
    }
1538
    return $record;
1539
}
1540
1298
=head2 GetXmlBiblio
1541
=head2 GetXmlBiblio
1299
1542
1300
  my $marcxml = GetXmlBiblio($biblionumber);
1543
  my $marcxml = GetXmlBiblio($biblionumber);
Lines 1427-1433 sub GetCOinSBiblio { Link Here
1427
                $oauthors .= "&amp;rft.au=$au";
1670
                $oauthors .= "&amp;rft.au=$au";
1428
            }
1671
            }
1429
        }
1672
        }
1430
        $title = "&amp;rft." . $titletype . "title=" . $record->subfield( '245', 'a' );
1673
        $title = $record->subfield( '245', 'a' ) // '';
1674
        $title = "&amp;rft." . $titletype . "title=" . $title;
1431
        $subtitle = $record->subfield( '245', 'b' ) || '';
1675
        $subtitle = $record->subfield( '245', 'b' ) || '';
1432
        $title .= $subtitle;
1676
        $title .= $subtitle;
1433
        if ($titletype eq 'a') {
1677
        if ($titletype eq 'a') {
Lines 1878-1884 sub GetMarcSubjects { Link Here
1878
        push @marcsubjects, {
2122
        push @marcsubjects, {
1879
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
2123
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
1880
            authoritylink => $authoritylink,
2124
            authoritylink => $authoritylink,
1881
        };
2125
        } if $authoritylink || @subfields_loop;
1882
2126
1883
    }
2127
    }
1884
    return \@marcsubjects;
2128
    return \@marcsubjects;
(-)a/C4/XSLT.pm (-6 / +11 lines)
Lines 86-97 sub transformMARCXML4XSLT { Link Here
86
                        if $av->{ $tag }->{ $letter };
86
                        if $av->{ $tag }->{ $letter };
87
                    push( @new_subfields, $letter, $value );
87
                    push( @new_subfields, $letter, $value );
88
                } 
88
                } 
89
                $field ->replace_with( MARC::Field->new(
89
                if (@new_subfields) {
90
                    $tag,
90
                    $field ->replace_with( MARC::Field->new(
91
                    $field->indicator(1),
91
                        $tag,
92
                    $field->indicator(2),
92
                        $field->indicator(1),
93
                    @new_subfields
93
                        $field->indicator(2),
94
                ) );
94
                        @new_subfields
95
                    ) );
96
                }
97
                else {
98
                    $record->delete_fields($field);
99
                }
95
            }
100
            }
96
        }
101
        }
97
    }
102
    }
(-)a/opac/opac-ISBDdetail.pl (-1 / +4 lines)
Lines 95-101 if (scalar @items >= 1) { Link Here
95
    }
95
    }
96
}
96
}
97
97
98
my $record = GetMarcBiblio($biblionumber);
98
my $record = GetMarcBiblio( {
99
                              biblionumber => $biblionumber,
100
                              interface    => 'opac',
101
                            } );
99
if ( ! $record ) {
102
if ( ! $record ) {
100
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
103
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
101
    exit;
104
    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 677-683 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); Link Here
677
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
684
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
678
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
685
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
679
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
686
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
680
my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
687
my ($st_tag,$st_subtag) = GetMarcFromKohaField('bibliosubtitle.subtitle',$dat->{'frameworkcode'});
688
my $subtitle;
689
if ($st_tag && $st_subtag) {
690
    my @subtitles = $record->subfield($st_tag,$st_subtag);
691
    $subtitle = \@subtitles if @subtitles;
692
}
693
if ($subtitle && @$subtitle) {
694
    my @subtitles = map { { subfield => $_ } } @$subtitle;
695
    $subtitle = \@subtitles;
696
}
681
697
682
    $template->param(
698
    $template->param(
683
                     MARCNOTES               => $marcnotesarray,
699
                     MARCNOTES               => $marcnotesarray,
Lines 727-732 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) { Link Here
727
}
743
}
728
744
729
foreach ( keys %{$dat} ) {
745
foreach ( keys %{$dat} ) {
746
    next if ( $HideMARC->{$_} );
730
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
747
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
731
}
748
}
732
749
(-)a/opac/opac-export.pl (-3 / +11 lines)
Lines 33-41 my $op=$query->param("op")||''; #op=export is currently the only use Link Here
33
my $format=$query->param("format")||'utf8';
33
my $format=$query->param("format")||'utf8';
34
my $biblionumber = $query->param("bib")||0;
34
my $biblionumber = $query->param("bib")||0;
35
$biblionumber = int($biblionumber);
35
$biblionumber = int($biblionumber);
36
my ($marc, $error)= ('','');
36
my ($marc, $marc_noitems, $error)= ('','','');
37
37
38
$marc = GetMarcBiblio($biblionumber, 1) if $biblionumber;
38
$marc = GetMarcBiblio( {
39
                         biblionumber => $biblionumber,
40
                         embeditems   => 1,
41
                         interface    => 'opac',
42
                       } ) if $biblionumber;
43
$marc_noitems = GetMarcBiblio( {
44
                         biblionumber => $biblionumber,
45
                         interface    => 'opac',
46
                       } ) if $biblionumber;
39
if(!$marc) {
47
if(!$marc) {
40
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
48
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
41
    exit;
49
    exit;
Lines 57-63 elsif ($format =~ /ris/) { Link Here
57
    $format = 'ris';
65
    $format = 'ris';
58
}
66
}
59
elsif ($format =~ /bibtex/) {
67
elsif ($format =~ /bibtex/) {
60
    $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
68
    $marc = marc2bibtex($marc_noitems,$biblionumber);
61
    $format = 'bibtex';
69
    $format = 'bibtex';
62
}
70
}
63
elsif ($format =~ /dc/) {
71
elsif ($format =~ /dc/) {
(-)a/opac/opac-showmarc.pl (-1 / +4 lines)
Lines 44-50 if ($importid) { Link Here
44
    $record = MARC::Record->new_from_usmarc($marc);
44
    $record = MARC::Record->new_from_usmarc($marc);
45
}
45
}
46
else {
46
else {
47
    $record =GetMarcBiblio($biblionumber);
47
    $record =GetMarcBiblio( {
48
                              biblionumber => $biblionumber,
49
                              interface    => 'opac',
50
                            } );
48
}
51
}
49
if(!ref $record) {
52
if(!ref $record) {
50
    print $input->redirect("/cgi-bin/koha/errors/404.pl");
53
    print $input->redirect("/cgi-bin/koha/errors/404.pl");
(-)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 / +100 lines)
Lines 17-24 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;
23
use Data::Dumper;
22
24
23
use MARC::Record;
25
use MARC::Record;
24
use t::lib::Mocks qw( mock_preference );
26
use t::lib::Mocks qw( mock_preference );
Lines 179-184 sub run_tests { Link Here
179
            "(GetMarcISBN) Corretly retrieves ISBN #". ($i + 1));
181
            "(GetMarcISBN) Corretly retrieves ISBN #". ($i + 1));
180
    }
182
    }
181
183
184
    my $unfiltered_record1;
185
    warning_is { $unfiltered_record1 = GetMarcBiblio( $biblionumber ); }
186
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call1.';
187
    my $unfiltered_record2;
188
    warning_is { $unfiltered_record2 = GetMarcBiblio( $biblionumber, 0 ); }
189
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call2.';
190
    my $unfiltered_record3;
191
    warning_is { $unfiltered_record3 =
192
                   GetMarcBiblio( { biblionumber => $biblionumber,
193
                                    debug => 1 } ); }
194
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call3.';
195
    my $unfiltered_record4;
196
    warning_is { $unfiltered_record4 =
197
                   GetMarcBiblio( { biblionumber => $biblionumber,
198
                                    embeditems => 0,
199
                                    debug => 1 } ); }
200
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call4.';
201
202
    is_deeply ( $unfiltered_record2, $unfiltered_record1, '(GetMarcBiblio w/o  items) old implicitly = old explicitly.');
203
    is_deeply ( $unfiltered_record3, $unfiltered_record1, '(GetMarcBiblio w/o  items) old implicitly = new implicitly.');
204
    is_deeply ( $unfiltered_record4, $unfiltered_record1, '(GetMarcBiblio w/o  items) old implicitly = new explicitly.');
205
206
    warning_is { $unfiltered_record1 = GetMarcBiblio( $biblionumber, 1 ); }
207
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call5.';
208
    warning_is { $unfiltered_record2 =
209
                   GetMarcBiblio( { biblionumber => $biblionumber,
210
                                    embeditems   => 1,
211
                                    debug        => 1 } ); }
212
               'INTERNAL FILTERING NOT PROCESSED!', 'GetMarcBiblio Call6.';
213
214
    is_deeply ( $unfiltered_record2, $unfiltered_record1, '(GetMarcBiblio with items) old explicitly = new explicitly.');
215
216
    # the frameworkcode for the added biblio was not set,
217
    # so the frameworkcode is '' for Default.
218
    my $title_field = ( $marcflavour eq 'UNIMARC' ) ? '200' : '245';
219
    my $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
220
    $sth->execute();
221
    my $hidden = $sth->fetchrow;
222
    if (defined($hidden)) {
223
        ok ( defined($hidden), 'There is a title field entry for the ' . $marcflavour . 'Default framework.');
224
225
        $dbh->do("UPDATE marc_subfield_structure SET hidden=4 WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
226
        $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
227
        $sth->execute();
228
        my $new_hidden = $sth->fetchrow;
229
        ok ( defined($new_hidden) && $new_hidden==4, 'Default framework title field hidden value updated.');
230
231
        my $fail_filter = GetFilteredBiblio();
232
        ok (!defined($fail_filter), 'GetFilteredBiblio properly handles no parameters.');
233
234
        my $filtered_record1 = GetFilteredBiblio( {
235
                                 record => $unfiltered_record1 } );
236
        my $filtered_record2 = GetFilteredBiblio( {
237
                                 record => $unfiltered_record1,
238
                                 frameworkcode => '' } );
239
        my @fields1 = $filtered_record1->fields();
240
        my @fields2 = $filtered_record2->fields();
241
        ok ( scalar @fields1 == scalar @fields2, 'No framework code matches Default framework results.');
242
243
        $title = $unfiltered_record1->subfield($title_field,'a');
244
        my $filtered_title = $filtered_record1->subfield($title_field,'a');
245
        ok ( defined($title) && !defined($filtered_title),
246
             'GetFilteredBiblio filtered title as expected. ' .
247
             "title: " . ($title ? $title : "UNDEF") . " -- " .
248
             "hidden: " . ($filtered_title ? $filtered_title : "UNDEF") );
249
250
        $sth = $dbh->prepare("UPDATE marc_subfield_structure SET hidden=? WHERE tagfield='$title_field' and tagsubfield='a' AND frameworkcode='';");
251
        $sth->execute($hidden);
252
        $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='$title_field' and tagsubfield='a' and frameworkcode='';");
253
        $sth->execute();
254
        $new_hidden = $sth->fetchrow;
255
        ok ( $new_hidden==$hidden, 'Default framework title field hidden value reset.');
256
    }
257
    else {
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
        ok ( !defined($hidden), 'Skipping tests for MARC field/subfield hiding under ' . $marcflavour . ' Default framework.');
264
    }
265
182
}
266
}
183
267
184
sub mock_marcfromkohafield {
268
sub mock_marcfromkohafield {
Lines 240-253 sub create_issn_field { Link Here
240
    return $field;
324
    return $field;
241
}
325
}
242
326
327
my $HideMARC = ShouldHideMARC();
328
my $keycount1 = keys %$HideMARC;
329
ok($keycount1>0,"There are $keycount1 values for the Default framework.");
330
331
$HideMARC = ShouldHideMARC({ frameworkcode => 'YOLO' });
332
my $keycount2 = keys %$HideMARC;
333
ok($keycount2==0,'The YOLO framework does not exist.');
334
335
$HideMARC = ShouldHideMARC({ frameworkcode => '' });
336
my $keycount3 = keys %$HideMARC;
337
ok($keycount1>0,"There are $keycount3 values for the Default framework.");
338
ok($keycount1==$keycount3,'The no parameter and empty parameter counts match.');
339
243
subtest 'MARC21' => sub {
340
subtest 'MARC21' => sub {
244
    plan tests => 25;
341
    plan tests => 41;
245
    run_tests('MARC21');
342
    run_tests('MARC21');
246
    $dbh->rollback;
343
    $dbh->rollback;
247
};
344
};
248
345
249
subtest 'UNIMARC' => sub {
346
subtest 'UNIMARC' => sub {
250
    plan tests => 25;
347
    plan tests => 41;
251
    run_tests('UNIMARC');
348
    run_tests('UNIMARC');
252
    $dbh->rollback;
349
    $dbh->rollback;
253
};
350
};
254
- 

Return to bug 11592