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

(-)a/C4/Biblio.pm (-2 / +106 lines)
Lines 79-84 BEGIN { Link Here
79
      &GetMarcSeries
79
      &GetMarcSeries
80
      &GetMarcHosts
80
      &GetMarcHosts
81
      GetMarcUrls
81
      GetMarcUrls
82
      &GetOpacHideMARC
83
      &GetFilteredOpacBiblio
82
      &GetUsedMarcStructure
84
      &GetUsedMarcStructure
83
      &GetXmlBiblio
85
      &GetXmlBiblio
84
      &GetCOinSBiblio
86
      &GetCOinSBiblio
Lines 1207-1212 sub GetUsedMarcStructure { Link Here
1207
    return $sth->fetchall_arrayref( {} );
1209
    return $sth->fetchall_arrayref( {} );
1208
}
1210
}
1209
1211
1212
=head2 GetOpacHideMARC
1213
1214
Return a hash reference of whether a field, built from
1215
kohafield and tag, is hidden in OPAC (1) or not (0).
1216
1217
  my $OpacHideMARC = GetOpacHideMARC($frameworkcode);
1218
1219
  if ($OpacHideMARC->{'stocknumber'}==1) {
1220
       print "Hidden!\n";
1221
  }
1222
1223
C<$OpacHideMARC> is a ref to a hash which contains a series
1224
of key value pairs indicating if that field (key) is
1225
hidden (value == 1) or not (value == 0).
1226
1227
C<$frameworkcode> is the framework code.
1228
1229
=cut
1230
1231
sub GetOpacHideMARC {
1232
    my ( $frameworkcode ) = shift || '';
1233
    my $dbh = C4::Context->dbh;
1234
    my $sth = $dbh->prepare("SELECT kohafield AS field,tagfield AS tag,hidden FROM marc_subfield_structure WHERE LENGTH(kohafield)>0 AND frameworkcode=? ORDER BY field,tagfield;");
1235
    my $rv = $sth->execute($frameworkcode);
1236
    my %opachidemarc;
1237
    my $data = $sth->fetchall_hashref( [ qw(field tag) ] );
1238
    foreach my $fullfield (keys %{$data}) {
1239
        my @tmpsplit = split(/\./,$fullfield);
1240
        my $field = $tmpsplit[-1];
1241
        foreach my $tag (keys %{$data->{$fullfield}}) {
1242
            if ($data->{$fullfield}->{$tag}->{'hidden'}>0) {
1243
                $opachidemarc{ $field } = 1;
1244
            }
1245
            elsif ( !exists($opachidemarc{ $field }) ) {
1246
                $opachidemarc{ $field } = 0;
1247
            }
1248
        }
1249
    }
1250
    return \%opachidemarc;
1251
}
1252
1253
=head2 GetFilteredOpacBiblio
1254
1255
Return a MARC::Record which has been filtered based
1256
on the corresponding marc_subfield_structure records
1257
for the given framework by excluding hidden>0.
1258
1259
  my $filtered_record = GetFilteredOpacBiblio($record,$frameworkcode);
1260
1261
C<$record> is a MARC::Record.
1262
1263
C<$frameworkcode> is the framework code.
1264
1265
=cut
1266
1267
sub GetFilteredOpacBiblio {
1268
    my ( $record ) = shift;
1269
    if (!$record) { return $record; }
1270
    my $filtered_record = $record->clone;
1271
1272
    my ( $frameworkcode ) = shift || '';
1273
1274
    my $marcsubfieldstructure = GetMarcStructure(0,$frameworkcode);
1275
    if ($marcsubfieldstructure->{'000'}->{'@'}->{hidden}>0) {
1276
        # LDR field is excluded from $record->fields().
1277
        # if we hide it here, the MARCXML->MARC::Record->MARCXML transformation blows up.
1278
    }
1279
    foreach my $fields ($filtered_record->fields()) {
1280
        my $tag = $fields->tag();
1281
        if ($tag>=10) {
1282
            foreach my $subpairs ($fields->subfields()) {
1283
                my ($subtag,$value) = @$subpairs;
1284
                my $hidden = $marcsubfieldstructure->{$tag}->{$subtag}->{hidden};
1285
                $hidden //= 0;
1286
                $hidden = ($hidden<=0) ? 0 : 1;
1287
                if ($hidden) {
1288
                    # deleting last subfield doesn't delete field, so
1289
                    # this detects that case to delete the field.
1290
                    if (scalar $fields->subfields() <= 1) {
1291
                        $filtered_record->delete_fields($fields);
1292
                    }
1293
                    else {
1294
                        $fields->delete_subfield( code => $subtag );
1295
                    }
1296
                }
1297
            }
1298
        }
1299
        # tags less than 10 don't have subfields, use @ trick.
1300
        else {
1301
            my $hidden = $marcsubfieldstructure->{$tag}->{'@'}->{hidden};
1302
            $hidden //= 0;
1303
            $hidden = ($hidden<=0) ? 0 : 1;
1304
            if ($hidden) {
1305
                $filtered_record->delete_fields($fields);
1306
            }
1307
        }
1308
    }
1309
1310
    return $filtered_record;
1311
}
1312
1210
=head2 GetMarcFromKohaField
1313
=head2 GetMarcFromKohaField
1211
1314
1212
  ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
1315
  ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
Lines 1427-1433 sub GetCOinSBiblio { Link Here
1427
                $oauthors .= "&amp;rft.au=$au";
1530
                $oauthors .= "&amp;rft.au=$au";
1428
            }
1531
            }
1429
        }
1532
        }
1430
        $title = "&amp;rft." . $titletype . "title=" . $record->subfield( '245', 'a' );
1533
        $title = $record->subfield( '245', 'a' ) || '';
1534
        $title = "&amp;rft." . $titletype . "title=" . $title;
1431
        $subtitle = $record->subfield( '245', 'b' ) || '';
1535
        $subtitle = $record->subfield( '245', 'b' ) || '';
1432
        $title .= $subtitle;
1536
        $title .= $subtitle;
1433
        if ($titletype eq 'a') {
1537
        if ($titletype eq 'a') {
Lines 1873-1879 sub GetMarcSubjects { Link Here
1873
        push @marcsubjects, {
1977
        push @marcsubjects, {
1874
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
1978
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
1875
            authoritylink => $authoritylink,
1979
            authoritylink => $authoritylink,
1876
        };
1980
        } if $authoritylink || $#subfields_loop>=0;
1877
1981
1878
    }
1982
    }
1879
    return \@marcsubjects;
1983
    return \@marcsubjects;
(-)a/C4/XSLT.pm (-6 / +11 lines)
Lines 93-104 sub transformMARCXML4XSLT { Link Here
93
                        if $av->{ $tag }->{ $letter };
93
                        if $av->{ $tag }->{ $letter };
94
                    push( @new_subfields, $letter, $value );
94
                    push( @new_subfields, $letter, $value );
95
                } 
95
                } 
96
                $field ->replace_with( MARC::Field->new(
96
                if (@new_subfields) {
97
                    $tag,
97
                    $field ->replace_with( MARC::Field->new(
98
                    $field->indicator(1),
98
                        $tag,
99
                    $field->indicator(2),
99
                        $field->indicator(1),
100
                    @new_subfields
100
                        $field->indicator(2),
101
                ) );
101
                        @new_subfields
102
                    ) );
103
                }
104
                else {
105
                    $record->delete_fields($field);
106
                }
102
            }
107
            }
103
        }
108
        }
104
    }
109
    }
(-)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 (-3 / +18 lines)
Lines 91-96 if ( ! $record ) { Link Here
91
}
91
}
92
$template->param( biblionumber => $biblionumber );
92
$template->param( biblionumber => $biblionumber );
93
93
94
# Filter out the things to hide in OPAC.
95
my $frameworkcode = GetFrameworkCode($biblionumber);
96
$record = GetFilteredOpacBiblio($record,$frameworkcode);
97
94
# get biblionumbers stored in the cart
98
# get biblionumbers stored in the cart
95
my @cart_list;
99
my @cart_list;
96
100
Lines 377-389 if ($session->param('busc')) { Link Here
377
    my ($previous, $next, $dataBiblioPaging);
381
    my ($previous, $next, $dataBiblioPaging);
378
    # Previous biblio
382
    # Previous biblio
379
    if ($paging{'previous'}->{biblionumber}) {
383
    if ($paging{'previous'}->{biblionumber}) {
380
        $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber}  . '&query_desc=' . $query->param('query_desc');
384
        $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber}  . '&query_desc=' . ($query->param('query_desc') // '');
381
        $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
385
        $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
382
        $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
386
        $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
383
    }
387
    }
384
    # Next biblio
388
    # Next biblio
385
    if ($paging{'next'}->{biblionumber}) {
389
    if ($paging{'next'}->{biblionumber}) {
386
        $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber} . '&query_desc=' . $query->param('query_desc');
390
        $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber} . '&query_desc=' . ($query->param('query_desc') // '');
387
        $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
391
        $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
388
        $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
392
        $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
389
    }
393
    }
Lines 485-490 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { Link Here
485
}
489
}
486
490
487
my $dat = &GetBiblioData($biblionumber);
491
my $dat = &GetBiblioData($biblionumber);
492
my $OpacHideMARC  = &GetOpacHideMARC($dat->{'frameworkcode'});
488
493
489
my $itemtypes = GetItemTypes();
494
my $itemtypes = GetItemTypes();
490
# imageurl:
495
# imageurl:
Lines 646-652 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); Link Here
646
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
651
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
647
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
652
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
648
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
653
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
649
my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
654
my ($st_tag,$st_subtag) = GetMarcFromKohaField('bibliosubtitle.subtitle',$dat->{'frameworkcode'});
655
my $subtitle;
656
if ($st_tag && $st_subtag) {
657
    my @subtitles = $record->subfield($st_tag,$st_subtag);
658
    $subtitle = \@subtitles if scalar @subtitles;
659
}
660
if ($subtitle && scalar @$subtitle) {
661
    my @subtitles = map { { subfield => $_ } } @$subtitle;
662
    $subtitle = \@subtitles;
663
}
650
664
651
    $template->param(
665
    $template->param(
652
                     MARCNOTES               => $marcnotesarray,
666
                     MARCNOTES               => $marcnotesarray,
Lines 696-701 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) { Link Here
696
}
710
}
697
711
698
foreach ( keys %{$dat} ) {
712
foreach ( keys %{$dat} ) {
713
    next if ( $OpacHideMARC->{$_} );
699
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
714
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
700
}
715
}
701
716
(-)a/opac/opac-showmarc.pl (+6 lines)
Lines 57-62 else { Link Here
57
57
58
if ($view eq 'card' || $view eq 'html') {
58
if ($view eq 'card' || $view eq 'html') {
59
    my $xmlrecord= $importid? $record->as_xml(): GetXmlBiblio($biblionumber);
59
    my $xmlrecord= $importid? $record->as_xml(): GetXmlBiblio($biblionumber);
60
    if (!$importid && $view eq 'html') {
61
        my $filtered_record = MARC::Record->new_from_xml($xmlrecord);
62
        my $frameworkcode = GetFrameworkCode($biblionumber);
63
        $filtered_record = GetFilteredOpacBiblio($filtered_record,$frameworkcode);
64
        $xmlrecord = $filtered_record->as_xml();
65
    }
60
    my $xslfile;
66
    my $xslfile;
61
    my $xslfilename;
67
    my $xslfilename;
62
    my $htdocs  = C4::Context->config('opachtdocs');
68
    my $htdocs  = C4::Context->config('opachtdocs');
(-)a/t/db_dependent/Biblio.t (-4 / +53 lines)
Lines 3-18 Link Here
3
# This Koha test module is a stub!  
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
4
# Add more tests here!!!
5
5
6
use strict;
6
use Modern::Perl;
7
use warnings;
7
use Test::More tests => 27;
8
use Test::More tests => 17;
9
use MARC::Record;
8
use MARC::Record;
10
use C4::Biblio;
9
use C4::Biblio;
10
use C4::Context;
11
use Data::Dumper;
11
12
12
BEGIN {
13
BEGIN {
13
    use_ok('C4::Biblio');
14
    use_ok('C4::Biblio');
14
}
15
}
15
16
17
my $OpacHideMARC = GetOpacHideMARC();
18
my $keycount1 = keys %$OpacHideMARC;
19
ok($keycount1>0,"There are $keycount1 values for the Default framework.");
20
21
$OpacHideMARC = GetOpacHideMARC('YOLO');
22
my $keycount2 = keys %$OpacHideMARC;
23
ok($keycount2==0,'The YOLO framework does not exist.');
24
25
$OpacHideMARC = GetOpacHideMARC('');
26
my $keycount3 = keys %$OpacHideMARC;
27
ok($keycount1>0,"There are $keycount3 values for the Default framework.");
28
ok($keycount1==$keycount3,'The no parameter and empty parameter counts match.');
29
16
my $isbn = '0590353403';
30
my $isbn = '0590353403';
17
my $title = 'Foundation';
31
my $title = 'Foundation';
18
32
Lines 109-113 $field->update('123456789X'); Link Here
109
$controlnumber = GetMarcControlnumber( $marc_record, 'MARC21' );
123
$controlnumber = GetMarcControlnumber( $marc_record, 'MARC21' );
110
is( $controlnumber, '123456789X', 'GetMarcControlnumber handles records with 001' );
124
is( $controlnumber, '123456789X', 'GetMarcControlnumber handles records with 001' );
111
125
126
my $dbh = C4::Context->dbh;
127
128
# the frameworkcode for the added biblio was not set,
129
# so the frameworkcode is '' for Default.
130
my $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='245' and tagsubfield='a' and frameworkcode='';");
131
$sth->execute();
132
my $hidden = $sth->fetchrow;
133
ok ( defined($hidden), 'There is a 245$a entry for the Default framework.');
134
135
$dbh->do("UPDATE marc_subfield_structure SET hidden=4 WHERE tagfield='245' and tagsubfield='a' and frameworkcode='';");
136
$sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='245' and tagsubfield='a' and frameworkcode='';");
137
$sth->execute();
138
my $new_hidden = $sth->fetchrow;
139
ok ( defined($new_hidden) && $new_hidden==4, 'Default framework 245$a hidden value updated.');
140
141
my $record = GetMarcBiblio($biblionumber);
142
my $fail_filter = GetFilteredOpacBiblio();
143
ok (!defined($fail_filter), 'GetFilteredOpacBiblio properly handles no parameters.');
144
145
my $filtered_record1 = GetFilteredOpacBiblio($record);
146
my $filtered_record2 = GetFilteredOpacBiblio($record,'');
147
my @fields1 = $filtered_record1->fields();
148
my @fields2 = $filtered_record2->fields();
149
ok ( scalar @fields1 == scalar @fields2, 'No framework code matches Default framework results.');
150
151
$title = $record->subfield('245','a');
152
my $filtered_title = $filtered_record1->subfield('245','a');
153
ok ( defined($title) && !defined($filtered_title), 'GetFilteredOpacBiblio filtered title as expected.');
154
155
$sth = $dbh->prepare("UPDATE marc_subfield_structure SET hidden=? WHERE tagfield='245' and tagsubfield='a' AND frameworkcode='';");
156
$sth->execute($hidden);
157
$sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='245' and tagsubfield='a' and frameworkcode='';");
158
$sth->execute();
159
$new_hidden = $sth->fetchrow;
160
ok ( $new_hidden==$hidden, 'Default framework 245$a hidden value reset.');
161
112
# clean up after ourselves
162
# clean up after ourselves
113
DelBiblio($biblionumber);
163
DelBiblio($biblionumber);
114
- 

Return to bug 11592