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

(-)a/Koha/Exceptions/HoldGroup.pm (+64 lines)
Line 0 Link Here
1
package Koha::Exceptions::HoldGroup;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Exception;
21
22
use Exception::Class (
23
    'Koha::Exceptions::HoldGroup' => {
24
        isa => 'Koha::Exception',
25
    },
26
    'Koha::Exceptions::HoldGroup::HoldDoesNotExist' => {
27
        isa         => 'Koha::Exceptions::HoldGroup',
28
        description => "One or more holds do not exist",
29
        fields      => ['hold_ids'],
30
    },
31
    'Koha::Exceptions::HoldGroup::HoldDoesNotBelongToPatron' => {
32
        isa         => 'Koha::Exceptions::HoldGroup',
33
        description => "One or more holds do not belong to patron",
34
        fields      => ['hold_ids'],
35
    },
36
    'Koha::Exceptions::HoldGroup::HoldHasAlreadyBeenFound' => {
37
        isa         => 'Koha::Exceptions::HoldGroup',
38
        description => "One or more holds have already been found",
39
        fields      => ['barcodes'],
40
    },
41
    'Koha::Exceptions::HoldGroup::HoldAlreadyBelongsToHoldGroup' => {
42
        isa         => 'Koha::Exceptions::HoldGroup',
43
        description => "One or more holds already belong to a hold group",
44
        fields      => ['hold_ids'],
45
    },
46
);
47
48
=head1 NAME
49
50
Koha::Exceptions::HoldGroup - Base class for HoldGroup exceptions
51
52
=head1 Exceptions
53
54
=head2 Koha::Exceptions::HoldGroup
55
56
Generic HoldGroup exception
57
58
=head2 Koha::Exceptions::HoldGroup::HoldDoesNotExist
59
60
Exception to be used when one or more provided holds do not exist.
61
62
=cut
63
64
1;
(-)a/Koha/Patron.pm (+67 lines)
Lines 45-50 use Koha::DateUtils qw( dt_from_string ); Link Here
45
use Koha::Encryption;
45
use Koha::Encryption;
46
use Koha::Exceptions;
46
use Koha::Exceptions;
47
use Koha::Exceptions::Password;
47
use Koha::Exceptions::Password;
48
use Koha::Exceptions::HoldGroup;
48
use Koha::Holds;
49
use Koha::Holds;
49
use Koha::HoldGroups;
50
use Koha::HoldGroups;
50
use Koha::ILL::Requests;
51
use Koha::ILL::Requests;
Lines 1843-1848 sub hold_groups { Link Here
1843
    return Koha::HoldGroups->_new_from_dbic($hold_group_rs);
1844
    return Koha::HoldGroups->_new_from_dbic($hold_group_rs);
1844
}
1845
}
1845
1846
1847
=head3 create_hold_group
1848
1849
my $hold_group = $patron->create_hold_group
1850
1851
Creates and returns a hold group given a list of hold ids
1852
1853
If force_grouped is supplied, the hold group will be created even if the holds are already grouped
1854
1855
=cut
1856
1857
sub create_hold_group {
1858
    my ( $self, $hold_ids, $force_grouped ) = @_;
1859
1860
    my @undef_holds;
1861
    foreach my $hold_id (@$hold_ids) {
1862
        my $hold = Koha::Holds->find($hold_id);
1863
        push @undef_holds, $hold_id unless $hold;
1864
    }
1865
1866
    Koha::Exceptions::HoldGroup::HoldDoesNotExist->throw(
1867
        hold_ids => \@undef_holds,
1868
    ) if (@undef_holds);
1869
1870
    my @not_own_holds;
1871
    foreach my $hold_id (@$hold_ids) {
1872
        my $hold = Koha::Holds->find($hold_id);
1873
        push @not_own_holds, $hold_id unless $hold->borrowernumber eq $self->borrowernumber;
1874
    }
1875
1876
    Koha::Exceptions::HoldGroup::HoldDoesNotBelongToPatron->throw(
1877
        hold_ids => \@not_own_holds,
1878
    ) if (@not_own_holds);
1879
1880
    my @already_found_holds;
1881
    foreach my $hold_id (@$hold_ids) {
1882
        my $hold = Koha::Holds->find($hold_id);
1883
        push @already_found_holds, $hold->item->barcode if $hold->found;
1884
    }
1885
1886
    Koha::Exceptions::HoldGroup::HoldHasAlreadyBeenFound->throw(
1887
        barcodes => \@already_found_holds,
1888
    ) if (@already_found_holds);
1889
1890
    my @already_in_group_holds;
1891
    foreach my $hold_id (@$hold_ids) {
1892
        my $hold = Koha::Holds->find($hold_id);
1893
        push @already_in_group_holds, $hold_id if $hold->hold_group_id;
1894
    }
1895
1896
    Koha::Exceptions::HoldGroup::HoldAlreadyBelongsToHoldGroup->throw(
1897
        hold_ids => \@already_in_group_holds,
1898
    ) if @already_in_group_holds && !$force_grouped;
1899
1900
    my $hold_group_rs = $self->_result->create_related(
1901
        'hold_groups',
1902
        {}
1903
    );
1904
    foreach my $hold_id (@$hold_ids) {
1905
        my $hold = Koha::Holds->find($hold_id);
1906
1907
        $hold->hold_group_id( $hold_group_rs->hold_group_id )->store;
1908
    }
1909
1910
    return Koha::HoldGroup->_new_from_dbic($hold_group_rs);
1911
}
1912
1846
=head3 curbside_pickups
1913
=head3 curbside_pickups
1847
1914
1848
my $curbside_pickups = $patron->curbside_pickups;
1915
my $curbside_pickups = $patron->curbside_pickups;
(-)a/opac/opac-reserve.pl (-9 / +4 lines)
Lines 195-201 if ( $op eq 'cud-place_reserve' ) { Link Here
195
    }
195
    }
196
196
197
    my @failed_holds;
197
    my @failed_holds;
198
    my $hold_group;
198
    my @successful_hold_ids;
199
    while (@selectedItems) {
199
    while (@selectedItems) {
200
        my $biblioNum = shift(@selectedItems);
200
        my $biblioNum = shift(@selectedItems);
201
        my $itemNum   = shift(@selectedItems);
201
        my $itemNum   = shift(@selectedItems);
Lines 292-304 if ( $op eq 'cud-place_reserve' ) { Link Here
292
292
293
        # Here we actually do the reserveration. Stage 3.
293
        # Here we actually do the reserveration. Stage 3.
294
        if ($canreserve) {
294
        if ($canreserve) {
295
            if ($add_to_hold_group) {
296
297
                #NOTE: We wait to create a hold group until we know that we can actually place a hold/reserve
298
                if ( !$hold_group ) {
299
                    $hold_group = Koha::HoldGroup->new->store;
300
                }
301
            }
302
            my $reserve_id = AddReserve(
295
            my $reserve_id = AddReserve(
303
                {
296
                {
304
                    branchcode       => $branch,
297
                    branchcode       => $branch,
Lines 313-329 if ( $op eq 'cud-place_reserve' ) { Link Here
313
                    found            => undef,
306
                    found            => undef,
314
                    itemtype         => $itemtype,
307
                    itemtype         => $itemtype,
315
                    item_group_id    => $item_group_id,
308
                    item_group_id    => $item_group_id,
316
                    hold_group_id    => $hold_group ? $hold_group->id : undef,
317
                }
309
                }
318
            );
310
            );
319
            if ($reserve_id) {
311
            if ($reserve_id) {
320
                ++$reserve_cnt;
312
                ++$reserve_cnt;
313
                push @successful_hold_ids, $reserve_id;
321
            } else {
314
            } else {
322
                push @failed_holds, 'not_placed';
315
                push @failed_holds, 'not_placed';
323
            }
316
            }
324
        }
317
        }
325
    }
318
    }
326
319
320
    $patron->create_hold_group( \@successful_hold_ids ) if $add_to_hold_group;
321
327
    print $query->redirect( "/cgi-bin/koha/opac-user.pl?"
322
    print $query->redirect( "/cgi-bin/koha/opac-user.pl?"
328
            . ( @failed_holds ? "failed_holds=" . join( '|', @failed_holds ) : q|| )
323
            . ( @failed_holds ? "failed_holds=" . join( '|', @failed_holds ) : q|| )
329
            . "&opac-user-holds=1" );
324
            . "&opac-user-holds=1" );
(-)a/reserve/placerequest.pl (-7 / +9 lines)
Lines 69-77 foreach my $bibnum (@holdable_bibs) { Link Here
69
69
70
if ( $op eq 'cud-placerequest' && $patron ) {
70
if ( $op eq 'cud-placerequest' && $patron ) {
71
    my %failed_holds;
71
    my %failed_holds;
72
    if ($hold_group_param) {
72
    my @successful_hold_ids;
73
        $hold_group = Koha::HoldGroup->new->store;
74
    }
75
73
76
    foreach my $biblionumber ( keys %bibinfos ) {
74
    foreach my $biblionumber ( keys %bibinfos ) {
77
75
Lines 95-101 if ( $op eq 'cud-placerequest' && $patron ) { Link Here
95
                    if ( $can_item_be_reserved eq 'OK'
93
                    if ( $can_item_be_reserved eq 'OK'
96
                        || ( $can_item_be_reserved ne 'itemAlreadyOnHold' && $can_override ) )
94
                        || ( $can_item_be_reserved ne 'itemAlreadyOnHold' && $can_override ) )
97
                    {
95
                    {
98
                        AddReserve(
96
                        my $reserve_id = AddReserve(
99
                            {
97
                            {
100
                                branchcode       => $item_pickup_location,
98
                                branchcode       => $item_pickup_location,
101
                                borrowernumber   => $patron->borrowernumber,
99
                                borrowernumber   => $patron->borrowernumber,
Lines 113-118 if ( $op eq 'cud-placerequest' && $patron ) { Link Here
113
                            }
111
                            }
114
                        );
112
                        );
115
113
114
                        push @successful_hold_ids, $reserve_id;
116
                        $hold_priority++;
115
                        $hold_priority++;
117
116
118
                    } else {
117
                    } else {
Lines 124-130 if ( $op eq 'cud-placerequest' && $patron ) { Link Here
124
        } elsif ( @biblionumbers > 1 || $multi_holds ) {
123
        } elsif ( @biblionumbers > 1 || $multi_holds ) {
125
            my $bibinfo = $bibinfos{$biblionumber};
124
            my $bibinfo = $bibinfos{$biblionumber};
126
            if ( $can_override || CanBookBeReserved( $patron->borrowernumber, $biblionumber )->{status} eq 'OK' ) {
125
            if ( $can_override || CanBookBeReserved( $patron->borrowernumber, $biblionumber )->{status} eq 'OK' ) {
127
                AddReserve(
126
                my $reserve_id = AddReserve(
128
                    {
127
                    {
129
                        branchcode       => $bibinfo->{pickup},
128
                        branchcode       => $bibinfo->{pickup},
130
                        borrowernumber   => $patron->borrowernumber,
129
                        borrowernumber   => $patron->borrowernumber,
Lines 141-153 if ( $op eq 'cud-placerequest' && $patron ) { Link Here
141
                        hold_group_id    => $hold_group ? $hold_group->id : undef,
140
                        hold_group_id    => $hold_group ? $hold_group->id : undef,
142
                    }
141
                    }
143
                );
142
                );
143
                push @successful_hold_ids, $reserve_id;
144
            }
144
            }
145
        } else {
145
        } else {
146
146
147
            # place a request on 1st available
147
            # place a request on 1st available
148
            for ( my $i = 0 ; $i < $holds_to_place_count ; $i++ ) {
148
            for ( my $i = 0 ; $i < $holds_to_place_count ; $i++ ) {
149
                if ( $can_override || CanBookBeReserved( $patron->borrowernumber, $biblionumber )->{status} eq 'OK' ) {
149
                if ( $can_override || CanBookBeReserved( $patron->borrowernumber, $biblionumber )->{status} eq 'OK' ) {
150
                    AddReserve(
150
                    my $reserve_id = AddReserve(
151
                        {
151
                        {
152
                            branchcode       => $branch,
152
                            branchcode       => $branch,
153
                            borrowernumber   => $patron->borrowernumber,
153
                            borrowernumber   => $patron->borrowernumber,
Lines 165-175 if ( $op eq 'cud-placerequest' && $patron ) { Link Here
165
                            hold_group_id    => $hold_group ? $hold_group->id : undef,
165
                            hold_group_id    => $hold_group ? $hold_group->id : undef,
166
                        }
166
                        }
167
                    );
167
                    );
168
                    push @successful_hold_ids, $reserve_id;
168
                }
169
                }
169
            }
170
            }
170
        }
171
        }
171
    }
172
    }
172
173
174
    $patron->create_hold_group( \@successful_hold_ids ) if $hold_group_param;
175
173
    my $redirect_url     = URI->new("request.pl");
176
    my $redirect_url     = URI->new("request.pl");
174
    my @failed_hold_msgs = ();
177
    my @failed_hold_msgs = ();
175
178
176
- 

Return to bug 40517