#
# 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 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 3 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.
+# 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.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use C4::Context;
use C4::Circulation;
use C4::Reserves qw(CheckReserves);
+use Koha::Database;
use DBI;
use Data::Dumper;
-use vars qw($VERSION @ISA @EXPORT);
+use vars qw(@ISA @EXPORT);
-# set the version for version checking
-$VERSION = 3.07.00.049;
=head1 NAME
sub CreateCollection {
my ( $title, $description ) = @_;
- ## Check for all neccessary parameters
+ my $schema = Koha::Database->new()->schema();
+ my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title });
+
+ ## Check for all necessary parameters
if ( !$title ) {
return ( 0, 1, "NO_TITLE" );
+ } elsif ( $duplicate_titles ) {
+ return ( 0, 2, "DUPLICATE_TITLE" );
}
$description ||= q{};
sub UpdateCollection {
my ( $colId, $title, $description ) = @_;
- ## Check for all neccessary parameters
+ my $schema = Koha::Database->new()->schema();
+ my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title, -not => { colId => $colId } });
+
+ ## Check for all necessary parameters
if ( !$colId ) {
return ( 0, 1, "NO_ID" );
}
if ( !$title ) {
return ( 0, 2, "NO_TITLE" );
}
+ if ( $duplicate_titles ) {
+ return ( 0, 3, "DUPLICATE_TITLE" );
+ }
my $dbh = C4::Context->dbh;
Deletes a collection of the given id
Input:
- $colId : id of the Archtype to be deleted
+ $colId : id of the Archetype to be deleted
Output:
$success: 1 if all database operations were successful, 0 otherwise
sub DeleteCollection {
my ($colId) = @_;
- ## Paramter check
+ ## Parameter check
if ( !$colId ) {
return ( 0, 1, "NO_ID" );
}
sub GetItemsInCollection {
my ($colId) = @_;
- ## Paramter check
+ ## Parameter check
if ( !$colId ) {
return ( 0, 0, 1, "NO_ID" );
}
sub AddItemToCollection {
my ( $colId, $itemnumber ) = @_;
- ## Check for all neccessary parameters
+ ## Check for all necessary parameters
if ( !$colId ) {
return ( 0, 1, "NO_ID" );
}
sub RemoveItemFromCollection {
my ( $colId, $itemnumber ) = @_;
- ## Check for all neccessary parameters
+ ## Check for all necessary parameters
if ( !$itemnumber ) {
return ( 0, 2, "NO_ITEM" );
}
sub TransferCollection {
my ( $colId, $colBranchcode ) = @_;
- ## Check for all neccessary parameters
+ ## Check for all necessary parameters
if ( !$colId ) {
return ( 0, 1, "NO_ID" );
}
my @results;
while ( my $item = $sth->fetchrow_hashref ) {
my ($status) = CheckReserves( $item->{itemnumber} );
- transferbook( $colBranchcode, $item->{barcode}, my $ignore_reserves = 1 ) unless ( $status eq 'Waiting' );
+ my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} );
+ C4::Circulation::transferbook( $colBranchcode, $item->{barcode}, my $ignore_reserves = 1 ) unless ( $status eq 'Waiting' || @transfers );
}
return 1;