X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FVirtualShelves.pm;h=5e1c3f4d578eea01159d1b1e4bdf0cd40c2db4a3;hb=2eac2e7242aa2685df8f511c49bbf50cb55be4fd;hp=6238f791c1bb4c0583379630516c9a1dbf2a43db;hpb=542c54e067e75d6c0f9fa470241541db35c34e02;p=koha.git diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 6238f791c1..5e1c3f4d57 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -17,16 +17,19 @@ package C4::VirtualShelves; # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; +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); @@ -36,21 +39,19 @@ BEGIN { require Exporter; @ISA = qw(Exporter); @EXPORT = qw( - &GetShelves &GetShelfContents &GetShelf - &GetRecentShelves &GetShelvesSummary - - &AddToShelf &AddToShelfFromBiblio &AddShelf - - &SetShelvesLimit - &RefreshShelvesSummary - - &ModShelf - &ShelfPossibleAction - &DelFromShelf &DelShelf + &GetShelves &GetShelfContents &GetShelf + &AddToShelf &AddToShelfFromBiblio &AddShelf + &ModShelf + &ShelfPossibleAction + &DelFromShelf &DelShelf + &GetBibliosShelves ); + @EXPORT_OK = qw( + &GetShelvesSummary &GetRecentShelves + &RefreshShelvesSummary &SetShelvesLimit + ); } -use C4::Auth qw(get_session); my $dbh = C4::Context->dbh; @@ -203,9 +204,9 @@ sub GetRecentShelves ($$$) { 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 !$owner; + shift @params if (not defined $owner); my $query = "SELECT * FROM virtualshelves"; - $query .= ($owner ? " WHERE owner = ? AND category = ?" : " WHERE category >= ? "); + $query .= ((defined $owner) ? " WHERE owner = ? AND category = ?" : " WHERE category >= ? "); $query .= " ORDER BY lastmodified DESC LIMIT ?, ?"; my $sth = $dbh->prepare($query); $sth->execute(@params); @@ -254,7 +255,7 @@ from C4::Circulation. =cut -sub GetShelfContents ($$;$$) { +sub GetShelfContents ($;$$$) { my ($shelfnumber, $row_count, $offset, $sortfield) = @_; my $dbh=C4::Context->dbh(); my $sth1 = $dbh->prepare("SELECT count(*) FROM virtualshelfcontents WHERE shelfnumber = ?"); @@ -266,8 +267,8 @@ sub GetShelfContents ($$;$$) { ($sortfield) = $sth2->fetchrow_array; } my $query = - " SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded, - biblio.*, biblioitems.itemtype, itemtypes.* + " SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded, itemtypes.*, + biblio.*, biblioitems.itemtype, biblioitems.publicationyear FROM virtualshelfcontents vc LEFT JOIN biblio ON vc.biblionumber = biblio.biblionumber LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber @@ -279,9 +280,11 @@ sub GetShelfContents ($$;$$) { $query .= " DESC " if ($sortfield eq 'copyrightdate'); push (@params, $sortfield); } - $query .= " LIMIT ?, ? "; - push (@params, ($offset ? $offset : 0)); - push (@params, $row_count); + 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); @@ -473,6 +476,7 @@ sub ShelfPossibleAction { $sth->execute($shelfnumber); my ( $owner, $category ) = $sth->fetchrow; my $borrower = GetMemberDetails($user); + return 0 if not defined($user); return 1 if ( $category >= 3); # open list return 1 if (($category >= 2) and defined($action) and $action eq 'view'); # public list, anybody can view @@ -530,6 +534,26 @@ sub DelShelf { return $sth->execute(shift); } +=item GetBibShelves + +This finds all the public lists that this bib record is in. + +=cut + +sub GetBibliosShelves { + my ( $biblionumber ) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare(' + SELECT vs.shelfname, vs.shelfnumber + FROM virtualshelves vs + JOIN virtualshelfcontents vc ON (vs.shelfnumber= vc.shelfnumber) + WHERE vs.category != 1 + AND vc.biblionumber= ? + '); + $sth->execute( $biblionumber ); + return $sth->fetchall_arrayref({}); +} + =item RefreshShelvesSummary ($total, $pubshelves, $barshelves) = RefreshShelvesSummary($sessionID, $loggedinuser, $row_count); @@ -546,7 +570,7 @@ This function is used in conjunction with the 'Lists' button in masthead.inc. sub RefreshShelvesSummary ($$$) { my ($sessionID, $loggedinuser, $row_count) = @_; - my $session = get_session($sessionID); + my $session = C4::Auth::get_session($sessionID); my ($total, $totshelves, $barshelves, $pubshelves); ($barshelves, $totshelves) = GetRecentShelves(1, $row_count, $loggedinuser); @@ -581,6 +605,26 @@ sub _shelf_count ($$) { return $total; } +sub _biblionumber_sth { + my ($shelf) = @_; + my $query = 'select biblionumber from virtualshelfcontents where shelfnumber = ?'; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query) + or die $dbh->errstr; + $sth->execute( $shelf ) + or die $sth->errstr; + $sth; +} + +sub each_biblionumbers (&$) { + my ($code,$shelf) = @_; + my $ref = _biblionumber_sth($shelf)->fetchall_arrayref; + map { + $_=$$_[0]; + $code->(); + } @$ref; +} + 1; __END__