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

(-)a/C4/VirtualShelves.pm (-60 lines)
Lines 40-46 BEGIN { Link Here
40
    require Exporter;
40
    require Exporter;
41
    @ISA    = qw(Exporter);
41
    @ISA    = qw(Exporter);
42
    @EXPORT = qw(
42
    @EXPORT = qw(
43
            &GetShelfContents
44
    );
43
    );
45
        @EXPORT_OK = qw(
44
        @EXPORT_OK = qw(
46
            &ShelvesMax
45
            &ShelvesMax
Lines 103-167 sub GetSomeShelfNames { Link Here
103
    return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar);
102
    return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar);
104
}
103
}
105
104
106
=head2 GetShelfContents
107
108
  $biblist = &GetShelfContents($shelfnumber);
109
110
Looks up information about the contents of virtual virtualshelves number
111
C<$shelfnumber>.  Sorted by a field in the biblio table.  copyrightdate 
112
gives a desc sort.
113
114
Returns a reference-to-array, whose elements are references-to-hash,
115
as returned by C<C4::Biblio::GetBiblioFromItemNumber>.
116
117
Note: the notforloan status comes from the itemtype, and where it equals 0
118
it does not ensure that related items.notforloan status is likewise 0. The
119
caller has to check any items on their own, possibly with CanBookBeIssued
120
from C4::Circulation.
121
122
=cut
123
124
sub GetShelfContents {
125
    my ($shelfnumber, $row_count, $offset, $sortfield, $sort_direction ) = @_;
126
    my $dbh=C4::Context->dbh();
127
    my $sth1 = $dbh->prepare("SELECT count(*) FROM virtualshelfcontents WHERE shelfnumber = ?");
128
    $sth1->execute($shelfnumber);
129
    my $total = $sth1->fetchrow;
130
    if(!$sortfield) {
131
        my $sth2 = $dbh->prepare('SELECT sortfield FROM virtualshelves WHERE shelfnumber=?');
132
        $sth2->execute($shelfnumber);
133
        ($sortfield) = $sth2->fetchrow_array;
134
    }
135
    my $query =
136
       " SELECT DISTINCT vc.biblionumber, vc.shelfnumber, vc.dateadded, itemtypes.*,
137
            biblio.*, biblioitems.itemtype, biblioitems.publicationyear as year, biblioitems.publishercode, biblioitems.place, biblioitems.size, biblioitems.pages
138
         FROM   virtualshelfcontents vc
139
         JOIN biblio      ON      vc.biblionumber =      biblio.biblionumber
140
         LEFT JOIN biblioitems ON  biblio.biblionumber = biblioitems.biblionumber
141
         LEFT JOIN items ON items.biblionumber=vc.biblionumber
142
         LEFT JOIN itemtypes   ON biblioitems.itemtype = itemtypes.itemtype
143
         WHERE  vc.shelfnumber=? ";
144
    my @params = ($shelfnumber);
145
    if($sortfield) {
146
        $query .= " ORDER BY " . $dbh->quote_identifier( $sortfield );
147
        $query .= " DESC " if ( $sort_direction eq 'desc' );
148
    }
149
    if($row_count){
150
       $query .= " LIMIT ?, ? ";
151
       push (@params, ($offset ? $offset : 0));
152
       push (@params, $row_count);
153
    }
154
    my $sth3 = $dbh->prepare($query);
155
    $sth3->execute(@params);
156
    return ($sth3->fetchall_arrayref({}), $total);
157
    # Like the perldoc says,
158
    # returns reference-to-array, where each element is reference-to-hash of the row:
159
    #   like [ $sth->fetchrow_hashref(), $sth->fetchrow_hashref() ... ]
160
    # Suitable for use in TMPL_LOOP.
161
    # See http://search.cpan.org/~timb/DBI-1.601/DBI.pm#fetchall_arrayref
162
    # or newer, for your version of DBI.
163
}
164
165
=head2 ShelvesMax
105
=head2 ShelvesMax
166
106
167
    $howmany= ShelvesMax($context);
107
    $howmany= ShelvesMax($context);
(-)a/opac/opac-addbybiblionumber.pl (-26 / +19 lines)
Lines 41-46 our $authorized = 1; Link Here
41
our $errcode		= 0;
41
our $errcode		= 0;
42
our @biblios;
42
our @biblios;
43
43
44
45
if (scalar(@biblionumber) == 1) {
46
    @biblionumber = (split /\//,$biblionumber[0]);
47
}
48
44
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
49
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45
    {
50
    {
46
        template_name   => "opac-addbybiblionumber.tt",
51
        template_name   => "opac-addbybiblionumber.tt",
Lines 72-91 else { Link Here
72
}
77
}
73
#end
78
#end
74
79
75
sub AddBibliosToShelf {
76
    #splits incoming biblionumber(s) to array and adds each to shelf.
77
    my ($shelfnumber,@biblionumber)=@_;
78
79
    #multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
80
    if (scalar(@biblionumber) == 1) {
81
        @biblionumber = (split /\//,$biblionumber[0]);
82
    }
83
    for my $bib (@biblionumber) {
84
        my $shelf = Koha::Virtualshelves->find( $shelfnumber );
85
        $shelf->add_biblio( $bib, $loggedinuser );
86
    }
87
}
88
89
sub HandleNewVirtualShelf {
80
sub HandleNewVirtualShelf {
90
    if ( $loggedinuser > 0 and
81
    if ( $loggedinuser > 0 and
91
        (
82
        (
Lines 100-113 sub HandleNewVirtualShelf { Link Here
100
                    category => $category,
91
                    category => $category,
101
                    owner => $loggedinuser,
92
                    owner => $loggedinuser,
102
                }
93
                }
103
            );
94
            )->store;
104
        };
95
        };
105
        if ( $@ or not $shelf ) {
96
        if ( $@ or not $shelf ) {
106
            $authorized = 0;
97
            $authorized = 0;
107
            $errcode = 1;
98
            $errcode = 1;
108
            return;
99
            return;
109
        }
100
        }
110
        AddBibliosToShelf($shelfnumber, @biblionumber);
101
102
        for my $bib (@biblionumber) {
103
            $shelf->add_biblio( $bib, $loggedinuser );
104
        }
105
111
        #Reload the page where you came from
106
        #Reload the page where you came from
112
        print $query->header;
107
        print $query->header;
113
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
108
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
Lines 118-124 sub HandleShelfNumber { Link Here
118
    my $shelfnumber = $query->param('shelfnumber');
113
    my $shelfnumber = $query->param('shelfnumber');
119
    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
114
    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
120
    if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
115
    if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
121
        AddBibliosToShelf($shelfnumber,@biblionumber);
116
        for my $bib (@biblionumber) {
117
            $shelf->add_biblio( $bib, $loggedinuser );
118
        }
122
        #Close this page and return
119
        #Close this page and return
123
        print $query->header;
120
        print $query->header;
124
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
121
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
Lines 181-197 sub HandleSelect { Link Here
181
}
178
}
182
179
183
sub LoadBib {
180
sub LoadBib {
184
    #see comment in AddBibliosToShelf
185
    if (scalar(@biblionumber) == 1) {
186
        @biblionumber = (split /\//,$biblionumber[0]);
187
    }
188
    for my $bib (@biblionumber) {
181
    for my $bib (@biblionumber) {
189
        my $data = GetBiblioData( $bib );
182
        my $data = GetBiblioData( $bib );
190
    push(@biblios,
183
        push(@biblios,
191
        { biblionumber => $bib,
184
            { biblionumber => $bib,
192
          title        => $data->{'title'},
185
              title        => $data->{'title'},
193
          author       => $data->{'author'},
186
              author       => $data->{'author'},
194
    } );
187
        } );
195
    }
188
    }
196
    $template->param(
189
    $template->param(
197
        multiple => (scalar(@biblios) > 1),
190
        multiple => (scalar(@biblios) > 1),
(-)a/opac/opac-downloadshelf.pl (-6 / +6 lines)
Lines 56-62 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
56
56
57
    if ($shelfnumber && $format) {
57
    if ($shelfnumber && $format) {
58
58
59
        my ($items, $totitems)  = GetShelfContents($shelfnumber);
59
60
        my $contents = $shelf->get_contents;
60
        my $marcflavour         = C4::Context->preference('marcflavour');
61
        my $marcflavour         = C4::Context->preference('marcflavour');
61
        my $output;
62
        my $output;
62
        my $extension;
63
        my $extension;
Lines 65-79 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
65
       # CSV
66
       # CSV
66
        if ($format =~ /^\d+$/) {
67
        if ($format =~ /^\d+$/) {
67
            my @biblios;
68
            my @biblios;
68
            foreach (@$items) {
69
            while ( my $content = $contents->next ) {
69
                push @biblios, $_->{biblionumber};
70
                push @biblios, $content->biblionumber->biblionumber;
70
            }
71
            }
71
            $output = marc2csv(\@biblios, $format);
72
            $output = marc2csv(\@biblios, $format);
72
                
73
        # Other formats
73
        # Other formats
74
        } else {
74
        } else {
75
            foreach my $biblio (@$items) {
75
            while ( my $content = $contents->next ) {
76
                my $biblionumber = $biblio->{biblionumber};
76
                my $biblionumber = $content->biblionumber->biblionumber;
77
77
78
                my $record = GetMarcBiblio($biblionumber, 1);
78
                my $record = GetMarcBiblio($biblionumber, 1);
79
                next unless $record;
79
                next unless $record;
(-)a/opac/opac-sendshelf.pl (-4 / +3 lines)
Lines 75-88 if ( $email ) { Link Here
75
    );
75
    );
76
76
77
    my $shelf = Koha::Virtualshelves->find( $shelfid );
77
    my $shelf = Koha::Virtualshelves->find( $shelfid );
78
    my ($items, $totitems)  = GetShelfContents($shelfid);
78
    my $contents = $shelf->get_contents;
79
    my $marcflavour         = C4::Context->preference('marcflavour');
79
    my $marcflavour         = C4::Context->preference('marcflavour');
80
    my $iso2709;
80
    my $iso2709;
81
    my @results;
81
    my @results;
82
82
83
    # retrieve biblios from shelf
83
    while ( my $content = $contents->next ) {
84
    foreach my $biblio (@$items) {
84
        my $biblionumber = $content->biblionumber->biblionumber;
85
        my $biblionumber = $biblio->{biblionumber};
86
        my $fw               = GetFrameworkCode($biblionumber);
85
        my $fw               = GetFrameworkCode($biblionumber);
87
        my $dat              = GetBiblioData($biblionumber);
86
        my $dat              = GetBiblioData($biblionumber);
88
        my $record           = GetMarcBiblio($biblionumber, 1);
87
        my $record           = GetMarcBiblio($biblionumber, 1);
(-)a/opac/opac-shelves.pl (-16 / +22 lines)
Lines 213-225 if ( $op eq 'view' ) { Link Here
213
            $category = $shelf->category;
213
            $category = $shelf->category;
214
            my $sortfield = $query->param('sortfield') || $shelf->sortfield;    # Passed in sorting overrides default sorting
214
            my $sortfield = $query->param('sortfield') || $shelf->sortfield;    # Passed in sorting overrides default sorting
215
            my $direction = $query->param('direction') || 'asc';
215
            my $direction = $query->param('direction') || 'asc';
216
            my ( $shelflimit, $shelfoffset, $itemoff );
216
            my ( $page, $rows );
217
            unless ( $query->param('print') or $query->param('rss') ) {
217
            unless ( $query->param('print') or $query->param('rss') ) {
218
                $shelflimit = C4::Context->preference('OPACnumSearchResults') || 20;
218
                $rows = C4::Context->preference('OPACnumSearchResults') || 20;
219
                $itemoff = ( $query->param('itemoff') ? $query->param('itemoff') : 1 );
219
                $page = ( $query->param('page') ? $query->param('page') : 1 );
220
                $shelfoffset = ( $itemoff - 1 ) * $shelflimit;    # Sets the offset to begin retrieving items at
221
            }
220
            }
222
            my ( $items, $totitems ) = GetShelfContents( $shelfnumber, $shelflimit, $shelfoffset, $sortfield, $direction );
221
            my $contents = $shelf->get_contents->search({}, { join => [ 'biblionumber' ], page => $page, rows => $rows, order_by => "$sortfield $direction", });
223
222
224
            # get biblionumbers stored in the cart
223
            # get biblionumbers stored in the cart
225
            my @cart_list;
224
            my @cart_list;
Lines 229-236 if ( $op eq 'view' ) { Link Here
229
228
230
            my $borrower = GetMember( borrowernumber => $loggedinuser );
229
            my $borrower = GetMember( borrowernumber => $loggedinuser );
231
230
232
            for my $this_item (@$items) {
231
            my @items;
233
                my $biblionumber = $this_item->{biblionumber};
232
            while ( my $content = $contents->next ) {
233
                my $this_item;
234
                my $biblionumber = $content->biblionumber->biblionumber;
234
                my $record       = GetMarcBiblio($biblionumber);
235
                my $record       = GetMarcBiblio($biblionumber);
235
236
236
                if ( C4::Context->preference("OPACXSLTResultsDisplay") ) {
237
                if ( C4::Context->preference("OPACXSLTResultsDisplay") ) {
Lines 238-246 if ( $op eq 'view' ) { Link Here
238
                }
239
                }
239
240
240
                my $marcflavour = C4::Context->preference("marcflavour");
241
                my $marcflavour = C4::Context->preference("marcflavour");
241
                $this_item->{'imageurl'}        = getitemtypeinfo( $this_item->{'itemtype'}, 'intranet' )->{'imageurl'};
242
                my $itemtypeinfo = getitemtypeinfo( $content->biblionumber->biblioitems->first->itemtype, 'intranet' );
243
                $this_item->{imageurl}          = $itemtypeinfo->{imageurl};
244
                $this_item->{description}       = $itemtypeinfo->{description};
245
                $this_item->{notforloan}        = $itemtypeinfo->{notforloan};
242
                $this_item->{'coins'}           = GetCOinSBiblio($record);
246
                $this_item->{'coins'}           = GetCOinSBiblio($record);
243
                $this_item->{'subtitle'}        = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $this_item->{'biblionumber'} ) );
247
                $this_item->{'subtitle'}        = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $biblionumber ) );
244
                $this_item->{'normalized_upc'}  = GetNormalizedUPC( $record, $marcflavour );
248
                $this_item->{'normalized_upc'}  = GetNormalizedUPC( $record, $marcflavour );
245
                $this_item->{'normalized_ean'}  = GetNormalizedEAN( $record, $marcflavour );
249
                $this_item->{'normalized_ean'}  = GetNormalizedEAN( $record, $marcflavour );
246
                $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour );
250
                $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour );
Lines 253-264 if ( $op eq 'view' ) { Link Here
253
                }
257
                }
254
258
255
                # Getting items infos for location display
259
                # Getting items infos for location display
256
                my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'} );
260
                my @items_infos = &GetItemsLocationInfo( $biblionumber );
257
                $this_item->{'ITEM_RESULTS'} = \@items_infos;
261
                $this_item->{'ITEM_RESULTS'} = \@items_infos;
258
262
259
                if (C4::Context->preference('TagsEnabled') and C4::Context->preference('TagsShowOnList')) {
263
                if (C4::Context->preference('TagsEnabled') and C4::Context->preference('TagsShowOnList')) {
260
                    $this_item->{TagLoop} = get_tags({
264
                    $this_item->{TagLoop} = get_tags({
261
                        biblionumber=>$this_item->{'biblionumber'}, approved=>1, 'sort'=>'-weight',
265
                        biblionumber => $biblionumber, approved=>1, 'sort'=>'-weight',
262
                        limit => C4::Context->preference('TagsShowOnList'),
266
                        limit => C4::Context->preference('TagsShowOnList'),
263
                    });
267
                    });
264
                }
268
                }
Lines 273-280 if ( $op eq 'view' ) { Link Here
273
                if ( $query->param('rss') ) {
277
                if ( $query->param('rss') ) {
274
                    $this_item->{title} = $content->biblionumber->title;
278
                    $this_item->{title} = $content->biblionumber->title;
275
                    $this_item->{author} = $content->biblionumber->author;
279
                    $this_item->{author} = $content->biblionumber->author;
276
                    $this_item->{biblionumber} = $biblionumber;
277
                }
280
                }
281
282
                $this_item->{biblionumber} = $biblionumber;
278
                push @items, $this_item;
283
                push @items, $this_item;
279
            }
284
            }
280
285
Lines 290-304 if ( $op eq 'view' ) { Link Here
290
                can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser),
295
                can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser),
291
                can_add_biblios    => $shelf->can_biblios_be_added($loggedinuser),
296
                can_add_biblios    => $shelf->can_biblios_be_added($loggedinuser),
292
                sortfield          => $sortfield,
297
                sortfield          => $sortfield,
293
                itemsloop          => $items,
298
                itemsloop          => \@items,
294
                sortfield          => $sortfield,
299
                sortfield          => $sortfield,
295
                direction          => $direction,
300
                direction          => $direction,
296
            );
301
            );
297
            if ($shelflimit) {
302
            if ( $page ) {
303
                my $pager = $contents->pager;
298
                $template->param(
304
                $template->param(
299
                    pagination_bar => pagination_bar(
305
                    pagination_bar => pagination_bar(
300
                        q||, ( int( $totitems / $shelflimit ) ) + ( ( $totitems % $shelflimit ) > 0 ? 1 : 0 ),
306
                        q||, $pager->last_page - $pager->first_page + 1,
301
                        $itemoff, "itemoff", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, }
307
                        $page, "page", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, }
302
                    ),
308
                    ),
303
                );
309
                );
304
            }
310
            }
(-)a/virtualshelves/addbybiblionumber.pl (-14 / +11 lines)
Lines 124-136 sub HandleBiblioPars { Link Here
124
    return @bib;
124
    return @bib;
125
}
125
}
126
126
127
sub AddBibliosToShelf {
128
    my ($shelfnumber, @biblionumber)=@_;
129
    for my $bib (@biblionumber){
130
        Koha::Virtualshelves->find( $shelfnumber )->add_biblio( $bib, $loggedinuser );
131
    }
132
}
133
134
sub HandleNewVirtualShelf {
127
sub HandleNewVirtualShelf {
135
    my $shelf = eval {
128
    my $shelf = eval {
136
        Koha::Virtualshelf->new(
129
        Koha::Virtualshelf->new(
Lines 141-154 sub HandleNewVirtualShelf { Link Here
141
                owner => $loggedinuser,
134
                owner => $loggedinuser,
142
            }
135
            }
143
        );
136
        );
144
    };
137
    }->store;
145
    if ( $@ or not $shelf ) {
138
    if ( $@ or not $shelf ) {
146
        $authorized = 0;
139
        $authorized = 0;
147
        $errcode    = 1;
140
        $errcode    = 1;
148
        return;
141
        return;
149
    }
142
    }
150
143
151
    AddBibliosToShelf($shelfnumber, @biblionumber);
144
    for my $bib (@biblionumber){
145
        $shelf->add_biblio( $bib, $loggedinuser );
146
    }
152
    #Reload the page where you came from
147
    #Reload the page where you came from
153
    print $query->header;
148
    print $query->header;
154
    print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
149
    print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
Lines 157-169 sub HandleNewVirtualShelf { Link Here
157
sub HandleShelfNumber {
152
sub HandleShelfNumber {
158
    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
153
    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
159
    if($authorized = $shelf->can_biblios_be_added( $loggedinuser ) ) {
154
    if($authorized = $shelf->can_biblios_be_added( $loggedinuser ) ) {
160
    AddBibliosToShelf($shelfnumber, @biblionumber);
155
        for my $bib (@biblionumber){
161
    #Close this page and return
156
            $shelf->add_biblio( $bib, $loggedinuser );
162
    print $query->header;
157
        }
163
    print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
158
        #Close this page and return
159
        print $query->header;
160
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
164
    }
161
    }
165
    else {
162
    else {
166
    $errcode=2; #no perm
163
        $errcode=2; #no perm
167
    }
164
    }
168
}
165
}
169
166
(-)a/virtualshelves/downloadshelf.pl (-5 / +5 lines)
Lines 54-60 my @messages; Link Here
54
54
55
if ($shelfid && $format) {
55
if ($shelfid && $format) {
56
56
57
    my ($items, $totitems)  = GetShelfContents($shelfid);
58
    my $marcflavour         = C4::Context->preference('marcflavour');
57
    my $marcflavour         = C4::Context->preference('marcflavour');
59
    my $output='';
58
    my $output='';
60
59
Lines 62-78 if ($shelfid && $format) { Link Here
62
    if ( $shelf ) {
61
    if ( $shelf ) {
63
        if ( $shelf->can_be_viewed( $loggedinuser ) ) {
62
        if ( $shelf->can_be_viewed( $loggedinuser ) ) {
64
63
64
            my $contents = $shelf->get_contents;
65
            # CSV
65
            # CSV
66
            if ($format =~ /^\d+$/) {
66
            if ($format =~ /^\d+$/) {
67
                my @biblios;
67
                my @biblios;
68
                foreach (@$items) {
68
                while ( my $content = $contents->next ) {
69
                    push @biblios, $_->{biblionumber};
69
                    push @biblios, $content->biblionumber->biblionumber;
70
                }
70
                }
71
                $output = marc2csv(\@biblios, $format);
71
                $output = marc2csv(\@biblios, $format);
72
            }
72
            }
73
            else { #Other formats
73
            else { #Other formats
74
                foreach my $biblio (@$items) {
74
                while ( my $content = $contents->next ) {
75
                    my $biblionumber = $biblio->{biblionumber};
75
                    my $biblionumber = $content->biblionumber->biblionumber;
76
                    my $record = GetMarcBiblio($biblionumber, 1);
76
                    my $record = GetMarcBiblio($biblionumber, 1);
77
                    if ($format eq 'iso2709') {
77
                    if ($format eq 'iso2709') {
78
                        $output .= $record->as_usmarc();
78
                        $output .= $record->as_usmarc();
(-)a/virtualshelves/sendshelf.pl (-4 / +3 lines)
Lines 72-85 if ($email) { Link Here
72
    );
72
    );
73
73
74
    my $shelf = Koha::Virtualshelves->find( $shelfid );
74
    my $shelf = Koha::Virtualshelves->find( $shelfid );
75
    my ( $items, $totitems ) = GetShelfContents($shelf->shelfnumber);
75
    my $contents = $shelf->get_contents;
76
    my $marcflavour = C4::Context->preference('marcflavour');
76
    my $marcflavour = C4::Context->preference('marcflavour');
77
    my $iso2709;
77
    my $iso2709;
78
    my @results;
78
    my @results;
79
79
80
    # retrieve biblios from shelf
80
    while ( my $content = $contents->next ) {
81
    foreach my $biblio (@$items) {
81
        my $biblionumber     = $content->biblionumber->biblionumber;
82
        my $biblionumber     = $biblio->{biblionumber};
83
        my $fw               = GetFrameworkCode($biblionumber);
82
        my $fw               = GetFrameworkCode($biblionumber);
84
        my $dat              = GetBiblioData($biblionumber);
83
        my $dat              = GetBiblioData($biblionumber);
85
        my $record           = GetMarcBiblio($biblionumber, 1);
84
        my $record           = GetMarcBiblio($biblionumber, 1);
(-)a/virtualshelves/shelves.pl (-15 / +22 lines)
Lines 196-213 if ( $op eq 'view' ) { Link Here
196
        if ( $shelf->can_be_viewed( $loggedinuser ) ) {
196
        if ( $shelf->can_be_viewed( $loggedinuser ) ) {
197
            my $sortfield = $query->param('sortfield') || $shelf->sortfield;    # Passed in sorting overrides default sorting
197
            my $sortfield = $query->param('sortfield') || $shelf->sortfield;    # Passed in sorting overrides default sorting
198
            my $direction = $query->param('direction') || 'asc';
198
            my $direction = $query->param('direction') || 'asc';
199
            my ( $shelflimit, $shelfoffset, $itemoff );
199
            my ( $rows, $page );
200
            unless ( $query->param('print') ) {
200
            unless ( $query->param('print') ) {
201
                $shelflimit = C4::Context->preference('numSearchResults') || 20;
201
                $rows = C4::Context->preference('numSearchResults') || 20;
202
                $itemoff = ( $query->param('itemoff') ? $query->param('itemoff') : 1 );
202
                $page = ( $query->param('page') ? $query->param('page') : 1 );
203
                $shelfoffset = ( $itemoff - 1 ) * $shelflimit;    # Sets the offset to begin retrieving items at
204
            }
203
            }
205
            my ( $items, $totitems ) = GetShelfContents( $shelfnumber, $shelflimit, $shelfoffset, $sortfield, $direction );
204
205
            my $contents = $shelf->get_contents->search({}, { join => [ 'biblionumber' ], page => $page, rows => $rows, order_by => "$sortfield $direction", });
206
206
207
            my $borrower = GetMember( borrowernumber => $loggedinuser );
207
            my $borrower = GetMember( borrowernumber => $loggedinuser );
208
208
209
            for my $this_item (@$items) {
209
            my @items;
210
                my $biblionumber = $this_item->{biblionumber};
210
            while ( my $content = $contents->next ) {
211
                my $this_item;
212
                my $biblionumber = $content->biblionumber->biblionumber;
211
                my $record       = GetMarcBiblio($biblionumber);
213
                my $record       = GetMarcBiblio($biblionumber);
212
214
213
                if ( C4::Context->preference("XSLTResultsDisplay") ) {
215
                if ( C4::Context->preference("XSLTResultsDisplay") ) {
Lines 215-223 if ( $op eq 'view' ) { Link Here
215
                }
217
                }
216
218
217
                my $marcflavour = C4::Context->preference("marcflavour");
219
                my $marcflavour = C4::Context->preference("marcflavour");
218
                $this_item->{'imageurl'}        = getitemtypeinfo( $this_item->{'itemtype'}, 'intranet' )->{'imageurl'};
220
                my $itemtypeinfo = getitemtypeinfo( $content->biblionumber->biblioitems->first->itemtype, 'intranet' );
221
                $this_item->{imageurl}          = $itemtypeinfo->{imageurl};
222
                $this_item->{description}       = $itemtypeinfo->{description};
223
                $this_item->{notforloan}        = $itemtypeinfo->{notforloan};
219
                $this_item->{'coins'}           = GetCOinSBiblio($record);
224
                $this_item->{'coins'}           = GetCOinSBiblio($record);
220
                $this_item->{'subtitle'}        = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $this_item->{'biblionumber'} ) );
225
                $this_item->{'subtitle'}        = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $biblionumber ) );
221
                $this_item->{'normalized_upc'}  = GetNormalizedUPC( $record, $marcflavour );
226
                $this_item->{'normalized_upc'}  = GetNormalizedUPC( $record, $marcflavour );
222
                $this_item->{'normalized_ean'}  = GetNormalizedEAN( $record, $marcflavour );
227
                $this_item->{'normalized_ean'}  = GetNormalizedEAN( $record, $marcflavour );
223
                $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour );
228
                $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour );
Lines 230-237 if ( $op eq 'view' ) { Link Here
230
                }
235
                }
231
236
232
                # Getting items infos for location display
237
                # Getting items infos for location display
233
                my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'} );
238
                my @items_infos = &GetItemsLocationInfo( $biblionumber );
234
                $this_item->{'ITEM_RESULTS'} = \@items_infos;
239
                $this_item->{'ITEM_RESULTS'} = \@items_infos;
240
                $this_item->{biblionumber} = $biblionumber;
241
                push @items, $this_item;
235
            }
242
            }
236
243
237
            # Build drop-down list for 'Add To:' menu...
244
            # Build drop-down list for 'Add To:' menu...
Lines 246-260 if ( $op eq 'view' ) { Link Here
246
                can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser),
253
                can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser),
247
                can_add_biblios    => $shelf->can_biblios_be_added($loggedinuser),
254
                can_add_biblios    => $shelf->can_biblios_be_added($loggedinuser),
248
                sortfield          => $sortfield,
255
                sortfield          => $sortfield,
249
                itemsloop          => $items,
256
                itemsloop          => \@items,
250
                sortfield          => $sortfield,
257
                sortfield          => $sortfield,
251
                direction          => $direction,
258
                direction          => $direction,
252
            );
259
            );
253
            if ($shelflimit) {
260
            if ( $page ) {
261
                my $pager = $contents->pager;
254
                $template->param(
262
                $template->param(
255
                    pagination_bar => pagination_bar(
263
                    pagination_bar => pagination_bar(
256
                        q||, ( int( $totitems / $shelflimit ) ) + ( ( $totitems % $shelflimit ) > 0 ? 1 : 0 ),
264
                        q||, $pager->last_page - $pager->first_page + 1,
257
                        $itemoff, "itemoff", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, }
265
                        $page, "page", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, }
258
                    ),
266
                    ),
259
                );
267
                );
260
            }
268
            }
261
- 

Return to bug 14544