X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FVirtualShelves.pm;h=57b86daba38f6dd713d339747e0a45b35f48dbac;hb=b2155fc483f09b34c4a6ba92256f2732152bb1d5;hp=e47b4b8eed5a90daed9e3ae1a37374b6bf319a06;hpb=64daee549541d8dc7c763426f417bdfe97f085bc;p=koha.git diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index e47b4b8eed..57b86daba3 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -40,14 +40,14 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &GetShelves &GetShelfContents &GetShelf - &AddToShelf &AddToShelfFromBiblio &AddShelf + &AddToShelf &AddShelf &ModShelf &ShelfPossibleAction &DelFromShelf &DelShelf &GetBibliosShelves ); @EXPORT_OK = qw( - &GetShelvesSummary &GetRecentShelves + &GetShelvesSummary &GetRecentShelves &GetAllShelves &RefreshShelvesSummary &SetShelvesLimit ); } @@ -67,13 +67,11 @@ C4::VirtualShelves - Functions for manipulating Koha virtual virtualshelves This module provides functions for manipulating virtual virtualshelves, including creating and deleting virtualshelves, and adding and removing -items to and from virtualshelves. +bibs to and from virtualshelves. =head1 FUNCTIONS -=over 2 - -=item GetShelves +=head2 GetShelves ($shelflist, $totshelves) = &GetShelves($mincategory, $row_count, $offset, $owner); ($shelfnumber, $shelfhash) = each %{$shelflist}; @@ -85,7 +83,7 @@ When C<$mincategory> is 2 or 3, supply undef as argument for C<$owner>. C<$shelflist>is a reference-to-hash. The keys are the virtualshelves numbers (C<$shelfnumber>, above), and the values (C<$shelfhash>, above) are themselves references-to-hash, with the following keys: -=over 4 +=over =item C<$shelfhash-E{shelfname}> @@ -118,8 +116,7 @@ sub GetShelves ($$$$) { $query .= ($mincategory == 1) ? "WHERE owner=? AND category=?" : "WHERE category>=?"; $query .= qq( GROUP BY virtualshelves.shelfnumber - ORDER BY virtualshelves.category - DESC + ORDER BY virtualshelves.shelfname LIMIT ?, ?); my $sth2 = $dbh->prepare($query); $sth2->execute(@params); @@ -128,6 +125,7 @@ sub GetShelves ($$$$) { $firstname, $category, $sortfield, $count ) = $sth2->fetchrow ) { $shelflist{$shelfnumber}->{'shelfname'} = $shelfname; $shelflist{$shelfnumber}->{'count'} = $count; + if($count eq 1){ $shelflist{$shelfnumber}->{'single'} = 1; } $shelflist{$shelfnumber}->{'sortfield'} = $sortfield; $shelflist{$shelfnumber}->{'category'} = $category; $shelflist{$shelfnumber}->{'owner'} = $owner; @@ -137,7 +135,7 @@ sub GetShelves ($$$$) { return ( \%shelflist, $total ); } -=item GetShelvesSummary +=head2 GetShelvesSummary ($shelves, $total) = GetShelvesSummary($mincategory, $row_count, $offset, $owner) @@ -186,11 +184,11 @@ sub GetShelvesSummary ($$$$) { # 2|6|Josh Ferraro|51|en_fuego|106 } -=item GetRecentShelves +=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>. @@ -199,22 +197,52 @@ 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 ); } -=item GetShelf +=head2 GetAllShelves + + $shelflist = GetAllShelves($owner) + +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 +the submitted parameters. + +=cut + +sub GetAllShelves { + my ($category,$owner) = @_; + 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 (shelfnumber,shelfname,owner,category,sortfield) = &GetShelf($shelfnumber); @@ -237,9 +265,9 @@ sub GetShelf ($) { return $sth->fetchrow; } -=item GetShelfContents +=head2 GetShelfContents - $itemlist = &GetShelfContents($shelfnumber); + $biblist = &GetShelfContents($shelfnumber); Looks up information about the contents of virtual virtualshelves number C<$shelfnumber>. Sorted by a field in the biblio table. copyrightdate @@ -268,7 +296,7 @@ sub GetShelfContents ($;$$$) { } my $query = " SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded, itemtypes.*, - biblio.*, biblioitems.itemtype, biblioitems.publicationyear + 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 @@ -295,7 +323,7 @@ sub GetShelfContents ($;$$$) { # or newer, for your version of DBI. } -=item AddShelf +=head2 AddShelf $shelfnumber = &AddShelf( $shelfname, $owner, $category); @@ -329,12 +357,12 @@ sub AddShelf { return ($shelfnumber); } -=item AddToShelf +=head2 AddToShelf &AddToShelf($biblionumber, $shelfnumber); -Adds item number C<$biblionumber> to virtual virtualshelves number -C<$shelfnumber>, unless that item is already on that shelf. +Adds bib number C<$biblionumber> to virtual virtualshelves number +C<$shelfnumber>, unless that bib is already on that shelf. =cut @@ -366,43 +394,7 @@ sub AddToShelf { $sth->execute( $shelfnumber ); } -=item AddToShelfFromBiblio - - &AddToShelfFromBiblio($biblionumber, $shelfnumber) - - this function allow to add a virtual into the shelf number $shelfnumber - from biblionumber. - -=cut - -sub AddToShelfFromBiblio { - my ( $biblionumber, $shelfnumber ) = @_; - return unless $biblionumber; - my $query = qq( - SELECT * - FROM virtualshelfcontents - WHERE shelfnumber=? AND biblionumber=? - ); - my $sth = $dbh->prepare($query); - $sth->execute( $shelfnumber, $biblionumber ); - unless ( $sth->rows ) { - my $query =qq( - INSERT INTO virtualshelfcontents - (shelfnumber, biblionumber, flags) - VALUES - (?, ?, 0) - ); - $sth = $dbh->prepare($query); - $sth->execute( $shelfnumber, $biblionumber ); - $query = qq(UPDATE virtualshelves - SET lastmodified = CURRENT_TIMESTAMP - WHERE shelfnumber = ?); - $sth = $dbh->prepare($query); - $sth->execute( $shelfnumber ); - } -} - -=item ModShelf +=head2 ModShelf ModShelf($shelfnumber, $hashref) @@ -451,7 +443,7 @@ sub ModShelf { $sth->execute( @bind_params ); } -=item ShelfPossibleAction +=head2 ShelfPossibleAction ShelfPossibleAction($loggedinuser, $shelfnumber, $action); @@ -484,12 +476,12 @@ sub ShelfPossibleAction { return 0; } -=item DelFromShelf +=head2 DelFromShelf &DelFromShelf( $biblionumber, $shelfnumber); -Removes item number C<$biblionumber> from virtual virtualshelves number -C<$shelfnumber>. If the item wasn't on that virtualshelves to begin with, +Removes bib number C<$biblionumber> from virtual virtualshelves number +C<$shelfnumber>. If the bib wasn't on that virtualshelves to begin with, nothing happens. =cut @@ -505,7 +497,7 @@ sub DelFromShelf { $sth->execute( $shelfnumber, $biblionumber ); } -=item DelShelf (old version) +=head2 DelShelf (old version) ($status, $msg) = &DelShelf($shelfnumber); @@ -516,7 +508,7 @@ Returns a two-element array, where C<$status> is 0 if the operation was successful, or non-zero otherwise. C<$msg> is "Done" in case of success, or an error message giving the reason for failure. -=item DelShelf (current version) +=head2 DelShelf (current version) $Number = DelShelf($shelfnumber); @@ -533,7 +525,7 @@ sub DelShelf { return $sth->execute(shift); } -=item GetBibShelves +=head2 GetBibShelves This finds all the public lists that this bib record is in. @@ -553,7 +545,7 @@ sub GetBibliosShelves { return $sth->fetchall_arrayref({}); } -=item RefreshShelvesSummary +=head2 RefreshShelvesSummary ($total, $pubshelves, $barshelves) = RefreshShelvesSummary($sessionID, $loggedinuser, $row_count); @@ -578,13 +570,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); @@ -628,11 +620,9 @@ sub each_biblionumbers (&$) { __END__ -=back - =head1 AUTHOR -Koha Development Team +Koha Development Team =head1 SEE ALSO