@@ -, +, @@ --- C4/RotatingCollections.pm | 55 --------------------------------- rotating_collections/editCollections.pl | 35 ++++++++++----------- 2 files changed, 17 insertions(+), 73 deletions(-) --- a/C4/RotatingCollections.pm +++ a/C4/RotatingCollections.pm @@ -48,8 +48,6 @@ BEGIN { require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( - UpdateCollection - GetItemsInCollection AddItemToCollection @@ -60,59 +58,6 @@ BEGIN { ); } -=head2 UpdateCollection - - ( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description ); - -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 - -=cut - -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 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; - - $description ||= q{}; - - my $sth; - $sth = $dbh->prepare( - "UPDATE collections - SET - colTitle = ?, colDesc = ? - WHERE colId = ?" - ); - $sth->execute( $title, $description, $colId ) - or return ( 0, 4, $sth->errstr() ); - - return 1; - -} - =head2 GetItemsInCollection ( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId ); --- a/rotating_collections/editCollections.pl +++ a/rotating_collections/editCollections.pl @@ -81,33 +81,32 @@ if ( $action eq 'create' ) { $template->param( previousActionEdit => 1, - editColId => $collection->{colId}, - editColTitle => $collection->{colTitle}, - editColDescription => $collection->{colDesc}, + editColId => $collection->colId, + editColTitle => $collection->colTitle, + editColDescription => $collection->colDesc, ); -} -# Update a Club or Service -elsif ( $action eq 'update' ) { +} elsif ( $action eq 'update' ) { # Update collection my $colId = $query->param('colId'); my $title = $query->param('title'); my $description = $query->param('description'); - my ( $createdSuccessfully, $errorCode, $errorMessage ) = - UpdateCollection( $colId, $title, $description ); + if ($colId) { + my $collection = Koha::RotatingCollections->find($colId); + $collection->colTitle($title); + $collection->colDesc($description); - $template->param( - previousActionUpdate => 1, - updatedTitle => $title, - ); + eval { $collection->store; }; - if ($createdSuccessfully) { - $template->param( updateSuccess => 1 ); - } - else { - $template->param( updateFailure => 1 ); - $template->param( failureMessage => $errorMessage ); + if ($@) { + push @messages, { type => 'error', code => 'error_on_update' }; + } else { + push @messages, { type => 'message', code => 'success_on_update' }; + } + + $action = "list"; } + } $template->param( --