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

(-)a/C4/Biblio.pm (-2 / +104 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 SUBSTRING(kohafield,LOCATE('.',kohafield)+1,40) AS field,tagfield AS tag,hidden FROM marc_subfield_structure WHERE LENGTH(TRIM(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 $field (keys %{$data}) {
1239
        foreach my $tag (keys %{$data->{$field}}) {
1240
            if ($data->{$field}->{$tag}->{'hidden'}>0) {
1241
                $opachidemarc{ $field } = 1;
1242
            }
1243
            elsif ( !exists($opachidemarc{ $field }) ) {
1244
                $opachidemarc{ $field } = 0;
1245
            }
1246
        }
1247
    }
1248
    return \%opachidemarc;
1249
}
1250
1251
=head2 GetFilteredOpacBiblio
1252
1253
Return a MARC::Record which has been filtered based
1254
on the corresponding marc_subfield_structure records
1255
for the given framework by excluding hidden>0.
1256
1257
  my $filtered_record = GetFilteredOpacBiblio($record,$frameworkcode);
1258
1259
C<$record> is a MARC::Record.
1260
1261
C<$frameworkcode> is the framework code.
1262
1263
=cut
1264
1265
sub GetFilteredOpacBiblio {
1266
    my ( $record ) = shift;
1267
    if (!$record) { return $record; }
1268
1269
    my ( $frameworkcode ) = shift || '';
1270
1271
    my $marcsubfieldstructure = GetMarcStructure(0,$frameworkcode);
1272
    if ($marcsubfieldstructure->{'000'}->{'@'}->{hidden}>0) {
1273
        # LDR field is excluded from $record->fields().
1274
        # if we hide it here, the MARCXML->MARC::Record->MARCXML transformation blows up.
1275
        print STDERR "Supposed to hide LEADER\n";
1276
    }
1277
    foreach my $fields ($record->fields()) {
1278
        my $tag = $fields->tag();
1279
        if ($tag>=10) {
1280
            foreach my $subpairs ($fields->subfields()) {
1281
                my ($subtag,$value) = @$subpairs;
1282
                my $hidden = $marcsubfieldstructure->{$tag}->{$subtag}->{hidden};
1283
                $hidden //= 0;
1284
                $hidden = ($hidden<=0) ? 0 : 1;
1285
                if ($hidden) {
1286
                    # deleting last subfield doesn't delete field, so
1287
                    # this detects that case to delete the field.
1288
                    if (scalar $fields->subfields() <= 1) {
1289
                        $record->delete_fields($fields);
1290
                    }
1291
                    else {
1292
                        $fields->delete_subfield( code => $subtag );
1293
                    }
1294
                }
1295
            }
1296
        }
1297
        # tags less than 10 don't have subfields, use @ trick.
1298
        else {
1299
            my $hidden = $marcsubfieldstructure->{$tag}->{'@'}->{hidden};
1300
            $hidden //= 0;
1301
            $hidden = ($hidden<=0) ? 0 : 1;
1302
            if ($hidden) {
1303
                $record->delete_fields($fields);
1304
            }
1305
        }
1306
    }
1307
1308
    return $record;
1309
}
1310
1210
=head2 GetMarcFromKohaField
1311
=head2 GetMarcFromKohaField
1211
1312
1212
  ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
1313
  ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
Lines 1427-1433 sub GetCOinSBiblio { Link Here
1427
                $oauthors .= "&amp;rft.au=$au";
1528
                $oauthors .= "&amp;rft.au=$au";
1428
            }
1529
            }
1429
        }
1530
        }
1430
        $title = "&amp;rft." . $titletype . "title=" . $record->subfield( '245', 'a' );
1531
        $title = $record->subfield( '245', 'a' ) || '';
1532
        $title = "&amp;rft." . $titletype . "title=" . $title;
1431
        $subtitle = $record->subfield( '245', 'b' ) || '';
1533
        $subtitle = $record->subfield( '245', 'b' ) || '';
1432
        $title .= $subtitle;
1534
        $title .= $subtitle;
1433
        if ($titletype eq 'a') {
1535
        if ($titletype eq 'a') {
Lines 1873-1879 sub GetMarcSubjects { Link Here
1873
        push @marcsubjects, {
1975
        push @marcsubjects, {
1874
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
1976
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
1875
            authoritylink => $authoritylink,
1977
            authoritylink => $authoritylink,
1876
        };
1978
        } if $authoritylink || $#subfields_loop>=0;
1877
1979
1878
    }
1980
    }
1879
    return \@marcsubjects;
1981
    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 (-1 / +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');
63
- 

Return to bug 11592