require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
- &GetShelfContents
);
@EXPORT_OK = qw(
&ShelvesMax
return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar);
}
-=head2 GetShelfContents
-
- $biblist = &GetShelfContents($shelfnumber);
-
-Looks up information about the contents of virtual virtualshelves number
-C<$shelfnumber>. Sorted by a field in the biblio table. copyrightdate
-gives a desc sort.
-
-Returns a reference-to-array, whose elements are references-to-hash,
-as returned by C<C4::Biblio::GetBiblioFromItemNumber>.
-
-Note: the notforloan status comes from the itemtype, and where it equals 0
-it does not ensure that related items.notforloan status is likewise 0. The
-caller has to check any items on their own, possibly with CanBookBeIssued
-from C4::Circulation.
-
-=cut
-
-sub GetShelfContents {
- my ($shelfnumber, $row_count, $offset, $sortfield, $sort_direction ) = @_;
- my $dbh=C4::Context->dbh();
- my $sth1 = $dbh->prepare("SELECT count(*) FROM virtualshelfcontents WHERE shelfnumber = ?");
- $sth1->execute($shelfnumber);
- my $total = $sth1->fetchrow;
- if(!$sortfield) {
- my $sth2 = $dbh->prepare('SELECT sortfield FROM virtualshelves WHERE shelfnumber=?');
- $sth2->execute($shelfnumber);
- ($sortfield) = $sth2->fetchrow_array;
- }
- my $query =
- " SELECT DISTINCT vc.biblionumber, vc.shelfnumber, vc.dateadded, itemtypes.*,
- biblio.*, biblioitems.itemtype, biblioitems.publicationyear as year, biblioitems.publishercode, biblioitems.place, biblioitems.size, biblioitems.pages
- FROM virtualshelfcontents vc
- JOIN biblio ON vc.biblionumber = biblio.biblionumber
- LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
- LEFT JOIN items ON items.biblionumber=vc.biblionumber
- LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
- WHERE vc.shelfnumber=? ";
- my @params = ($shelfnumber);
- if($sortfield) {
- $query .= " ORDER BY " . $dbh->quote_identifier( $sortfield );
- $query .= " DESC " if ( $sort_direction eq 'desc' );
- }
- if($row_count){
- $query .= " LIMIT ?, ? ";
- push (@params, ($offset ? $offset : 0));
- push (@params, $row_count);
- }
- my $sth3 = $dbh->prepare($query);
- $sth3->execute(@params);
- return ($sth3->fetchall_arrayref({}), $total);
- # Like the perldoc says,
- # returns reference-to-array, where each element is reference-to-hash of the row:
- # like [ $sth->fetchrow_hashref(), $sth->fetchrow_hashref() ... ]
- # Suitable for use in TMPL_LOOP.
- # See http://search.cpan.org/~timb/DBI-1.601/DBI.pm#fetchall_arrayref
- # or newer, for your version of DBI.
-}
-
=head2 ShelvesMax
$howmany= ShelvesMax($context);
our $errcode = 0;
our @biblios;
+
+if (scalar(@biblionumber) == 1) {
+ @biblionumber = (split /\//,$biblionumber[0]);
+}
+
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "opac-addbybiblionumber.tt",
}
#end
-sub AddBibliosToShelf {
- #splits incoming biblionumber(s) to array and adds each to shelf.
- my ($shelfnumber,@biblionumber)=@_;
-
- #multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
- if (scalar(@biblionumber) == 1) {
- @biblionumber = (split /\//,$biblionumber[0]);
- }
- for my $bib (@biblionumber) {
- my $shelf = Koha::Virtualshelves->find( $shelfnumber );
- $shelf->add_biblio( $bib, $loggedinuser );
- }
-}
-
sub HandleNewVirtualShelf {
if ( $loggedinuser > 0 and
(
category => $category,
owner => $loggedinuser,
}
- );
+ )->store;
};
if ( $@ or not $shelf ) {
$authorized = 0;
$errcode = 1;
return;
}
- AddBibliosToShelf($shelfnumber, @biblionumber);
+
+ for my $bib (@biblionumber) {
+ $shelf->add_biblio( $bib, $loggedinuser );
+ }
+
#Reload the page where you came from
print $query->header;
print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
my $shelfnumber = $query->param('shelfnumber');
my $shelf = Koha::Virtualshelves->find( $shelfnumber );
if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
- AddBibliosToShelf($shelfnumber,@biblionumber);
+ for my $bib (@biblionumber) {
+ $shelf->add_biblio( $bib, $loggedinuser );
+ }
#Close this page and return
print $query->header;
print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
}
sub LoadBib {
- #see comment in AddBibliosToShelf
- if (scalar(@biblionumber) == 1) {
- @biblionumber = (split /\//,$biblionumber[0]);
- }
for my $bib (@biblionumber) {
my $data = GetBiblioData( $bib );
- push(@biblios,
- { biblionumber => $bib,
- title => $data->{'title'},
- author => $data->{'author'},
- } );
+ push(@biblios,
+ { biblionumber => $bib,
+ title => $data->{'title'},
+ author => $data->{'author'},
+ } );
}
$template->param(
multiple => (scalar(@biblios) > 1),
if ($shelfnumber && $format) {
- my ($items, $totitems) = GetShelfContents($shelfnumber);
+
+ my $contents = $shelf->get_contents;
my $marcflavour = C4::Context->preference('marcflavour');
my $output;
my $extension;
# CSV
if ($format =~ /^\d+$/) {
my @biblios;
- foreach (@$items) {
- push @biblios, $_->{biblionumber};
+ while ( my $content = $contents->next ) {
+ push @biblios, $content->biblionumber->biblionumber;
}
$output = marc2csv(\@biblios, $format);
-
# Other formats
} else {
- foreach my $biblio (@$items) {
- my $biblionumber = $biblio->{biblionumber};
+ while ( my $content = $contents->next ) {
+ my $biblionumber = $content->biblionumber->biblionumber;
my $record = GetMarcBiblio($biblionumber, 1);
next unless $record;
);
my $shelf = Koha::Virtualshelves->find( $shelfid );
- my ($items, $totitems) = GetShelfContents($shelfid);
+ my $contents = $shelf->get_contents;
my $marcflavour = C4::Context->preference('marcflavour');
my $iso2709;
my @results;
- # retrieve biblios from shelf
- foreach my $biblio (@$items) {
- my $biblionumber = $biblio->{biblionumber};
+ while ( my $content = $contents->next ) {
+ my $biblionumber = $content->biblionumber->biblionumber;
my $fw = GetFrameworkCode($biblionumber);
my $dat = GetBiblioData($biblionumber);
my $record = GetMarcBiblio($biblionumber, 1);
$category = $shelf->category;
my $sortfield = $query->param('sortfield') || $shelf->sortfield; # Passed in sorting overrides default sorting
my $direction = $query->param('direction') || 'asc';
- my ( $shelflimit, $shelfoffset, $itemoff );
+ my ( $page, $rows );
unless ( $query->param('print') or $query->param('rss') ) {
- $shelflimit = C4::Context->preference('OPACnumSearchResults') || 20;
- $itemoff = ( $query->param('itemoff') ? $query->param('itemoff') : 1 );
- $shelfoffset = ( $itemoff - 1 ) * $shelflimit; # Sets the offset to begin retrieving items at
+ $rows = C4::Context->preference('OPACnumSearchResults') || 20;
+ $page = ( $query->param('page') ? $query->param('page') : 1 );
}
- my ( $items, $totitems ) = GetShelfContents( $shelfnumber, $shelflimit, $shelfoffset, $sortfield, $direction );
+ my $contents = $shelf->get_contents->search({}, { join => [ 'biblionumber' ], page => $page, rows => $rows, order_by => "$sortfield $direction", });
# get biblionumbers stored in the cart
my @cart_list;
my $borrower = GetMember( borrowernumber => $loggedinuser );
- for my $this_item (@$items) {
- my $biblionumber = $this_item->{biblionumber};
+ my @items;
+ while ( my $content = $contents->next ) {
+ my $this_item;
+ my $biblionumber = $content->biblionumber->biblionumber;
my $record = GetMarcBiblio($biblionumber);
if ( C4::Context->preference("OPACXSLTResultsDisplay") ) {
}
my $marcflavour = C4::Context->preference("marcflavour");
- $this_item->{'imageurl'} = getitemtypeinfo( $this_item->{'itemtype'}, 'intranet' )->{'imageurl'};
+ my $itemtypeinfo = getitemtypeinfo( $content->biblionumber->biblioitems->first->itemtype, 'intranet' );
+ $this_item->{imageurl} = $itemtypeinfo->{imageurl};
+ $this_item->{description} = $itemtypeinfo->{description};
+ $this_item->{notforloan} = $itemtypeinfo->{notforloan};
$this_item->{'coins'} = GetCOinSBiblio($record);
- $this_item->{'subtitle'} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $this_item->{'biblionumber'} ) );
+ $this_item->{'subtitle'} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $biblionumber ) );
$this_item->{'normalized_upc'} = GetNormalizedUPC( $record, $marcflavour );
$this_item->{'normalized_ean'} = GetNormalizedEAN( $record, $marcflavour );
$this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour );
}
# Getting items infos for location display
- my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'} );
+ my @items_infos = &GetItemsLocationInfo( $biblionumber );
$this_item->{'ITEM_RESULTS'} = \@items_infos;
if (C4::Context->preference('TagsEnabled') and C4::Context->preference('TagsShowOnList')) {
$this_item->{TagLoop} = get_tags({
- biblionumber=>$this_item->{'biblionumber'}, approved=>1, 'sort'=>'-weight',
+ biblionumber => $biblionumber, approved=>1, 'sort'=>'-weight',
limit => C4::Context->preference('TagsShowOnList'),
});
}
if ( $query->param('rss') ) {
$this_item->{title} = $content->biblionumber->title;
$this_item->{author} = $content->biblionumber->author;
- $this_item->{biblionumber} = $biblionumber;
}
+
+ $this_item->{biblionumber} = $biblionumber;
push @items, $this_item;
}
can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser),
can_add_biblios => $shelf->can_biblios_be_added($loggedinuser),
sortfield => $sortfield,
- itemsloop => $items,
+ itemsloop => \@items,
sortfield => $sortfield,
direction => $direction,
);
- if ($shelflimit) {
+ if ( $page ) {
+ my $pager = $contents->pager;
$template->param(
pagination_bar => pagination_bar(
- q||, ( int( $totitems / $shelflimit ) ) + ( ( $totitems % $shelflimit ) > 0 ? 1 : 0 ),
- $itemoff, "itemoff", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, }
+ q||, $pager->last_page - $pager->first_page + 1,
+ $page, "page", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, }
),
);
}
return @bib;
}
-sub AddBibliosToShelf {
- my ($shelfnumber, @biblionumber)=@_;
- for my $bib (@biblionumber){
- Koha::Virtualshelves->find( $shelfnumber )->add_biblio( $bib, $loggedinuser );
- }
-}
-
sub HandleNewVirtualShelf {
my $shelf = eval {
Koha::Virtualshelf->new(
owner => $loggedinuser,
}
);
- };
+ }->store;
if ( $@ or not $shelf ) {
$authorized = 0;
$errcode = 1;
return;
}
- AddBibliosToShelf($shelfnumber, @biblionumber);
+ for my $bib (@biblionumber){
+ $shelf->add_biblio( $bib, $loggedinuser );
+ }
#Reload the page where you came from
print $query->header;
print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
sub HandleShelfNumber {
my $shelf = Koha::Virtualshelves->find( $shelfnumber );
if($authorized = $shelf->can_biblios_be_added( $loggedinuser ) ) {
- AddBibliosToShelf($shelfnumber, @biblionumber);
- #Close this page and return
- print $query->header;
- print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
+ for my $bib (@biblionumber){
+ $shelf->add_biblio( $bib, $loggedinuser );
+ }
+ #Close this page and return
+ print $query->header;
+ print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
}
else {
- $errcode=2; #no perm
+ $errcode=2; #no perm
}
}
if ($shelfid && $format) {
- my ($items, $totitems) = GetShelfContents($shelfid);
my $marcflavour = C4::Context->preference('marcflavour');
my $output='';
if ( $shelf ) {
if ( $shelf->can_be_viewed( $loggedinuser ) ) {
+ my $contents = $shelf->get_contents;
# CSV
if ($format =~ /^\d+$/) {
my @biblios;
- foreach (@$items) {
- push @biblios, $_->{biblionumber};
+ while ( my $content = $contents->next ) {
+ push @biblios, $content->biblionumber->biblionumber;
}
$output = marc2csv(\@biblios, $format);
}
else { #Other formats
- foreach my $biblio (@$items) {
- my $biblionumber = $biblio->{biblionumber};
+ while ( my $content = $contents->next ) {
+ my $biblionumber = $content->biblionumber->biblionumber;
my $record = GetMarcBiblio($biblionumber, 1);
if ($format eq 'iso2709') {
$output .= $record->as_usmarc();
);
my $shelf = Koha::Virtualshelves->find( $shelfid );
- my ( $items, $totitems ) = GetShelfContents($shelf->shelfnumber);
+ my $contents = $shelf->get_contents;
my $marcflavour = C4::Context->preference('marcflavour');
my $iso2709;
my @results;
- # retrieve biblios from shelf
- foreach my $biblio (@$items) {
- my $biblionumber = $biblio->{biblionumber};
+ while ( my $content = $contents->next ) {
+ my $biblionumber = $content->biblionumber->biblionumber;
my $fw = GetFrameworkCode($biblionumber);
my $dat = GetBiblioData($biblionumber);
my $record = GetMarcBiblio($biblionumber, 1);
if ( $shelf->can_be_viewed( $loggedinuser ) ) {
my $sortfield = $query->param('sortfield') || $shelf->sortfield; # Passed in sorting overrides default sorting
my $direction = $query->param('direction') || 'asc';
- my ( $shelflimit, $shelfoffset, $itemoff );
+ my ( $rows, $page );
unless ( $query->param('print') ) {
- $shelflimit = C4::Context->preference('numSearchResults') || 20;
- $itemoff = ( $query->param('itemoff') ? $query->param('itemoff') : 1 );
- $shelfoffset = ( $itemoff - 1 ) * $shelflimit; # Sets the offset to begin retrieving items at
+ $rows = C4::Context->preference('numSearchResults') || 20;
+ $page = ( $query->param('page') ? $query->param('page') : 1 );
}
- my ( $items, $totitems ) = GetShelfContents( $shelfnumber, $shelflimit, $shelfoffset, $sortfield, $direction );
+
+ my $contents = $shelf->get_contents->search({}, { join => [ 'biblionumber' ], page => $page, rows => $rows, order_by => "$sortfield $direction", });
my $borrower = GetMember( borrowernumber => $loggedinuser );
- for my $this_item (@$items) {
- my $biblionumber = $this_item->{biblionumber};
+ my @items;
+ while ( my $content = $contents->next ) {
+ my $this_item;
+ my $biblionumber = $content->biblionumber->biblionumber;
my $record = GetMarcBiblio($biblionumber);
if ( C4::Context->preference("XSLTResultsDisplay") ) {
}
my $marcflavour = C4::Context->preference("marcflavour");
- $this_item->{'imageurl'} = getitemtypeinfo( $this_item->{'itemtype'}, 'intranet' )->{'imageurl'};
+ my $itemtypeinfo = getitemtypeinfo( $content->biblionumber->biblioitems->first->itemtype, 'intranet' );
+ $this_item->{imageurl} = $itemtypeinfo->{imageurl};
+ $this_item->{description} = $itemtypeinfo->{description};
+ $this_item->{notforloan} = $itemtypeinfo->{notforloan};
$this_item->{'coins'} = GetCOinSBiblio($record);
- $this_item->{'subtitle'} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $this_item->{'biblionumber'} ) );
+ $this_item->{'subtitle'} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $biblionumber ) );
$this_item->{'normalized_upc'} = GetNormalizedUPC( $record, $marcflavour );
$this_item->{'normalized_ean'} = GetNormalizedEAN( $record, $marcflavour );
$this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour );
}
# Getting items infos for location display
- my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'} );
+ my @items_infos = &GetItemsLocationInfo( $biblionumber );
$this_item->{'ITEM_RESULTS'} = \@items_infos;
+ $this_item->{biblionumber} = $biblionumber;
+ push @items, $this_item;
}
# Build drop-down list for 'Add To:' menu...
can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser),
can_add_biblios => $shelf->can_biblios_be_added($loggedinuser),
sortfield => $sortfield,
- itemsloop => $items,
+ itemsloop => \@items,
sortfield => $sortfield,
direction => $direction,
);
- if ($shelflimit) {
+ if ( $page ) {
+ my $pager = $contents->pager;
$template->param(
pagination_bar => pagination_bar(
- q||, ( int( $totitems / $shelflimit ) ) + ( ( $totitems % $shelflimit ) > 0 ? 1 : 0 ),
- $itemoff, "itemoff", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, }
+ q||, $pager->last_page - $pager->first_page + 1,
+ $page, "page", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, }
),
);
}