Bug 7600: Return a single-pixel GIF when no local cover image exists
[koha_gimpoz] / C4 / VirtualShelves.pm
index 97cd150..c74ecb3 100644 (file)
@@ -26,10 +26,7 @@ use warnings;
 
 use Carp;
 use C4::Context;
 
 use Carp;
 use C4::Context;
-use C4::Circulation;
 use C4::Debug;
 use C4::Debug;
-use C4::Members;
-require C4::Auth;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
 
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
 
@@ -40,14 +37,14 @@ BEGIN {
        @ISA    = qw(Exporter);
        @EXPORT = qw(
             &GetShelves &GetShelfContents &GetShelf
        @ISA    = qw(Exporter);
        @EXPORT = qw(
             &GetShelves &GetShelfContents &GetShelf
-            &AddToShelf &AddToShelfFromBiblio &AddShelf
+            &AddToShelf &AddShelf
             &ModShelf
             &ShelfPossibleAction
             &DelFromShelf &DelShelf
             &GetBibliosShelves
        );
         @EXPORT_OK = qw(
             &ModShelf
             &ShelfPossibleAction
             &DelFromShelf &DelShelf
             &GetBibliosShelves
        );
         @EXPORT_OK = qw(
-            &GetShelvesSummary &GetRecentShelves
+            &GetShelvesSummary &GetRecentShelves &GetAllShelves
             &RefreshShelvesSummary &SetShelvesLimit
         );
 }
             &RefreshShelvesSummary &SetShelvesLimit
         );
 }
@@ -67,7 +64,7 @@ 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
 
 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
 
 
 =head1 FUNCTIONS
 
@@ -116,8 +113,7 @@ sub GetShelves ($$$$) {
     $query .= ($mincategory == 1) ? "WHERE  owner=? AND category=?" : "WHERE category>=?";
        $query .= qq(
         GROUP BY virtualshelves.shelfnumber
     $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);
                LIMIT ?, ?);
     my $sth2 = $dbh->prepare($query);
     $sth2->execute(@params);
@@ -126,6 +122,7 @@ sub GetShelves ($$$$) {
                $firstname,   $category,  $sortfield, $count ) = $sth2->fetchrow ) {
         $shelflist{$shelfnumber}->{'shelfname'} = $shelfname;
         $shelflist{$shelfnumber}->{'count'}     = $count;
                $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;
         $shelflist{$shelfnumber}->{'sortfield'} = $sortfield;
         $shelflist{$shelfnumber}->{'category'}  = $category;
         $shelflist{$shelfnumber}->{'owner'}     = $owner;
@@ -186,9 +183,9 @@ sub GetShelvesSummary ($$$$) {
 
 =head2 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>.
 
 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,19 +194,49 @@ the submitted parameters.
 
 =cut
 
 
 =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)
+
+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
 }
 
 =head2 GetShelf
@@ -237,7 +264,7 @@ sub GetShelf ($) {
 
 =head2 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 
 
 Looks up information about the contents of virtual virtualshelves number
 C<$shelfnumber>.  Sorted by a field in the biblio table.  copyrightdate 
@@ -266,7 +293,7 @@ sub GetShelfContents ($;$$$) {
        }
     my $query =
        " SELECT vc.biblionumber, vc.shelfnumber, vc.dateadded, itemtypes.*,
        }
     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
          FROM   virtualshelfcontents vc
                 LEFT JOIN biblio      ON      vc.biblionumber =      biblio.biblionumber
                 LEFT JOIN biblioitems ON  biblio.biblionumber = biblioitems.biblionumber
@@ -331,8 +358,8 @@ sub AddShelf {
 
   &AddToShelf($biblionumber, $shelfnumber);
 
 
   &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
 
 
 =cut
 
@@ -364,42 +391,6 @@ sub AddToShelf {
        $sth->execute( $shelfnumber );
 }
 
        $sth->execute( $shelfnumber );
 }
 
-=head2 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 );
-    }
-}
-
 =head2 ModShelf
 
 ModShelf($shelfnumber, $hashref)
 =head2 ModShelf
 
 ModShelf($shelfnumber, $hashref)
@@ -472,7 +463,8 @@ sub ShelfPossibleAction {
     my $sth = $dbh->prepare($query);
     $sth->execute($shelfnumber);
     my ( $owner, $category ) = $sth->fetchrow;
     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
        return 0 if not defined($user);
        return 1 if ( $category >= 3);                                                  # open list
     return 1 if (($category >= 2) and
@@ -486,8 +478,8 @@ sub ShelfPossibleAction {
 
   &DelFromShelf( $biblionumber, $shelfnumber);
 
 
   &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
 nothing happens.
 
 =cut
@@ -565,7 +557,7 @@ This function is used in conjunction with the 'Lists' button in masthead.inc.
 =cut
 
 sub RefreshShelvesSummary ($$$) {
 =cut
 
 sub RefreshShelvesSummary ($$$) {
-       
+       require C4::Auth;
        my ($sessionID, $loggedinuser, $row_count) = @_;
        my $session = C4::Auth::get_session($sessionID);
        my ($total, $totshelves, $barshelves, $pubshelves);
        my ($sessionID, $loggedinuser, $row_count) = @_;
        my $session = C4::Auth::get_session($sessionID);
        my ($total, $totshelves, $barshelves, $pubshelves);
@@ -576,13 +568,13 @@ sub RefreshShelvesSummary ($$$) {
        $total->{'pubtotal'} = $totshelves;
 
        # Update the current session with the latest shelves...
        $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...
        $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);
        C4::Context::set_shelves_userenv('tot',$total);
 
        return ($total, $pubshelves, $barshelves);
@@ -628,7 +620,7 @@ __END__
 
 =head1 AUTHOR
 
 
 =head1 AUTHOR
 
-Koha Development Team <info@koha.org>
+Koha Development Team <http://koha-community.org/>
 
 =head1 SEE ALSO
 
 
 =head1 SEE ALSO