@@ -, +, @@ collections from having the same title --- C4/RotatingCollections.pm | 12 ++++++++++++ .../prog/en/modules/rotating_collections/editCollections.tt | 4 ++++ 2 files changed, 16 insertions(+) --- a/C4/RotatingCollections.pm +++ a/C4/RotatingCollections.pm @@ -27,6 +27,7 @@ use Modern::Perl; use C4::Context; use C4::Circulation; use C4::Reserves qw(CheckReserves); +use Koha::Database; use DBI; @@ -84,9 +85,14 @@ BEGIN { sub CreateCollection { my ( $title, $description ) = @_; + my $schema = Koha::Database->new()->schema(); + my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title }); + ## Check for all neccessary parameters if ( !$title ) { return ( 0, 1, "NO_TITLE" ); + } elsif ( $duplicate_titles ) { + return ( 0, 2, "DUPLICATE_TITLE" ); } $description ||= q{}; @@ -127,6 +133,9 @@ Updates a collection sub UpdateCollection { my ( $colId, $title, $description ) = @_; + my $schema = Koha::Database->new()->schema(); + my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title, -not => { colId => $colId } }); + ## Check for all neccessary parameters if ( !$colId ) { return ( 0, 1, "NO_ID" ); @@ -134,6 +143,9 @@ sub UpdateCollection { if ( !$title ) { return ( 0, 2, "NO_TITLE" ); } + if ( $duplicate_titles ) { + return ( 0, 3, "DUPLICATE_TITLE" ); + } my $dbh = C4::Context->dbh; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt @@ -37,6 +37,8 @@

[% IF failureMessage == "NO_TITLE" %] No title entered. + [% ELSIF failureMessage == "DUPLICATE_TITLE" %] + Title already in use. [% ELSIF failureMessage == "NO_DESCRIPTION" %] No description entered. [% ELSE %] @@ -70,6 +72,8 @@

[% IF failureMessage == "NO_ID" %] No collection id given. + [% ELSIF failureMessage == "DUPLICATE_TITLE" %] + Title already in use. [% ELSE %] [% failureMessage %] [% END %] --