- }
- # // form
- foreach my $field ($record->field('7..')) {
- my $lang = substr($field->subfield('8'),3,3);
- $seeheading.= '<span class="langue"> En '.$language{$lang}.' : </span><span class="OT"> '.$field->subfield('a')."</span><br />\n";
- }
- $broaderterms =~s/-- \n$//;
- $narrowerterms =~s/-- \n$//;
- $seealso =~s/-- \n$//;
- $see =~s/-- \n$//;
- $summary = $heading."<br />".($notes?"$notes <br />":"");
- $summary.= '<p><div class="label">TG : '.$broaderterms.'</div></p>' if ($broaderterms);
- $summary.= '<p><div class="label">TS : '.$narrowerterms.'</div></p>' if ($narrowerterms);
- $summary.= '<p><div class="label">TA : '.$seealso.'</div></p>' if ($seealso);
- $summary.= '<p><div class="label">EP : '.$see.'</div></p>' if ($see);
- $summary.= '<p><div class="label">'.$seeheading.'</div></p>' if ($seeheading);
- } else {
- # construct MARC21 summary
- # FIXME - looping over 1XX is questionable
- # since MARC21 authority should have only one 1XX
- foreach my $field ($record->field('1..')) {
- next if "152" eq $field->tag(); # FIXME - 152 is not a good tag to use
- # in MARC21 -- purely local tags really ought to be
- # 9XX
- if ($record->field('100')) {
- $heading.= $field->as_string('abcdefghjklmnopqrstvxyz68');
- } elsif ($record->field('110')) {
- $heading.= $field->as_string('abcdefghklmnoprstvxyz68');
- } elsif ($record->field('111')) {
- $heading.= $field->as_string('acdefghklnpqstvxyz68');
- } elsif ($record->field('130')) {
- $heading.= $field->as_string('adfghklmnoprstvxyz68');
- } elsif ($record->field('148')) {
- $heading.= $field->as_string('abvxyz68');
- } elsif ($record->field('150')) {
- $heading.= $field->as_string('abvxyz68');
- #$heading.= $field->as_formatted();
- my $tag=$field->tag();
- $heading=~s /^$tag//g;
- $heading =~s /\_/\$/g;
- } elsif ($record->field('151')) {
- $heading.= $field->as_string('avxyz68');
- } elsif ($record->field('155')) {
- $heading.= $field->as_string('abvxyz68');
- } elsif ($record->field('180')) {
- $heading.= $field->as_string('vxyz68');
- } elsif ($record->field('181')) {
- $heading.= $field->as_string('vxyz68');
- } elsif ($record->field('182')) {
- $heading.= $field->as_string('vxyz68');
- } elsif ($record->field('185')) {
- $heading.= $field->as_string('vxyz68');
- } else {
- $heading.= $field->as_string();
- }
- } #See From
- foreach my $field ($record->field('4..')) {
- $seeheading.= "<br /> <i>used for/see from:</i> ".$field->as_string();
- } #See Also
- foreach my $field ($record->field('5..')) {
- $altheading.= "<br /> <i>see also:</i> ".$field->as_string();
- }
- $summary .= ": " if $summary;
- $summary.=$heading.$seeheading.$altheading;
- }
- }
- return $summary;
+ foreach my $field ($record->field('4..')) {
+ my $thesaurus = $field->subfield('2') ? "thes. : ".$thesaurus{"$field->subfield('2')"}." : " : '';
+ push @seefrom, {
+ heading => $thesaurus . $field->as_string('abcdefghijlmnopqrstuvwxyz'),
+ hemain => ( $field->subfield('a') // undef ),
+ type => 'seefrom',
+ field => $field->tag(),
+ };
+ }
+
+ # see :
+ @seealso = map {
+ my $type = $unimarc_relation_from_code{$_->subfield('5') || 'a'};
+ my $heading = $_->as_string('abcdefgjxyz');
+ {
+ field => $_->tag,
+ type => $type,
+ heading => $heading,
+ hemain => ( $_->subfield('a') // undef ),
+ search => $heading,
+ authid => ( $_->subfield('9') // undef ),
+ }
+ } $record->field('5..');
+
+ # Other forms
+ @otherscript = map { {
+ lang => length ($_->subfield('8')) == 6 ? substr ($_->subfield('8'), 3, 3) : $_->subfield('8') || '',
+ term => $_->subfield('a') . ($_->subfield('b') ? ', ' . $_->subfield('b') : ''),
+ direction => 'ltr',
+ field => $_->tag,
+ } } $record->field('7..');
+
+ } else {
+# construct MARC21 summary
+# FIXME - looping over 1XX is questionable
+# since MARC21 authority should have only one 1XX
+ my $subfields_to_report;
+ foreach my $field ($record->field('1..')) {
+ my $tag = $field->tag();
+ next if "152" eq $tag;
+# FIXME - 152 is not a good tag to use
+# in MARC21 -- purely local tags really ought to be
+# 9XX
+ if ($tag eq '100') {
+ $subfields_to_report = 'abcdefghjklmnopqrstvxyz';
+ } elsif ($tag eq '110') {
+ $subfields_to_report = 'abcdefghklmnoprstvxyz';
+ } elsif ($tag eq '111') {
+ $subfields_to_report = 'acdefghklnpqstvxyz';
+ } elsif ($tag eq '130') {
+ $subfields_to_report = 'adfghklmnoprstvxyz';
+ } elsif ($tag eq '148') {
+ $subfields_to_report = 'abvxyz';
+ } elsif ($tag eq '150') {
+ $subfields_to_report = 'abvxyz';
+ } elsif ($tag eq '151') {
+ $subfields_to_report = 'avxyz';
+ } elsif ($tag eq '155') {
+ $subfields_to_report = 'abvxyz';
+ } elsif ($tag eq '180') {
+ $subfields_to_report = 'vxyz';
+ } elsif ($tag eq '181') {
+ $subfields_to_report = 'vxyz';
+ } elsif ($tag eq '182') {
+ $subfields_to_report = 'vxyz';
+ } elsif ($tag eq '185') {
+ $subfields_to_report = 'vxyz';
+ }
+ if ($subfields_to_report) {
+ push @authorized, {
+ heading => $field->as_string($subfields_to_report),
+ hemain => ( $field->subfield( substr($subfields_to_report, 0, 1) ) // undef ),
+ field => $tag,
+ };
+ } else {
+ push @authorized, {
+ heading => $field->as_string(),
+ hemain => ( $field->subfield( 'a' ) // undef ),
+ field => $tag,
+ };
+ }
+ }
+ foreach my $field ($record->field('4..')) { #See From
+ my $type = 'seefrom';
+ $type = ($marc21controlrefs{substr $field->subfield('w'), 0, 1} || '') if ($field->subfield('w'));
+ if ($type eq 'notapplicable') {
+ $type = substr $field->subfield('w'), 2, 1;
+ $type = 'earlier' if $type && $type ne 'n';
+ }
+ if ($type eq 'subfi') {
+ push @seefrom, {
+ heading => $field->as_string($marc21subfields),
+ hemain => $field->subfield( substr($marc21subfields, 0, 1) ),
+ type => ($field->subfield('i') || ''),
+ field => $field->tag(),
+ };
+ } else {
+ push @seefrom, {
+ heading => $field->as_string($marc21subfields),
+ hemain => $field->subfield( substr($marc21subfields, 0, 1) ),
+ type => $type,
+ field => $field->tag(),
+ };
+ }
+ }
+ foreach my $field ($record->field('5..')) { #See Also
+ my $type = 'seealso';
+ $type = ($marc21controlrefs{substr $field->subfield('w'), 0, 1} || '') if ($field->subfield('w'));
+ if ($type eq 'notapplicable') {
+ $type = substr $field->subfield('w'), 2, 1;
+ $type = 'earlier' if $type && $type ne 'n';
+ }
+ if ($type eq 'subfi') {
+ push @seealso, {
+ heading => $field->as_string($marc21subfields),
+ hemain => $field->subfield( substr($marc21subfields, 0, 1) ),
+ type => $field->subfield('i'),
+ field => $field->tag(),
+ search => $field->as_string($marc21subfields) || '',
+ authid => $field->subfield('9') || ''
+ };
+ } else {
+ push @seealso, {
+ heading => $field->as_string($marc21subfields),
+ hemain => $field->subfield( substr($marc21subfields, 0, 1) ),
+ type => $type,
+ field => $field->tag(),
+ search => $field->as_string($marc21subfields) || '',
+ authid => $field->subfield('9') || ''
+ };
+ }
+ }
+ foreach my $field ($record->field('6..')) {
+ push @notes, { note => $field->as_string(), field => $field->tag() };
+ }
+ foreach my $field ($record->field('880')) {
+ my $linkage = $field->subfield('6');
+ my $category = substr $linkage, 0, 1;
+ if ($category eq '1') {
+ $category = 'preferred';
+ } elsif ($category eq '4') {
+ $category = 'seefrom';
+ } elsif ($category eq '5') {
+ $category = 'seealso';
+ }
+ my $type;
+ if ($field->subfield('w')) {
+ $type = $marc21controlrefs{substr $field->subfield('w'), '0'};
+ } else {
+ $type = $category;
+ }
+ my $direction = $linkage =~ m#/r$# ? 'rtl' : 'ltr';
+ push @otherscript, { term => $field->as_string($subfields_to_report), category => $category, type => $type, direction => $direction, linkage => $linkage };
+ }
+ }
+ $summary{mainentry} = $authorized[0]->{heading};
+ $summary{mainmainentry} = $authorized[0]->{hemain};
+ $summary{authorized} = \@authorized;
+ $summary{notes} = \@notes;
+ $summary{seefrom} = \@seefrom;
+ $summary{seealso} = \@seealso;
+ $summary{otherscript} = \@otherscript;
+ return \%summary;
+}
+
+=head2 GetAuthorizedHeading
+
+ $heading = &GetAuthorizedHeading({ record => $record, authid => $authid })
+
+Takes a MARC::Record object describing an authority record or an authid, and
+returns a string representation of the first authorized heading. This routine
+should be considered a temporary shim to ease the future migration of authority
+data from C4::AuthoritiesMarc to the object-oriented Koha::*::Authority.
+
+=cut
+
+sub GetAuthorizedHeading {
+ my $args = shift;
+ my $record;
+ unless ($record = $args->{record}) {
+ return unless $args->{authid};
+ $record = GetAuthority($args->{authid});
+ }
+ return unless (ref $record eq 'MARC::Record');
+ if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
+# construct UNIMARC summary, that is quite different from MARC21 one
+# accepted form
+ foreach my $field ($record->field('2..')) {
+ return $field->as_string('abcdefghijlmnopqrstuvwxyz');
+ }
+ } else {
+ foreach my $field ($record->field('1..')) {
+ my $tag = $field->tag();
+ next if "152" eq $tag;
+# FIXME - 152 is not a good tag to use
+# in MARC21 -- purely local tags really ought to be
+# 9XX
+ if ($tag eq '100') {
+ return $field->as_string('abcdefghjklmnopqrstvxyz68');
+ } elsif ($tag eq '110') {
+ return $field->as_string('abcdefghklmnoprstvxyz68');
+ } elsif ($tag eq '111') {
+ return $field->as_string('acdefghklnpqstvxyz68');
+ } elsif ($tag eq '130') {
+ return $field->as_string('adfghklmnoprstvxyz68');
+ } elsif ($tag eq '148') {
+ return $field->as_string('abvxyz68');
+ } elsif ($tag eq '150') {
+ return $field->as_string('abvxyz68');
+ } elsif ($tag eq '151') {
+ return $field->as_string('avxyz68');
+ } elsif ($tag eq '155') {
+ return $field->as_string('abvxyz68');
+ } elsif ($tag eq '180') {
+ return $field->as_string('vxyz68');
+ } elsif ($tag eq '181') {
+ return $field->as_string('vxyz68');
+ } elsif ($tag eq '182') {
+ return $field->as_string('vxyz68');
+ } elsif ($tag eq '185') {
+ return $field->as_string('vxyz68');
+ } else {
+ return $field->as_string();
+ }
+ }
+ }
+ return;