Bug 29697: Replace GetMarcBiblio occurrences with $biblio->metadata->record
[srvgit] / basket / basket.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
19 use Modern::Perl;
20 use CGI qw ( -utf8 );
21 use C4::Koha;
22 use C4::Biblio qw(
23     GetMarcSeries
24     GetMarcSubjects
25     GetMarcUrls
26 );
27 use C4::Items qw( GetItemsInfo );
28 use C4::Auth qw( get_template_and_user );
29 use C4::Output qw( output_html_with_http_headers );
30
31 use Koha::AuthorisedValues;
32 use Koha::Biblios;
33 use Koha::CsvProfiles;
34
35 my $query = CGI->new;
36
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
38     {
39         template_name   => "basket/basket.tt",
40         query           => $query,
41         type            => "intranet",
42         flagsrequired   => { catalogue => 1 },
43     }
44 );
45
46 my $bib_list     = $query->param('bib_list');
47 my $verbose      = $query->param('verbose');
48
49 if ($verbose)      { $template->param( verbose      => 1 ); }
50
51 my @bibs = split( /\//, $bib_list );
52 my @results;
53
54 my $num = 1;
55 my $marcflavour = C4::Context->preference('marcflavour');
56 if (C4::Context->preference('TagsEnabled')) {
57         $template->param(TagsEnabled => 1);
58         foreach (qw(TagsShowOnList TagsInputOnList)) {
59                 C4::Context->preference($_) and $template->param($_ => 1);
60         }
61 }
62
63
64 foreach my $biblionumber ( @bibs ) {
65     $template->param( biblionumber => $biblionumber );
66
67     my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
68     my $dat              = $biblio->unblessed;
69     my $record           = $biblio->metadata->record;
70     my $marcnotesarray   = $biblio->get_marc_notes;
71     my $marcauthorsarray = $biblio->get_marc_authors;
72     my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
73     my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
74     my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
75     my @items            = GetItemsInfo( $biblionumber );
76
77     my $hasauthors = 0;
78     if($dat->{'author'} || @$marcauthorsarray) {
79       $hasauthors = 1;
80     }
81         
82     my $shelflocations =
83       { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
84
85         for my $itm (@items) {
86             if ($itm->{'location'}){
87             $itm->{'location_description'} = $shelflocations->{$itm->{'location'} };
88                 }
89         }
90         # COinS format FIXME: for books Only
91         my $fmt = substr $record->leader(), 6,2;
92         my $fmts;
93         $fmts->{'am'} = 'book';
94         $dat->{ocoins_format} = $fmts->{$fmt};
95
96     if ( $num % 2 == 1 ) {
97         $dat->{'even'} = 1;
98     }
99
100     $num++;
101     $dat->{biblionumber} = $biblionumber;
102     $dat->{ITEM_RESULTS}   = \@items;
103     $dat->{MARCNOTES}      = $marcnotesarray;
104     $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
105     $dat->{MARCAUTHORS}    = $marcauthorsarray;
106     $dat->{MARCSERIES}  = $marcseriesarray;
107     $dat->{MARCURLS}    = $marcurlsarray;
108     $dat->{HASAUTHORS}  = $hasauthors;
109
110     push( @results, $dat );
111 }
112
113 my $resultsarray = \@results;
114
115 # my $itemsarray=\@items;
116
117 $template->param(
118     BIBLIO_RESULTS => $resultsarray,
119     csv_profiles => Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }),
120     bib_list => $bib_list,
121 );
122
123 output_html_with_http_headers $query, $cookie, $template->output;