View | Details | Raw Unified | Return to bug 18606
Collapse All | Expand All

(-)a/C4/RotatingCollections.pm (-55 lines)
Lines 48-55 BEGIN { Link Here
48
    require Exporter;
48
    require Exporter;
49
    @ISA    = qw( Exporter );
49
    @ISA    = qw( Exporter );
50
    @EXPORT = qw(
50
    @EXPORT = qw(
51
      UpdateCollection
52
53
      GetItemsInCollection
51
      GetItemsInCollection
54
52
55
      AddItemToCollection
53
      AddItemToCollection
Lines 60-118 BEGIN { Link Here
60
    );
58
    );
61
}
59
}
62
60
63
=head2 UpdateCollection
64
65
 ( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description );
66
67
Updates a collection
68
69
 Input:
70
   $colId: id of the collection to be updated
71
   $title: short description of the club or service
72
   $description: long description of the club or service
73
74
 Output:
75
   $success: 1 if all database operations were successful, 0 otherwise
76
   $errorCode: Code for reason of failure, good for translating errors in templates
77
   $errorMessage: English description of error
78
79
=cut
80
81
sub UpdateCollection {
82
    my ( $colId, $title, $description ) = @_;
83
84
    my $schema = Koha::Database->new()->schema();
85
    my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title,  -not => { colId => $colId } });
86
87
    ## Check for all necessary parameters
88
    if ( !$colId ) {
89
        return ( 0, 1, "NO_ID" );
90
    }
91
    if ( !$title ) {
92
        return ( 0, 2, "NO_TITLE" );
93
    }
94
    if ( $duplicate_titles ) {
95
        return ( 0, 3, "DUPLICATE_TITLE" );
96
    }
97
98
    my $dbh = C4::Context->dbh;
99
100
    $description ||= q{};
101
102
    my $sth;
103
    $sth = $dbh->prepare(
104
        "UPDATE collections
105
                        SET 
106
                        colTitle = ?, colDesc = ? 
107
                        WHERE colId = ?"
108
    );
109
    $sth->execute( $title, $description, $colId )
110
      or return ( 0, 4, $sth->errstr() );
111
112
    return 1;
113
114
}
115
116
=head2 GetItemsInCollection
61
=head2 GetItemsInCollection
117
62
118
 ( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId );
63
 ( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId );
(-)a/rotating_collections/editCollections.pl (-19 / +17 lines)
Lines 81-113 if ( $action eq 'create' ) { Link Here
81
81
82
    $template->param(
82
    $template->param(
83
        previousActionEdit => 1,
83
        previousActionEdit => 1,
84
        editColId          => $collection->{colId},
84
        editColId          => $collection->colId,
85
        editColTitle       => $collection->{colTitle},
85
        editColTitle       => $collection->colTitle,
86
        editColDescription => $collection->{colDesc},
86
        editColDescription => $collection->colDesc,
87
    );
87
    );
88
}
89
88
90
# Update a Club or Service
89
} elsif ( $action eq 'update' ) { # Update collection
91
elsif ( $action eq 'update' ) {
92
    my $colId       = $query->param('colId');
90
    my $colId       = $query->param('colId');
93
    my $title       = $query->param('title');
91
    my $title       = $query->param('title');
94
    my $description = $query->param('description');
92
    my $description = $query->param('description');
95
93
96
    my ( $createdSuccessfully, $errorCode, $errorMessage ) =
94
    if ($colId) {
97
      UpdateCollection( $colId, $title, $description );
95
        my $collection = Koha::RotatingCollections->find($colId);
96
        $collection->colTitle($title);
97
        $collection->colDesc($description);
98
98
99
    $template->param(
99
        eval { $collection->store; };
100
        previousActionUpdate => 1,
101
        updatedTitle         => $title,
102
    );
103
100
104
    if ($createdSuccessfully) {
101
        if ($@) {
105
        $template->param( updateSuccess => 1 );
102
            push @messages, { type => 'error', code => 'error_on_update' };
106
    }
103
        } else {
107
    else {
104
            push @messages, { type => 'message', code => 'success_on_update' };
108
        $template->param( updateFailure  => 1 );
105
        }
109
        $template->param( failureMessage => $errorMessage );
106
107
        $action = "list";
110
    }
108
    }
109
111
}
110
}
112
111
113
$template->param(
112
$template->param(
114
- 

Return to bug 18606