$template->param( loggedinusername => $user );
$template->param( sessionID => $sessionID );
- my ($total, $pubshelves, $barshelves) = C4::Context->get_shelves_userenv();
- if (defined($pubshelves)) {
- $template->param( pubshelves => scalar (@$pubshelves),
- pubshelvesloop => $pubshelves,
- );
- $template->param( pubtotal => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar (@$pubshelves));
- }
- if (defined($barshelves)) {
- $template->param( barshelves => scalar (@$barshelves),
- barshelvesloop => $barshelves,
- );
- $template->param( bartotal => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar (@$barshelves));
- }
+ my ($total, $pubshelves, $barshelves) = C4::Context->get_shelves_userenv();
+ if (defined($pubshelves)) {
+ $template->param( pubshelves => scalar @{$pubshelves},
+ pubshelvesloop => $pubshelves,
+ );
+ $template->param( pubtotal => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar @{$pubshelves});
+ }
+ if (defined($barshelves)) {
+ $template->param( barshelves => scalar @{$barshelves},
+ barshelvesloop => $barshelves,
+ );
+ $template->param( bartotal => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar @{$barshelves});
+ }
$borrowernumber = getborrowernumber($user) if defined($user);
$template->param( sessionID => $sessionID );
my ($total, $pubshelves) = C4::Context->get_shelves_userenv(); # an anonymous user has no 'barshelves'...
- if (defined(($pubshelves))) {
- $template->param( pubshelves => scalar (@$pubshelves),
+ if (defined $pubshelves) {
+ $template->param( pubshelves => scalar @{$pubshelves},
pubshelvesloop => $pubshelves,
);
- $template->param( pubtotal => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar (@$pubshelves));
+ $template->param( pubtotal => $total->{'pubtotal'}, ) if ($total->{'pubtotal'} > scalar @{$pubshelves});
}
}
$total->{'bartotal'} = $totshelves;
($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef);
$total->{'pubtotal'} = $totshelves;
- $session->param('barshelves', $barshelves->[0]);
- $session->param('pubshelves', $pubshelves->[0]);
+ $session->param('barshelves', $barshelves);
+ $session->param('pubshelves', $pubshelves);
$session->param('totshelves', $total);
- C4::Context::set_shelves_userenv('bar',$barshelves->[0]);
- C4::Context::set_shelves_userenv('pub',$pubshelves->[0]);
+ C4::Context::set_shelves_userenv('bar',$barshelves);
+ C4::Context::set_shelves_userenv('pub',$pubshelves);
C4::Context::set_shelves_userenv('tot',$total);
}
else {
my ($total, $totshelves, $pubshelves);
($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef);
$total->{'pubtotal'} = $totshelves;
- $session->param('pubshelves', $pubshelves->[0]);
+ $session->param('pubshelves', $pubshelves);
$session->param('totshelves', $total);
- C4::Context::set_shelves_userenv('pub',$pubshelves->[0]);
+ C4::Context::set_shelves_userenv('pub',$pubshelves);
C4::Context::set_shelves_userenv('tot',$total);
# setting a couple of other session vars...
=head2 GetRecentShelves
- ($shelflist) = GetRecentShelves(1, $limit, $owner)
+ ($shelflist, $total) = GetRecentShelves(1, $limit, $owner)
-This function returns a references to an array of hashrefs containing specified shelves sorted
+This function returns a reference to an array of hashrefs containing specified shelves sorted
by the date the shelf was last modified in descending order limited to the number of records
specified by C<$row_count>. If calling with C<$mincategory> other than 1, use undef as C<$owner>.
=cut
-sub GetRecentShelves ($$$) {
- my ($mincategory, $row_count, $owner) = @_;
- my (@shelflist);
- my $total = _shelf_count($owner, $mincategory);
- my @params = ($owner, $mincategory, 0, $row_count); #FIXME: offset is hardcoded here, but could be passed in for enhancements
- shift @params if (not defined $owner);
- my $query = "SELECT * FROM virtualshelves";
- $query .= ((defined $owner) ? " WHERE owner = ? AND category = ?" : " WHERE category >= ? ");
- $query .= " ORDER BY lastmodified DESC LIMIT ?, ?";
- my $sth = $dbh->prepare($query);
- $sth->execute(@params);
- @shelflist = $sth->fetchall_arrayref({});
- return ( \@shelflist, $total );
+sub GetRecentShelves {
+ my ($mincategory, $row_count, $owner) = @_;
+ my $total = _shelf_count($owner, $mincategory);
+ my @params;
+ my $selection;
+ if (defined $owner) {
+ @params = ($owner, $mincategory, $row_count);
+ $selection = ' WHERE owner = ? AND category = ?';
+ } else {
+ @params = ( $mincategory, $row_count);
+ $selection = ' WHERE category >= ? ';
+ }
+ my $query = 'SELECT * FROM virtualshelves';
+ $query .= $selection;
+ $query .= ' ORDER BY lastmodified DESC LIMIT ?';
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@params);
+ my $shelflist = $sth->fetchall_arrayref({});
+ return ( $shelflist, $total );
}
=head2 GetAllShelves
$total->{'pubtotal'} = $totshelves;
# Update the current session with the latest shelves...
- $session->param('barshelves', $barshelves->[0]);
- $session->param('pubshelves', $pubshelves->[0]);
+ $session->param('barshelves', $barshelves);
+ $session->param('pubshelves', $pubshelves);
$session->param('totshelves', $total);
# likewise the userenv...
- C4::Context->set_shelves_userenv('bar',$barshelves->[0]);
- C4::Context->set_shelves_userenv('pub',$pubshelves->[0]);
+ C4::Context->set_shelves_userenv('bar',$barshelves);
+ C4::Context->set_shelves_userenv('pub',$pubshelves);
C4::Context::set_shelves_userenv('tot',$total);
return ($total, $pubshelves, $barshelves);
if ( defined $barshelves ) {
$template->param(
- barshelves => scalar( @{ $barshelves->[0] } ),
- barshelvesloop => $barshelves->[0],
+ barshelves => scalar( @{ $barshelves } ),
+ barshelvesloop => $barshelves,
);
- $template->param( bartotal => $total->{'bartotal'}, ) if ( $total->{'bartotal'} > scalar( @{ $barshelves->[0] } ) );
+ $template->param( bartotal => $total->{'bartotal'}, ) if ( $total->{'bartotal'} > scalar( @{ $barshelves } ) );
}
if ( defined $pubshelves ) {
$template->param(
- pubshelves => scalar( @{ $pubshelves->[0] } ),
- pubshelvesloop => $pubshelves->[0],
+ pubshelves => scalar( @{ $pubshelves } ),
+ pubshelvesloop => $pubshelves,
);
- $template->param( pubtotal => $total->{'pubtotal'}, ) if ( $total->{'pubtotal'} > scalar( @{ $pubshelves->[0] } ) );
+ $template->param( pubtotal => $total->{'pubtotal'}, ) if ( $total->{'pubtotal'} > scalar( @{ $pubshelves } ) );
}
output_html_with_http_headers $query, $cookie, $template->output;
my ($pubshelves, $total) = GetRecentShelves(2, $row_count, undef);
my ($barshelves, $total) = GetRecentShelves(1, $row_count, $borrowernumber);
-my @pubshelves = @{$pubshelves};
-my @barshelves = @{$barshelves};
-
-if (@pubshelves) {
- $template->param( addpubshelves => scalar (@pubshelves));
- $template->param( addpubshelvesloop => @pubshelves);
+if (@{$pubshelves}) {
+ $template->param( addpubshelves => scalar @{$pubshelves});
+ $template->param( addpubshelvesloop => $pubshelves);
}
-if (@barshelves) {
- $template->param( addbarshelves => scalar (@barshelves));
- $template->param( addbarshelvesloop => @barshelves);
+if (@{$barshelves}) {
+ $template->param( addbarshelves => scalar @{$barshelves});
+ $template->param( addbarshelvesloop => $barshelves);
}
param1 += "<option id=\"s<!-- TMPL_VAR NAME="shelfnumber" -->\" value=\"addtolist\"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"--><\/option>";<!-- /TMPL_LOOP -->
param1 += "<\/optgroup>";<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="addpubshelves" -->param1 += "<optgroup label=\""+_("Public Lists:")+"\">"<!-- TMPL_LOOP NAME="addpubshelvesloop" -->+"<option id=\"s<!-- TMPL_VAR NAME="shelfnumber" -->\" value=\"addtolist\"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"--><\/option>"<!-- /TMPL_LOOP -->
+ <!-- /TMPL_IF -->
param1 +="<\/optgroup><option value=\"newlist\">"+_("[ New List ]")+"<\/option>"
-<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
param1 += "<\/select> <input id=\"cartsubmit\" type=\"submit\" class=\"submit\" value=\""+_("Save")+"\" />";
$('#sortsubmit').hide();
#grab each type of shelf, open (type 3) should not be limited by user.
foreach my $shelftype (1,2,3) {
my ($shelflist) = GetRecentShelves($shelftype, $limit, $shelftype == 3 ? undef : $loggedinuser);
- for my $shelf (@{ $shelflist->[0] }) {
+ for my $shelf (@{ $shelflist }) {
push(@shelvesloop, $shelf->{shelfnumber});
$shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
}
}
- if(@shelvesloop gt 0){
+ if( @shelvesloop ){
my $CGIvirtualshelves = CGI::scrolling_list
(
-name => 'shelfnumber',