[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/C4 RotatingCollections.pm [dev_week]
From: |
Kyle Hall |
Subject: |
[Koha-cvs] koha/C4 RotatingCollections.pm [dev_week] |
Date: |
Mon, 14 May 2007 15:17:06 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: dev_week
Changes by: Kyle Hall <kylemhall> 07/05/14 15:17:06
Added files:
C4 : RotatingCollections.pm
Log message:
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/RotatingCollections.pm?cvsroot=koha&only_with_tag=dev_week&rev=1.1.2.1
Patches:
Index: RotatingCollections.pm
===================================================================
RCS file: RotatingCollections.pm
diff -N RotatingCollections.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RotatingCollections.pm 14 May 2007 15:17:06 -0000 1.1.2.1
@@ -0,0 +1,467 @@
+package C4::RotatingCollections;
+
+# $Id: RotatingCollections.pm,v 0.1 2007/04/20 kylemhall
+
+# This package is inteded to keep track of what library
+# Items of a certain collection should be at.
+
+# Copyright 2007 Kyle Hall
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# 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
+
+use strict;
+
+require Exporter;
+
+use C4::Context;
+
+use DBI;
+
+use Data::Dumper;
+
+use vars qw($VERSION @ISA @EXPORT);
+
+# set the version for version checking
+$VERSION = 0.01;
+
+=head1 NAME
+
+C4::RotatingCollections - Functions for managing rotating collections
+
+=head1 FUNCTIONS
+
+=over 2
+
+=cut
+
address@hidden = qw( Exporter );
address@hidden = qw(
+ CreateCollection
+ UpdateCollection
+ DeleteCollection
+
+ GetItemsInCollection
+
+ GetCollection
+ GetCollections
+
+ AddItemToCollection
+ RemoveItemFromCollection
+ TransferCollection
+
+ GetCollectionItemBranches
+
+ getItemnumberByBarcode
+);
+
+## function CreateCollection
+## Creates a new collection
+## Input:
+## $title: short description of the club or service
+## $description: long description of the club or service
+## Output:
+## $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
+sub CreateCollection {
+ my ( $title, $description ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $title ) {
+ return ( 0, 1, "No Title Given" );
+ }
+ if ( ! $description ) {
+ return ( 0, 2, "No Description Given" );
+ }
+
+ my $success = 1;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $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;
+
+}
+
+## function UpdateCollection
+## Updates a collection
+## Input:
+## $colId: id of the collection to be updated
+## $title: short description of the club or service
+## $description: long description of the club or service
+## Output:
+## $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
+sub UpdateCollection {
+ my ( $colId, $title, $description ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $colId ) {
+ return ( 0, 1, "No Id Given" );
+ }
+ if ( ! $title ) {
+ return ( 0, 2, "No Title Given" );
+ }
+ if ( ! $description ) {
+ return ( 0, 3, "No Description Given" );
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $sth = $dbh->prepare("UPDATE collections
+ SET
+ colTitle = ?, colDesc = ?
+ WHERE colId = ?");
+ $sth->execute( $title, $description, $colId ) or return ( 0, 4,
$sth->errstr() );
+ $sth->finish;
+
+ return 1;
+
+}
+
+## function DeleteCollection
+## Deletes a collection of the given id
+## Input:
+## $colId : id of the Archtype to be deleted
+## Output:
+## $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
+sub DeleteCollection {
+ my ( $colId ) = @_;
+
+ ## Paramter check
+ if ( ! $colId ) {
+ return ( 0, 1, "No Collection Id Given" );;
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+
+ $sth = $dbh->prepare("DELETE FROM collections WHERE colId = ?");
+ $sth->execute( $colId ) or return ( 0, 4, $sth->errstr() );
+ $sth->finish;
+
+ return 1;
+}
+
+## function GetCollections
+## Returns data about all collections
+## Input:
+## None
+## Output:
+## On Success:
+## $results: Reference to an array of associated arrays
+## On Failure:
+## $errorCode: Code for reason of failure, good for translating errors in
templates
+## $errorMessage: English description of error
+sub GetCollections {
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT * FROM collections");
+ $sth->execute() or return ( 1, $sth->errstr() );
+
+ my @results;
+ while ( my $row = $sth->fetchrow_hashref ) {
+ push( @results , $row );
+ }
+
+ $sth->finish;
+
+ return address@hidden;
+}
+
+## function GetItemsInCollection
+## Returns information about the items in the given collection
+## Input:
+## $colId: The id of the collection
+## Output:
+## $results: Reference to an array of associated arrays
+## $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
+sub GetItemsInCollection {
+ my ( $colId ) = @_;
+
+ ## Paramter check
+ if ( ! $colId ) {
+ return ( 0, 0, 1, "No Collection Id Given" );;
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT
+ biblio.title,
+ items.itemcallnumber,
+ items.barcode
+ FROM collections, collectionsTracking, items, biblio
+ WHERE collections.colId = collectionsTracking.colId
+ AND collectionsTracking.itemnumber =
items.itemnumber
+ AND items.biblionumber = biblio.biblionumber
+ AND collections.colId = ?");
+ $sth->execute( $colId ) or return ( 0, 0, 2, $sth->errstr() );
+
+ my @results;
+ while ( my $row = $sth->fetchrow_hashref ) {
+ push( @results , $row );
+ }
+
+ $sth->finish;
+
+ return address@hidden;
+}
+
+## function GetCollection
+## Returns information about a collection
+## Input:
+## $colId: Id of the collection
+## Output:
+## $colId, $colTitle, $colDesc, $colBranchcode
+
+sub GetCollection {
+ my ( $colId ) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my ( $sth, @results );
+ $sth = $dbh->prepare("SELECT * FROM collections WHERE colId = ?");
+ $sth->execute( $colId ) or return 0;
+
+ my $row = $sth->fetchrow_hashref;
+
+ $sth->finish;
+
+ return (
+ $$row{'colId'},
+ $$row{'colTitle'},
+ $$row{'colDesc'},
+ $$row{'colBranchcode'}
+ );
+
+}
+
+## function AddItemToCollection
+## Adds an item to a collection
+## Input:
+## $colId: Collection to add the item to.
+## $itemnumber: Item to be added to the collection
+## Output:
+## $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
+sub AddItemToCollection {
+ my ( $colId, $itemnumber ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $colId ) {
+ return ( 0, 1, "No Collection Given" );
+ }
+ if ( ! $itemnumber ) {
+ return ( 0, 2, "No Itemnumber Given" );
+ }
+
+ if ( isItemInThisCollection( $itemnumber, $colId ) ) {
+ return ( 0, 2, "Item is already in the collection!" );
+ } elsif ( isItemInAnyCollection( $itemnumber ) ) {
+ return ( 0, 3, "Item is already in a different collection!" );
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $sth = $dbh->prepare("INSERT INTO collectionsTracking ( ctId, colId,
itemnumber )
+ VALUES ( NULL, ?, ? )");
+ $sth->execute( $colId, $itemnumber ) or return ( 0, 3, $sth->errstr() );
+ $sth->finish;
+
+ return 1;
+
+}
+
+## function RemoveItemFromCollection
+## Removes an item to a collection
+## Input:
+## $colId: Collection to add the item to.
+## $itemnumber: Item to be removed from collection
+## Output:
+## $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
+sub RemoveItemFromCollection {
+ my ( $colId, $itemnumber ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $itemnumber ) {
+ return ( 0, 2, "No Itemnumber Given" );
+ }
+
+ if ( ! isItemInThisCollection( $itemnumber, $colId ) ) {
+ return ( 0, 2, "Item is not in the collection!" );
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $sth = $dbh->prepare("DELETE FROM collectionsTracking
+ WHERE itemnumber = ?");
+ $sth->execute( $itemnumber ) or return ( 0, 3, $sth->errstr() );
+ $sth->finish;
+
+ return 1;
+}
+
+## function TransferCollection
+## Transfers a collection to another branch
+## Input:
+## $colId: id of the collection to be updated
+## $colBranchcode: branch where collection is moving to
+## Output:
+## $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
+sub TransferCollection {
+ my ( $colId, $colBranchcode ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $colId ) {
+ return ( 0, 1, "No Id Given" );
+ }
+ if ( ! $colBranchcode ) {
+ return ( 0, 2, "No Branchcode Given" );
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $sth = $dbh->prepare("UPDATE collections
+ SET
+ colBranchcode = ?
+ WHERE colId = ?");
+ $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() );
+ $sth->finish;
+
+ return 1;
+
+}
+
+## function GetCollectionItemBranches
+## Input:
+## $itemnumber: itemnumber to look up
+## Output:
+## $collectionBranch: Branch where this item should be
+## $holdingBranch: Branch where the item currently is
+## On Error:
+## $success: 0
+## $errorCode: Code for reason of failure, good for translating errors in
templates
+## $errorMessage: English description of error
+
+sub GetCollectionItemBranches {
+ my ( $itemnumber ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $itemnumber ) {
+ return ( 0, 1, "No Itemnumber Given" );
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my ( $sth, @results );
+ $sth = $dbh->prepare("SELECT holdingbranch, colBranchcode FROM items,
collections, collectionsTracking
+ WHERE items.itemnumber = collectionsTracking.itemnumber
+ AND collections.colId = collectionsTracking.colId
+ AND items.itemnumber = ?");
+ $sth->execute( $itemnumber ) or return ( 0, 2, $sth->errstr() );
+
+ my $row = $sth->fetchrow_hashref;
+
+ $sth->finish;
+
+ return (
+ $$row{'holdingbranch'},
+ $$row{'colBranchcode'},
+ );
+
+}
+
+sub getItemnumberByBarcode {
+ my ( $barcode ) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE barcode = ?");
+ $sth->execute( $barcode ) or return( 0 );
+
+ my $row = $sth->fetchrow_hashref;
+
+ my $itemnumber = $$row{'itemnumber'};
+ $sth->finish;
+
+ return( $itemnumber );
+}
+
+sub isItemInThisCollection {
+ my ( $itemnumber, $colId ) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT COUNT(*) as inCollection FROM
collectionsTracking WHERE itemnumber = ? AND colId = ?");
+ $sth->execute( $itemnumber, $colId ) or return( 0 );
+
+ my $row = $sth->fetchrow_hashref;
+
+ return $$row{'inCollection'};
+}
+
+sub isItemInAnyCollection {
+ my ( $itemnumber ) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT itemnumber FROM collectionsTracking WHERE
itemnumber = ?");
+ $sth->execute( $itemnumber ) or return( 0 );
+
+ my $row = $sth->fetchrow_hashref;
+
+ my $itemnumber = $$row{'itemnumber'};
+ $sth->finish;
+
+ if ( $itemnumber ) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+1;
+
+__END__
+
+=back
+
+=head1 AUTHOR
+
+Kyle Hall <address@hidden>
+
+=cut
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Koha-cvs] koha/C4 RotatingCollections.pm [dev_week],
Kyle Hall <=