@@ -, +, @@ --- C4/RotatingCollections.pm | 46 --------------------------------- rotating_collections/editCollections.pl | 30 ++++++++++----------- 2 files changed, 15 insertions(+), 61 deletions(-) --- a/C4/RotatingCollections.pm +++ a/C4/RotatingCollections.pm @@ -48,7 +48,6 @@ BEGIN { require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( - CreateCollection UpdateCollection GetItemsInCollection @@ -61,51 +60,6 @@ BEGIN { ); } -=head2 CreateCollection - ( $success, $errorcode, $errormessage ) = CreateCollection( $title, $description ); - 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 - -=cut - -sub CreateCollection { - my ( $title, $description ) = @_; - - 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{}; - - 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() ); - - return 1; - -} - =head2 UpdateCollection ( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description ); --- a/rotating_collections/editCollections.pl +++ a/rotating_collections/editCollections.pl @@ -47,21 +47,22 @@ if ( $action eq 'create' ) { my $title = $query->param('title'); my $description = $query->param('description'); - my ( $createdSuccessfully, $errorCode, $errorMessage ) = - CreateCollection( $title, $description ); - - $template->param( - previousActionCreate => 1, - createdTitle => $title, + my $collection = Koha::RotatingCollection->new( + { colTitle => $title, + colDesc => $description, + } ); - if ($createdSuccessfully) { - $template->param( createSuccess => 1 ); - } - else { - $template->param( createFailure => 1 ); - $template->param( failureMessage => $errorMessage ); + eval { $collection->store; }; + + if ($@) { + push @messages, { type => 'error', code => 'error_on_insert' }; + } else { + push @messages, { type => 'message', code => 'success_on_insert' }; } + + $action = "list"; + } elsif ( $action eq 'delete' ) { # Delete collection my $colId = $query->param('colId'); my $collection = Koha::RotatingCollections->find($colId); @@ -72,11 +73,10 @@ if ( $action eq 'create' ) { } else { push @messages, { type => 'message', code => 'success_on_delete' }; } + $action = "list"; -} -## Edit a club or service: grab data, put in form. -elsif ( $action eq 'edit' ) { +} elsif ( $action eq 'edit' ) { # Edit page of collection my $collection = Koha::RotatingCollections->find($query->param('colId')); $template->param( --