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 (+28 lines)
Lines 87-92 sub add_item { Link Here
87
    return $col_tracking;
87
    return $col_tracking;
88
}
88
}
89
89
90
=head3 remove_item
91
92
$collection->remove_item( $item_object )
93
94
throws
95
    Koha::Exceptions::MissingParameter
96
    Koha::Exceptions::ObjectNotFound
97
98
=cut
99
100
sub remove_item {
101
    my ( $self, $item ) = @_;
102
103
    Koha::Exceptions::MissingParameter->throw if not defined $item;
104
105
    Koha::Exceptions::ObjectNotFound->throw if ref($item) ne 'Koha::Item';
106
107
    my $collection_tracking = Koha::RotatingCollection::Trackings->find(
108
        {
109
            itemnumber => $item->itemnumber,
110
            colId      => $self->colId,
111
        } );
112
113
    Koha::Exceptions::ObjectNotFound->throw if not defined $collection_tracking;
114
115
    return $collection_tracking->delete;
116
}
117
90
=head3 type
118
=head3 type
91
119
92
=cut
120
=cut
(-)a/rotating_collections/addItems.pl (-20 / +9 lines)
Lines 65-93 if ( $query->param('action') eq 'addItem' ) { Link Here
65
        } else {
65
        } else {
66
            push @messages, { code => 'success_adding_item' };
66
            push @messages, { code => 'success_adding_item' };
67
        }
67
        }
68
68
    } else {
69
        $template->param(
70
            previousActionAdd => 1,
71
        );
72
    }
73
    else {
74
        ## Remove the given item from the collection
69
        ## Remove the given item from the collection
75
        ( $success, $errorCode, $errorMessage ) =
70
        my $deleted = eval { $collection->remove_item( $item ) };
76
          RemoveItemFromCollection( $colId, $itemnumber );
77
71
78
        $template->param(
72
        if ( $@ or not $deleted ) {
79
            previousActionRemove => 1,
73
            push @errors, { code => 'error_removing_item' };
80
            removeChecked        => 1,
74
        } else {
81
        );
75
            push @messages, { code => 'success_removing_item' };
82
83
        if ($success) {
84
            $template->param( removeSuccess => 1 );
85
        }
86
        else {
87
            $template->param( removeFailure  => 1 );
88
            $template->param( failureMessage => $errorMessage );
89
        }
76
        }
90
77
78
        $template->param(
79
            removeChecked => 1,
80
        );
91
    }
81
    }
92
}
82
}
93
83
94
- 

Return to bug 18606