X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FVirtualShelves.pm;h=c74ecb3ef871473908658ec1dda0b70b48687973;hb=cb170fe4ff807a9299adfb56acf84e66996f20f1;hp=72571490ecc34c9bfdc01f6b4c02f888822a2f9a;hpb=f8ea370fdd5e62c38dc22b3ee7c8eebcf9a4a780;p=koha_gimpoz diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 72571490ec..c74ecb3ef8 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -26,10 +26,7 @@ use warnings; use Carp; use C4::Context; -use C4::Circulation; use C4::Debug; -use C4::Members; -require C4::Auth; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); @@ -186,9 +183,9 @@ sub GetShelvesSummary ($$$$) { =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>. @@ -197,26 +194,36 @@ the submitted parameters. =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); + $selection = ' WHERE owner = ? AND category = ?'; + } else { + @params = ( $mincategory); + $selection = ' WHERE category >= ? '; + } + my $query = 'SELECT * FROM virtualshelves'; + $query .= $selection; + $query .= ' ORDER BY lastmodified DESC'; + if ($row_count){ + $query .= ' LIMIT ?'; + push @params,$row_count; + } + my $sth = $dbh->prepare($query); + $sth->execute(@params); + my $shelflist = $sth->fetchall_arrayref({}); + return ( $shelflist, $total ); } =head2 GetAllShelves - ($shelflist) = GetAllShelves($owner) + $shelflist = GetAllShelves($owner) -This function returns a references to an array of hashrefs containing all shelves sorted +This function returns a reference to an array of hashrefs containing all shelves sorted by the shelf name. This function is intended to return a dataset reflecting all the shelves for @@ -224,15 +231,12 @@ the submitted parameters. =cut -sub GetAllShelves ($$) { +sub GetAllShelves { my ($category,$owner) = @_; - my (@shelflist); - my @params = ($category,$owner); - my $query = "SELECT * FROM virtualshelves WHERE category = ? AND owner = ? ORDER BY shelfname ASC"; - my $sth = $dbh->prepare($query); - $sth->execute(@params); - @shelflist = $sth->fetchall_arrayref({}); - return ( \@shelflist ); + my $query = 'SELECT * FROM virtualshelves WHERE category = ? AND owner = ? ORDER BY shelfname ASC'; + my $sth = $dbh->prepare( $query ); + $sth->execute( $category, $owner ); + return $sth->fetchall_arrayref({}); } =head2 GetShelf @@ -289,7 +293,7 @@ sub GetShelfContents ($;$$$) { } my $query = " SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded, itemtypes.*, - biblio.*, biblioitems.itemtype, biblioitems.publicationyear, biblioitems.publishercode, biblioitems.place, biblioitems.size, biblioitems.pages + biblio.*, biblioitems.itemtype, biblioitems.publicationyear as year, biblioitems.publishercode, biblioitems.place, biblioitems.size, biblioitems.pages FROM virtualshelfcontents vc LEFT JOIN biblio ON vc.biblionumber = biblio.biblionumber LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber @@ -459,7 +463,8 @@ sub ShelfPossibleAction { my $sth = $dbh->prepare($query); $sth->execute($shelfnumber); my ( $owner, $category ) = $sth->fetchrow; - my $borrower = GetMemberDetails($user); + require C4::Members; + my $borrower = C4::Members::GetMemberDetails($user); return 0 if not defined($user); return 1 if ( $category >= 3); # open list return 1 if (($category >= 2) and @@ -552,7 +557,7 @@ This function is used in conjunction with the 'Lists' button in masthead.inc. =cut sub RefreshShelvesSummary ($$$) { - + require C4::Auth; my ($sessionID, $loggedinuser, $row_count) = @_; my $session = C4::Auth::get_session($sessionID); my ($total, $totshelves, $barshelves, $pubshelves); @@ -563,13 +568,13 @@ sub RefreshShelvesSummary ($$$) { $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);