+=head3 cover_images
+
+Return the cover images associated with this biblio.
+
+=cut
+
+sub cover_images {
+ my ( $self ) = @_;
+
+ my $cover_images_rs = $self->_result->cover_images;
+ return unless $cover_images_rs;
+ return Koha::CoverImages->_new_from_dbic($cover_images_rs);
+}
+
+=head3 get_marc_notes
+
+ $marcnotesarray = $biblio->get_marc_notes({ opac => 1 });
+
+Get all notes from the MARC record and returns them in an array.
+The notes are stored in different fields depending on MARC flavour.
+MARC21 5XX $u subfields receive special attention as they are URIs.
+
+=cut
+
+sub get_marc_notes {
+ my ( $self, $params ) = @_;
+
+ my $marcflavour = C4::Context->preference('marcflavour');
+ my $opac = $params->{opac} // '0';
+ my $interface = $params->{opac} ? 'opac' : 'intranet';
+
+ my $record = $params->{record} // $self->metadata->record;
+ my $record_processor = Koha::RecordProcessor->new(
+ {
+ filters => [ 'ViewPolicy', 'ExpandCodedFields' ],
+ options => {
+ interface => $interface,
+ frameworkcode => $self->frameworkcode
+ }
+ }
+ );
+ $record_processor->process($record);
+
+ my $scope = $marcflavour eq "UNIMARC"? '3..': '5..';
+ #MARC21 specs indicate some notes should be private if first indicator 0
+ my %maybe_private = (
+ 541 => 1,
+ 542 => 1,
+ 561 => 1,
+ 583 => 1,
+ 590 => 1
+ );
+
+ my %hiddenlist = map { $_ => 1 }
+ split( /,/, C4::Context->preference('NotesToHide'));
+
+ my @marcnotes;
+ foreach my $field ( $record->field($scope) ) {
+ my $tag = $field->tag();
+ next if $hiddenlist{ $tag };
+ next if $opac && $maybe_private{$tag} && !$field->indicator(1);
+ if( $marcflavour ne 'UNIMARC' && $field->subfield('u') ) {
+ # Field 5XX$u always contains URI
+ # Examples: 505u, 506u, 510u, 514u, 520u, 530u, 538u, 540u, 542u, 552u, 555u, 561u, 563u, 583u
+ # We first push the other subfields, then all $u's separately
+ # Leave further actions to the template (see e.g. opac-detail)
+ my $othersub =
+ join '', ( 'a' .. 't', 'v' .. 'z', '0' .. '9' ); # excl 'u'
+ push @marcnotes, { marcnote => $field->as_string($othersub) };
+ foreach my $sub ( $field->subfield('u') ) {
+ $sub =~ s/^\s+|\s+$//g; # trim
+ push @marcnotes, { marcnote => $sub };
+ }
+ } else {
+ push @marcnotes, { marcnote => $field->as_string() };
+ }
+ }
+ return \@marcnotes;
+}
+
+=head3 _get_marc_authors
+
+Private method to return the list of authors contained in the MARC record.
+See get get_marc_contributors and get_marc_authors for the public methods.
+
+=cut
+
+sub _get_marc_authors {
+ my ( $self, $params ) = @_;
+
+ my $fields_filter = $params->{fields_filter};
+ my $mintag = $params->{mintag};
+ my $maxtag = $params->{maxtag};
+
+ my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
+ my $marcflavour = C4::Context->preference('marcflavour');
+
+ # tagslib useful only for UNIMARC author responsibilities
+ my $tagslib = $marcflavour eq "UNIMARC"
+ ? C4::Biblio::GetMarcStructure( 1, $self->frameworkcode, { unsafe => 1 } )
+ : undef;
+
+ my @marcauthors;
+ foreach my $field ( $self->metadata->record->field($fields_filter) ) {
+
+ next
+ if $mintag && $field->tag() < $mintag
+ || $maxtag && $field->tag() > $maxtag;
+
+ my @subfields_loop;
+ my @link_loop;
+ my @subfields = $field->subfields();
+ my $count_auth = 0;
+
+ # if there is an authority link, build the link with Koha-Auth-Number: subfield9
+ my $subfield9 = $field->subfield('9');
+ if ($subfield9) {
+ my $linkvalue = $subfield9;
+ $linkvalue =~ s/(\(|\))//g;
+ @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
+ }
+
+ # other subfields
+ my $unimarc3;
+ for my $authors_subfield (@subfields) {
+ next if ( $authors_subfield->[0] eq '9' );
+
+ # unimarc3 contains the $3 of the author for UNIMARC.
+ # For french academic libraries, it's the "ppn", and it's required for idref webservice
+ $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
+
+ # don't load unimarc subfields 3, 5
+ next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
+
+ my $code = $authors_subfield->[0];
+ my $value = $authors_subfield->[1];
+ my $linkvalue = $value;
+ $linkvalue =~ s/(\(|\))//g;
+ # UNIMARC author responsibility
+ if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
+ $value = C4::Biblio::GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
+ $linkvalue = "($value)";
+ }
+ # if no authority link, build a search query
+ unless ($subfield9) {
+ push @link_loop, {
+ limit => 'au',
+ 'link' => $linkvalue,
+ operator => (scalar @link_loop) ? ' AND ' : undef
+ };
+ }
+ my @this_link_loop = @link_loop;
+ # do not display $0
+ unless ( $code eq '0') {
+ push @subfields_loop, {
+ tag => $field->tag(),
+ code => $code,
+ value => $value,
+ link_loop => \@this_link_loop,
+ separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
+ };
+ }
+ }
+ push @marcauthors, {
+ MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
+ authoritylink => $subfield9,
+ unimarc3 => $unimarc3
+ };
+ }
+ return \@marcauthors;
+}
+
+=head3 get_marc_contributors
+
+ my $contributors = $biblio->get_marc_contributors;
+
+Get all contributors (but first author) from the MARC record and returns them in an array.
+They are stored in different fields depending on MARC flavour (700..720 for MARC21)
+
+=cut
+
+sub get_marc_contributors {
+ my ( $self, $params ) = @_;
+
+ my ( $mintag, $maxtag, $fields_filter );
+ my $marcflavour = C4::Context->preference('marcflavour');
+
+ if ( $marcflavour eq "UNIMARC" ) {
+ $mintag = "700";
+ $maxtag = "712";
+ $fields_filter = '7..';
+ } else { # marc21/normarc
+ $mintag = "700";
+ $maxtag = "720";
+ $fields_filter = '7..';
+ }
+
+ return $self->_get_marc_authors(
+ {
+ fields_filter => $fields_filter,
+ mintag => $mintag,
+ maxtag => $maxtag
+ }
+ );
+}
+
+=head3 get_marc_authors
+
+ my $authors = $biblio->get_marc_authors;
+
+Get all authors from the MARC record and returns them in an array.
+They are stored in different fields depending on MARC flavour
+(main author from 100 then secondary authors from 700..720).
+
+=cut
+
+sub get_marc_authors {
+ my ( $self, $params ) = @_;
+
+ my ( $mintag, $maxtag, $fields_filter );
+ my $marcflavour = C4::Context->preference('marcflavour');
+
+ if ( $marcflavour eq "UNIMARC" ) {
+ $fields_filter = '200';
+ } else { # marc21/normarc
+ $fields_filter = '100';
+ }
+
+ my @first_authors = @{$self->_get_marc_authors(
+ {
+ fields_filter => $fields_filter,
+ mintag => $mintag,
+ maxtag => $maxtag
+ }
+ )};
+
+ my @other_authors = @{$self->get_marc_contributors};
+
+ return [@first_authors, @other_authors];
+}
+
+