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

(-)a/C4/RotatingCollections.pm (-46 lines)
Lines 48-54 BEGIN { Link Here
48
    require Exporter;
48
    require Exporter;
49
    @ISA    = qw( Exporter );
49
    @ISA    = qw( Exporter );
50
    @EXPORT = qw(
50
    @EXPORT = qw(
51
      CreateCollection
52
      UpdateCollection
51
      UpdateCollection
53
52
54
      GetItemsInCollection
53
      GetItemsInCollection
Lines 61-111 BEGIN { Link Here
61
    );
60
    );
62
}
61
}
63
62
64
=head2  CreateCollection
65
 ( $success, $errorcode, $errormessage ) = CreateCollection( $title, $description );
66
 Creates a new collection
67
68
 Input:
69
   $title: short description of the club or service
70
   $description: long description of the club or service
71
72
 Output:
73
   $success: 1 if all database operations were successful, 0 otherwise
74
   $errorCode: Code for reason of failure, good for translating errors in templates
75
   $errorMessage: English description of error
76
77
=cut
78
79
sub CreateCollection {
80
    my ( $title, $description ) = @_;
81
82
    my $schema = Koha::Database->new()->schema();
83
    my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title });
84
85
    ## Check for all necessary parameters
86
    if ( !$title ) {
87
        return ( 0, 1, "NO_TITLE" );
88
    } elsif ( $duplicate_titles ) {
89
        return ( 0, 2, "DUPLICATE_TITLE" );
90
    }
91
92
    $description ||= q{};
93
94
    my $success = 1;
95
96
    my $dbh = C4::Context->dbh;
97
98
    my $sth;
99
    $sth = $dbh->prepare(
100
        "INSERT INTO collections ( colId, colTitle, colDesc )
101
                        VALUES ( NULL, ?, ? )"
102
    );
103
    $sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() );
104
105
    return 1;
106
107
}
108
109
=head2 UpdateCollection
63
=head2 UpdateCollection
110
64
111
 ( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description );
65
 ( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description );
(-)a/rotating_collections/editCollections.pl (-16 / +15 lines)
Lines 47-67 if ( $action eq 'create' ) { Link Here
47
    my $title       = $query->param('title');
47
    my $title       = $query->param('title');
48
    my $description = $query->param('description');
48
    my $description = $query->param('description');
49
49
50
    my ( $createdSuccessfully, $errorCode, $errorMessage ) =
50
    my $collection = Koha::RotatingCollection->new(
51
      CreateCollection( $title, $description );
51
        {   colTitle => $title,
52
52
            colDesc  => $description,
53
    $template->param(
53
        }
54
        previousActionCreate => 1,
55
        createdTitle         => $title,
56
    );
54
    );
57
55
58
    if ($createdSuccessfully) {
56
    eval { $collection->store; };
59
        $template->param( createSuccess => 1 );
57
60
    }
58
    if ($@) {
61
    else {
59
        push @messages, { type => 'error', code => 'error_on_insert' };
62
        $template->param( createFailure  => 1 );
60
    } else {
63
        $template->param( failureMessage => $errorMessage );
61
        push @messages, { type => 'message', code => 'success_on_insert' };
64
    }
62
    }
63
64
    $action = "list";
65
65
} elsif ( $action eq 'delete' ) { # Delete collection
66
} elsif ( $action eq 'delete' ) { # Delete collection
66
    my $colId = $query->param('colId');
67
    my $colId = $query->param('colId');
67
    my $collection = Koha::RotatingCollections->find($colId);
68
    my $collection = Koha::RotatingCollections->find($colId);
Lines 72-82 if ( $action eq 'create' ) { Link Here
72
    } else {
73
    } else {
73
        push @messages, { type => 'message', code => 'success_on_delete' };
74
        push @messages, { type => 'message', code => 'success_on_delete' };
74
    }
75
    }
76
75
    $action = "list";
77
    $action = "list";
76
}
77
78
78
## Edit a club or service: grab data, put in form.
79
} elsif ( $action eq 'edit' ) { # Edit page of collection
79
elsif ( $action eq 'edit' ) {
80
    my $collection = Koha::RotatingCollections->find($query->param('colId'));
80
    my $collection = Koha::RotatingCollections->find($query->param('colId'));
81
81
82
    $template->param(
82
    $template->param(
83
- 

Return to bug 18606