Bug 9044: (follow-up) fix merge conflict typo that broke this script
[koha.git] / C4 / RotatingCollections.pm
index 254453f..09b5216 100644 (file)
@@ -18,11 +18,12 @@ package C4::RotatingCollections;
 # 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; FIXME - Bug 2505
 
 require Exporter;
 
@@ -36,7 +37,7 @@ use Data::Dumper;
 use vars qw($VERSION @ISA @EXPORT);
 
 # set the version for version checking
-$VERSION = 0.01;
+$VERSION = 3.07.00.049;
 
 =head1 NAME
 
@@ -44,8 +45,6 @@ C4::RotatingCollections - Functions for managing rotating collections
 
 =head1 FUNCTIONS
 
-=over 2
-
 =cut
 
 @ISA = qw( Exporter );
@@ -66,7 +65,7 @@ C4::RotatingCollections - Functions for managing rotating collections
   GetCollectionItemBranches
 );
 
-=item  CreateCollection
+=head2  CreateCollection
  ( $success, $errorcode, $errormessage ) = CreateCollection( $title, $description );
  Creates a new collection
 
@@ -78,7 +77,9 @@ C4::RotatingCollections - Functions for managing rotating collections
    $success: 1 if all database operations were successful, 0 otherwise
    $errorCode: Code for reason of failure, good for translating errors in templates
    $errorMessage: English description of error
+
 =cut
+
 sub CreateCollection {
   my ( $title, $description ) = @_;
 
@@ -98,15 +99,16 @@ sub CreateCollection {
   $sth = $dbh->prepare("INSERT INTO collections ( colId, colTitle, colDesc ) 
                         VALUES ( NULL, ?, ? )");
   $sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() );
-  $sth->finish;
 
   return 1;
-  
 }
 
-=item UpdateCollection
+=head2 UpdateCollection
+
  ( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description );
- Updates a collection
+
+Updates a collection
 
  Input:
    $colId: id of the collection to be updated
@@ -117,7 +119,9 @@ sub CreateCollection {
    $success: 1 if all database operations were successful, 0 otherwise
    $errorCode: Code for reason of failure, good for translating errors in templates
    $errorMessage: English description of error
+
 =cut
+
 sub UpdateCollection {
   my ( $colId, $title, $description ) = @_;
 
@@ -140,13 +144,13 @@ sub UpdateCollection {
                         colTitle = ?, colDesc = ? 
                         WHERE colId = ?");
   $sth->execute( $title, $description, $colId ) or return ( 0, 4, $sth->errstr() );
-  $sth->finish;
   
   return 1;
   
 }
 
-=item DeleteCollection
+=head2 DeleteCollection
+
  ( $success, $errorcode, $errormessage ) = DeleteCollection( $colId );
  Deletes a collection of the given id
 
@@ -157,7 +161,9 @@ sub UpdateCollection {
    $success: 1 if all database operations were successful, 0 otherwise
    $errorCode: Code for reason of failure, good for translating errors in templates
    $errorMessage: English description of error
+
 =cut
+
 sub DeleteCollection {
   my ( $colId ) = @_;
 
@@ -172,12 +178,12 @@ sub DeleteCollection {
 
   $sth = $dbh->prepare("DELETE FROM collections WHERE colId = ?");
   $sth->execute( $colId ) or return ( 0, 4, $sth->errstr() );
-  $sth->finish;
 
   return 1;
 }
 
-=item GetCollections
+=head2 GetCollections
+
  $collections = GetCollections();
  Returns data about all collections
 
@@ -187,7 +193,9 @@ sub DeleteCollection {
   On Failure:
    $errorCode: Code for reason of failure, good for translating errors in templates
    $errorMessage: English description of error
+
 =cut
+
 sub GetCollections {
 
   my $dbh = C4::Context->dbh;
@@ -200,13 +208,13 @@ sub GetCollections {
     push( @results , $row );
   }
   
-  $sth->finish;
-  
   return \@results;
 }
 
-=item GetItemsInCollection
+=head2 GetItemsInCollection
+
  ( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId );
+
  Returns information about the items in the given collection
  
  Input:
@@ -217,7 +225,9 @@ sub GetCollections {
    $success: 1 if all database operations were successful, 0 otherwise
    $errorCode: Code for reason of failure, good for translating errors in templates
    $errorMessage: English description of error
+
 =cut
+
 sub GetItemsInCollection {
   my ( $colId ) = @_;
 
@@ -244,20 +254,22 @@ sub GetItemsInCollection {
     push( @results , $row );
   }
   
-  $sth->finish;
-  
   return \@results;
 }
 
-=item GetCollection
+=head2 GetCollection
+
  ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $colId );
- Returns information about a collection
+
+Returns information about a collection
 
  Input:
    $colId: Id of the collection
  Output:
    $colId, $colTitle, $colDesc, $colBranchcode
+
 =cut
+
 sub GetCollection {
   my ( $colId ) = @_;
 
@@ -269,8 +281,6 @@ sub GetCollection {
     
   my $row = $sth->fetchrow_hashref;
   
-  $sth->finish;
-  
   return (
       $$row{'colId'},
       $$row{'colTitle'},
@@ -280,9 +290,11 @@ sub GetCollection {
     
 }
 
-=item AddItemToCollection
+=head2 AddItemToCollection
+
  ( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber );
- Adds an item to a rotating collection.
+
+Adds an item to a rotating collection.
 
  Input:
    $colId: Collection to add the item to.
@@ -291,7 +303,9 @@ sub GetCollection {
    $success: 1 if all database operations were successful, 0 otherwise
    $errorCode: Code for reason of failure, good for translating errors in templates
    $errorMessage: English description of error
+
 =cut
+
 sub AddItemToCollection {
   my ( $colId, $itemnumber ) = @_;
 
@@ -315,15 +329,16 @@ sub AddItemToCollection {
   $sth = $dbh->prepare("INSERT INTO collections_tracking ( ctId, colId, itemnumber ) 
                         VALUES ( NULL, ?, ? )");
   $sth->execute( $colId, $itemnumber ) or return ( 0, 3, $sth->errstr() );
-  $sth->finish;
 
   return 1;
   
 }
 
-=item  RemoveItemFromCollection
+=head2  RemoveItemFromCollection
+
  ( $success, $errorcode, $errormessage ) = RemoveItemFromCollection( $colId, $itemnumber );
- Removes an item to a collection
+
+Removes an item to a collection
 
  Input:
    $colId: Collection to add the item to.
@@ -333,7 +348,9 @@ sub AddItemToCollection {
    $success: 1 if all database operations were successful, 0 otherwise
    $errorCode: Code for reason of failure, good for translating errors in templates
    $errorMessage: English description of error
+
 =cut
+
 sub RemoveItemFromCollection {
   my ( $colId, $itemnumber ) = @_;
 
@@ -352,14 +369,15 @@ sub RemoveItemFromCollection {
   $sth = $dbh->prepare("DELETE FROM collections_tracking 
                         WHERE itemnumber = ?");
   $sth->execute( $itemnumber ) or return ( 0, 3, $sth->errstr() );
-  $sth->finish;
 
   return 1;
 }
 
-=item TransferCollection
+=head2 TransferCollection
+
  ( $success, $errorcode, $errormessage ) = TransferCollection( $colId, $colBranchcode );
- Transfers a collection to another branch
+
+Transfers a collection to another branch
 
  Input:
    $colId: id of the collection to be updated
@@ -369,7 +387,9 @@ sub RemoveItemFromCollection {
    $success: 1 if all database operations were successful, 0 otherwise
    $errorCode: Code for reason of failure, good for translating errors in templates
    $errorMessage: English description of error
+
 =cut
+
 sub TransferCollection {
   my ( $colId, $colBranchcode ) = @_;
 
@@ -389,7 +409,6 @@ sub TransferCollection {
                         colBranchcode = ? 
                         WHERE colId = ?");
   $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() );
-  $sth->finish;
   
   $sth = $dbh->prepare("SELECT barcode FROM items, collections_tracking 
                         WHERE items.itemnumber = collections_tracking.itemnumber
@@ -399,17 +418,47 @@ sub TransferCollection {
   while ( my $item = $sth->fetchrow_hashref ) {
     my ( $dotransfer, $messages, $iteminformation ) = transferbook( $colBranchcode, $item->{'barcode'}, my $ignore_reserves = 1);
   }
-  
 
-  
   return 1;
   
 }
 
+=head2 GetCollectionItemBranches
+
+  my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
+
+=cut
+
+sub GetCollectionItemBranches {
+  my ( $itemnumber ) = @_;
+
+  if ( ! $itemnumber ) {
+    return;
+  }
+
+  my $dbh = C4::Context->dbh;
+
+  my ( $sth, @results );
+  $sth = $dbh->prepare("SELECT holdingbranch, colBranchcode FROM items, collections, collections_tracking 
+                        WHERE items.itemnumber = collections_tracking.itemnumber
+                        AND collections.colId = collections_tracking.colId
+                        AND items.itemnumber = ?");
+  $sth->execute( $itemnumber );
+    
+  my $row = $sth->fetchrow_hashref;
+  
+  return (
+      $$row{'holdingbranch'},
+      $$row{'colBranchcode'},
+  );  
+}
+
+=head2 isItemInThisCollection
+
+  $inCollection = isItemInThisCollection( $itemnumber, $colId );
+
+=cut
 
-=item isItemInThisCollection
-$inCollection = isItemInThisCollection( $itemnumber, $colId );
-=cut            
 sub isItemInThisCollection {
   my ( $itemnumber, $colId ) = @_;
   
@@ -423,9 +472,12 @@ sub isItemInThisCollection {
   return $$row{'inCollection'};
 }
 
-=item isItemInAnyCollection
+=head2 isItemInAnyCollection
+
 $inCollection = isItemInAnyCollection( $itemnumber );
+
 =cut
+
 sub isItemInAnyCollection {
   my ( $itemnumber ) = @_;
   
@@ -436,9 +488,7 @@ sub isItemInAnyCollection {
       
   my $row = $sth->fetchrow_hashref;
         
-  my $itemnumber = $$row{'itemnumber'};
-  $sth->finish;
-            
+  $itemnumber = $row->{itemnumber};
   if ( $itemnumber ) {
     return 1;
   } else {
@@ -450,8 +500,6 @@ sub isItemInAnyCollection {
 
 __END__
 
-=back
-
 =head1 AUTHOR
 
 Kyle Hall <kylemhall@gmail.com>