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 kohafield>'' 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;
1877
1981
1878
    }
1982
    }
1879
    return \@marcsubjects;
1983
    return \@marcsubjects;
(-)a/C4/XSLT.pm (-6 / +11 lines)
Lines 92-103 sub transformMARCXML4XSLT { Link Here
92
                        if $av->{ $tag }->{ $letter };
92
                        if $av->{ $tag }->{ $letter };
93
                    push( @new_subfields, $letter, $value );
93
                    push( @new_subfields, $letter, $value );
94
                } 
94
                } 
95
                $field ->replace_with( MARC::Field->new(
95
                if (@new_subfields) {
96
                    $tag,
96
                    $field ->replace_with( MARC::Field->new(
97
                    $field->indicator(1),
97
                        $tag,
98
                    $field->indicator(2),
98
                        $field->indicator(1),
99
                    @new_subfields
99
                        $field->indicator(2),
100
                ) );
100
                        @new_subfields
101
                    ) );
102
                }
103
                else {
104
                    $record->delete_fields($field);
105
                }
101
            }
106
            }
102
        }
107
        }
103
    }
108
    }
(-)a/opac/opac-ISBDdetail.pl (-2 / +4 lines)
Lines 93-103 if (scalar @items >= 1) { Link Here
93
    }
93
    }
94
}
94
}
95
95
96
my $record = GetMarcBiblio($biblionumber);
96
my $unfiltered_record = GetMarcBiblio($biblionumber);
97
if ( ! $record ) {
97
if ( ! $unfiltered_record ) {
98
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
98
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
99
    exit;
99
    exit;
100
}
100
}
101
my $record = GetFilteredOpacBiblio($unfiltered_record,GetFrameworkCode($biblionumber));
102
101
# some useful variables for enhanced content;
103
# some useful variables for enhanced content;
102
# in each case, we're grabbing the first value we find in
104
# in each case, we're grabbing the first value we find in
103
# the record and normalizing it
105
# the record and normalizing it
(-)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 90-95 if ( ! $record ) { Link Here
90
}
90
}
91
$template->param( biblionumber => $biblionumber );
91
$template->param( biblionumber => $biblionumber );
92
92
93
# Filter out the things to hide in OPAC.
94
my $frameworkcode = GetFrameworkCode($biblionumber);
95
$record = GetFilteredOpacBiblio($record,$frameworkcode);
96
93
# get biblionumbers stored in the cart
97
# get biblionumbers stored in the cart
94
my @cart_list;
98
my @cart_list;
95
99
Lines 376-388 if ($session->param('busc')) { Link Here
376
    my ($previous, $next, $dataBiblioPaging);
380
    my ($previous, $next, $dataBiblioPaging);
377
    # Previous biblio
381
    # Previous biblio
378
    if ($paging{'previous'}->{biblionumber}) {
382
    if ($paging{'previous'}->{biblionumber}) {
379
        $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber}  . '&query_desc=' . $query->param('query_desc');
383
        $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber}  . '&query_desc=' . ($query->param('query_desc') // '');
380
        $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
384
        $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
381
        $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
385
        $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
382
    }
386
    }
383
    # Next biblio
387
    # Next biblio
384
    if ($paging{'next'}->{biblionumber}) {
388
    if ($paging{'next'}->{biblionumber}) {
385
        $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber} . '&query_desc=' . $query->param('query_desc');
389
        $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber} . '&query_desc=' . ($query->param('query_desc') // '');
386
        $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
390
        $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
387
        $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
391
        $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
388
    }
392
    }
Lines 484-489 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { Link Here
484
}
488
}
485
489
486
my $dat = &GetBiblioData($biblionumber);
490
my $dat = &GetBiblioData($biblionumber);
491
my $OpacHideMARC  = GetOpacHideMARC($dat->{'frameworkcode'});
487
492
488
my $itemtypes = GetItemTypes();
493
my $itemtypes = GetItemTypes();
489
# imageurl:
494
# imageurl:
Lines 645-651 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); Link Here
645
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
650
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
646
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
651
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
647
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
652
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
648
my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
653
my ($st_tag,$st_subtag) = GetMarcFromKohaField('bibliosubtitle.subtitle',$dat->{'frameworkcode'});
654
my $subtitle;
655
if ($st_tag && $st_subtag) {
656
    my @subtitles = $record->subfield($st_tag,$st_subtag);
657
    $subtitle = \@subtitles if @subtitles;
658
}
659
if ($subtitle && @$subtitle) {
660
    my @subtitles = map { { subfield => $_ } } @$subtitle;
661
    $subtitle = \@subtitles;
662
}
649
663
650
    $template->param(
664
    $template->param(
651
                     MARCNOTES               => $marcnotesarray,
665
                     MARCNOTES               => $marcnotesarray,
Lines 695-700 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) { Link Here
695
}
709
}
696
710
697
foreach ( keys %{$dat} ) {
711
foreach ( keys %{$dat} ) {
712
    next if ( $OpacHideMARC->{$_} );
698
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
713
    $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
699
}
714
}
700
715
(-)a/opac/opac-export.pl (-3 / +6 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 ($unfiltered_marc, $error, $frameworkcode)= ('','','');
36
37
$unfiltered_marc = GetMarcBiblio($biblionumber, 1) if $biblionumber;
38
$frameworkcode = GetFrameworkCode($biblionumber) if $biblionumber;
39
my $marc = GetFilteredOpacBiblio($unfiltered_marc,$frameworkcode);
36
40
37
$marc = GetMarcBiblio($biblionumber, 1) if $biblionumber;
38
if(!$marc) {
41
if(!$marc) {
39
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
42
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
40
    exit;
43
    exit;
Lines 56-62 elsif ($format =~ /ris/) { Link Here
56
    $format = 'ris';
59
    $format = 'ris';
57
}
60
}
58
elsif ($format =~ /bibtex/) {
61
elsif ($format =~ /bibtex/) {
59
    $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
62
    $marc = marc2bibtex($marc,$biblionumber);
60
    $format = 'bibtex';
63
    $format = 'bibtex';
61
}
64
}
62
elsif ($format =~ /dc/) {
65
elsif ($format =~ /dc/) {
(-)a/opac/opac-showmarc.pl (+6 lines)
Lines 60-65 if(!ref $record) { Link Here
60
60
61
if ($view eq 'card' || $view eq 'html') {
61
if ($view eq 'card' || $view eq 'html') {
62
    my $xmlrecord= $importid? $record->as_xml(): GetXmlBiblio($biblionumber);
62
    my $xmlrecord= $importid? $record->as_xml(): GetXmlBiblio($biblionumber);
63
    if (!$importid && $view eq 'html') {
64
        my $filtered_record = MARC::Record->new_from_xml($xmlrecord);
65
        my $frameworkcode = GetFrameworkCode($biblionumber);
66
        $filtered_record = GetFilteredOpacBiblio($filtered_record,$frameworkcode);
67
        $xmlrecord = $filtered_record->as_xml();
68
    }
63
    my $xslfile;
69
    my $xslfile;
64
    my $xslfilename;
70
    my $xslfilename;
65
    my $htdocs  = C4::Context->config('opachtdocs');
71
    my $htdocs  = C4::Context->config('opachtdocs');
(-)a/t/db_dependent/Biblio.t (-4 / +52 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
11
12
BEGIN {
12
BEGIN {
13
    use_ok('C4::Biblio');
13
    use_ok('C4::Biblio');
14
}
14
}
15
15
16
my $OpacHideMARC = GetOpacHideMARC();
17
my $keycount1 = keys %$OpacHideMARC;
18
ok($keycount1>0,"There are $keycount1 values for the Default framework.");
19
20
$OpacHideMARC = GetOpacHideMARC('YOLO');
21
my $keycount2 = keys %$OpacHideMARC;
22
ok($keycount2==0,'The YOLO framework does not exist.');
23
24
$OpacHideMARC = GetOpacHideMARC('');
25
my $keycount3 = keys %$OpacHideMARC;
26
ok($keycount1>0,"There are $keycount3 values for the Default framework.");
27
ok($keycount1==$keycount3,'The no parameter and empty parameter counts match.');
28
16
my $isbn = '0590353403';
29
my $isbn = '0590353403';
17
my $title = 'Foundation';
30
my $title = 'Foundation';
18
31
Lines 109-113 $field->update('123456789X'); Link Here
109
$controlnumber = GetMarcControlnumber( $marc_record, 'MARC21' );
122
$controlnumber = GetMarcControlnumber( $marc_record, 'MARC21' );
110
is( $controlnumber, '123456789X', 'GetMarcControlnumber handles records with 001' );
123
is( $controlnumber, '123456789X', 'GetMarcControlnumber handles records with 001' );
111
124
125
my $dbh = C4::Context->dbh;
126
127
# the frameworkcode for the added biblio was not set,
128
# so the frameworkcode is '' for Default.
129
my $sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='245' and tagsubfield='a' and frameworkcode='';");
130
$sth->execute();
131
my $hidden = $sth->fetchrow;
132
ok ( defined($hidden), 'There is a 245$a entry for the Default framework.');
133
134
$dbh->do("UPDATE marc_subfield_structure SET hidden=4 WHERE tagfield='245' and tagsubfield='a' and frameworkcode='';");
135
$sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='245' and tagsubfield='a' and frameworkcode='';");
136
$sth->execute();
137
my $new_hidden = $sth->fetchrow;
138
ok ( defined($new_hidden) && $new_hidden==4, 'Default framework 245$a hidden value updated.');
139
140
my $record = GetMarcBiblio($biblionumber);
141
my $fail_filter = GetFilteredOpacBiblio();
142
ok (!defined($fail_filter), 'GetFilteredOpacBiblio properly handles no parameters.');
143
144
my $filtered_record1 = GetFilteredOpacBiblio($record);
145
my $filtered_record2 = GetFilteredOpacBiblio($record,'');
146
my @fields1 = $filtered_record1->fields();
147
my @fields2 = $filtered_record2->fields();
148
ok ( scalar @fields1 == scalar @fields2, 'No framework code matches Default framework results.');
149
150
$title = $record->subfield('245','a');
151
my $filtered_title = $filtered_record1->subfield('245','a');
152
ok ( defined($title) && !defined($filtered_title), 'GetFilteredOpacBiblio filtered title as expected.');
153
154
$sth = $dbh->prepare("UPDATE marc_subfield_structure SET hidden=? WHERE tagfield='245' and tagsubfield='a' AND frameworkcode='';");
155
$sth->execute($hidden);
156
$sth = $dbh->prepare("SELECT hidden FROM marc_subfield_structure WHERE tagfield='245' and tagsubfield='a' and frameworkcode='';");
157
$sth->execute();
158
$new_hidden = $sth->fetchrow;
159
ok ( $new_hidden==$hidden, 'Default framework 245$a hidden value reset.');
160
112
# clean up after ourselves
161
# clean up after ourselves
113
DelBiblio($biblionumber);
162
DelBiblio($biblionumber);
114
- 

Return to bug 11592