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

(-)a/C4/RotatingCollections.pm (-42 lines)
Lines 48-99 BEGIN { Link Here
48
    require Exporter;
48
    require Exporter;
49
    @ISA    = qw( Exporter );
49
    @ISA    = qw( Exporter );
50
    @EXPORT = qw(
50
    @EXPORT = qw(
51
      RemoveItemFromCollection
52
      TransferCollection
51
      TransferCollection
53
    );
52
    );
54
}
53
}
55
54
56
=head2  RemoveItemFromCollection
57
58
 ( $success, $errorcode, $errormessage ) = RemoveItemFromCollection( $colId, $itemnumber );
59
60
Removes an item to a collection
61
62
 Input:
63
   $colId: Collection to add the item to.
64
   $itemnumber: Item to be removed from collection
65
66
 Output:
67
   $success: 1 if all database operations were successful, 0 otherwise
68
   $errorCode: Code for reason of failure, good for translating errors in templates
69
   $errorMessage: English description of error
70
71
=cut
72
73
sub RemoveItemFromCollection {
74
    my ( $colId, $itemnumber ) = @_;
75
76
    ## Check for all necessary parameters
77
    if ( !$itemnumber ) {
78
        return ( 0, 2, "NO_ITEM" );
79
    }
80
81
    if ( !isItemInThisCollection( $itemnumber, $colId ) ) {
82
        return ( 0, 2, "NOT_IN_COLLECTION" );
83
    }
84
85
    my $dbh = C4::Context->dbh;
86
87
    my $sth;
88
    $sth = $dbh->prepare(
89
        "DELETE FROM collections_tracking
90
                        WHERE itemnumber = ?"
91
    );
92
    $sth->execute($itemnumber) or return ( 0, 3, $sth->errstr() );
93
94
    return 1;
95
}
96
97
=head2 TransferCollection
55
=head2 TransferCollection
98
56
99
 ( $success, $errorcode, $errormessage ) = TransferCollection( $colId, $colBranchcode );
57
 ( $success, $errorcode, $errormessage ) = TransferCollection( $colId, $colBranchcode );
(-)a/Koha/RotatingCollection.pm (+26 lines)
Lines 84-89 sub add_item { Link Here
84
    return $col_tracking;
84
    return $col_tracking;
85
}
85
}
86
86
87
=head3 remove_item
88
89
$collection->remove_item( $itemnumber )
90
91
throws
92
    Koha::Exceptions::MissingParameter
93
    Koha::Exceptions::ObjectNotFound
94
95
=cut
96
97
sub remove_item {
98
    my ( $self, $itemnumber ) = @_;
99
100
    Koha::Exceptions::MissingParameter->throw if not defined $itemnumber;
101
102
    my $collection_tracking = Koha::RotatingCollection::Trackings->find(
103
        {
104
            itemnumber => $itemnumber,
105
            colId      => $self->colId,
106
        } );
107
108
    Koha::Exceptions::ObjectNotFound->throw if not defined $collection_tracking;
109
110
    return $collection_tracking->delete;
111
}
112
87
=head3 type
113
=head3 type
88
114
89
=cut
115
=cut
(-)a/rotating_collections/addItems.pl (-20 / +9 lines)
Lines 64-92 if ( $query->param('action') eq 'addItem' ) { Link Here
64
        } else {
64
        } else {
65
            push @messages, { code => 'success_adding_item' };
65
            push @messages, { code => 'success_adding_item' };
66
        }
66
        }
67
67
    } else {
68
        $template->param(
69
            previousActionAdd => 1,
70
        );
71
    }
72
    else {
73
        ## Remove the given item from the collection
68
        ## Remove the given item from the collection
74
        ( $success, $errorCode, $errorMessage ) =
69
        my $deleted = eval { $collection->remove_item( $itemnumber ) };
75
          RemoveItemFromCollection( $colId, $itemnumber );
76
70
77
        $template->param(
71
        if ( $@ or not $deleted ) {
78
            previousActionRemove => 1,
72
            push @errors, { code => 'error_removing_item' };
79
            removeChecked        => 1,
73
        } else {
80
        );
74
            push @messages, { code => 'success_removing_item' };
81
82
        if ($success) {
83
            $template->param( removeSuccess => 1 );
84
        }
85
        else {
86
            $template->param( removeFailure  => 1 );
87
            $template->param( failureMessage => $errorMessage );
88
        }
75
        }
89
76
77
        $template->param(
78
            removeChecked => 1,
79
        );
90
    }
80
    }
91
}
81
}
92
82
93
- 

Return to bug 18606