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

(-)a/Koha/Patron/Debarments.pm (-32 / +15 lines)
Lines 27-34 BEGIN { Link Here
27
    require Exporter;
27
    require Exporter;
28
    @ISA       = qw(Exporter);
28
    @ISA       = qw(Exporter);
29
    @EXPORT_OK = qw(
29
    @EXPORT_OK = qw(
30
      GetDebarments
31
32
      AddDebarment
30
      AddDebarment
33
      DelDebarment
31
      DelDebarment
34
      ModDebarment
32
      ModDebarment
Lines 45-72 Koha::Patron::Debarments - Module for managing patron debarments Link Here
45
43
46
=cut
44
=cut
47
45
48
=head2 GetDebarments
49
50
my $arrayref = GetDebarments({ borrowernumber => $borrowernumber [, key => $value ] );
51
52
=cut
53
54
sub GetDebarments {
55
    my ($params) = @_;
56
57
    return unless ( $params->{'borrowernumber'} );
58
59
    my @keys   = keys %$params;
60
    my @values = values %$params;
61
62
    my $where = join( ' AND ', map { "$_ = ?" } @keys );
63
    my $sql   = "SELECT * FROM borrower_debarments WHERE $where";
64
    my $sth   = C4::Context->dbh->prepare($sql);
65
    $sth->execute(@values);
66
67
    return $sth->fetchall_arrayref( {} );
68
}
69
70
=head2 AddDebarment
46
=head2 AddDebarment
71
47
72
my $success = AddDebarment({
48
my $success = AddDebarment({
Lines 197-214 sub AddUniqueDebarment { Link Here
197
173
198
    return unless ( $borrowernumber && $type );
174
    return unless ( $borrowernumber && $type );
199
175
200
    my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0];
176
    my $patron = Koha::Patrons->find($borrowernumber);
177
    return unless $patron;
178
179
    my $debarment =
180
      $patron->restrictions->search( { type => $type }, { rows => 1 } )->single;
201
181
202
    my $r;
182
    my $r;
203
    if ($debarment) {
183
    if ($debarment) {
204
184
205
        # We don't want to shorten a unique debarment's period, so if this 'update' would do so, just keep the current expiration date instead
185
        # We don't want to shorten a unique debarment's period, so if this 'update' would do so, just keep the current expiration date instead
206
        $params->{'expiration'} = $debarment->{'expiration'}
186
        $params->{'expiration'} = $debarment->expiration
207
          if ( $debarment->{'expiration'}
187
          if ( $debarment->expiration
208
            && $debarment->{'expiration'} gt $params->{'expiration'} );
188
            && $debarment->expiration gt $params->{'expiration'} );
209
189
210
        $params->{'borrower_debarment_id'} =
190
        $params->{'borrower_debarment_id'} =
211
          $debarment->{'borrower_debarment_id'};
191
          $debarment->borrower_debarment_id;
212
        $r = ModDebarment($params);
192
        $r = ModDebarment($params);
213
    } else {
193
    } else {
214
194
Lines 242-252 sub DelUniqueDebarment { Link Here
242
222
243
    return unless ( $borrowernumber && $type );
223
    return unless ( $borrowernumber && $type );
244
224
245
    my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0];
225
    my $patron = Koha::Patrons->find($borrowernumber);
226
    return unless $patron;
227
228
    my $debarment =
229
      $patron->restrictions->search( { type => $type }, { rows => 1 } )->single;
246
230
247
    return unless ( $debarment );
231
    return unless ( $debarment );
248
232
249
    return DelDebarment( $debarment->{'borrower_debarment_id'} );
233
    return DelDebarment( $debarment->borrower_debarment_id );
250
}
234
}
251
235
252
=head2 UpdateBorrowerDebarmentFlags
236
=head2 UpdateBorrowerDebarmentFlags
253
- 

Return to bug 31095