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

(-)a/Koha/Calendar.pm (-9 / +32 lines)
Lines 48-53 sub _init { Link Here
48
          1;
48
          1;
49
    }
49
    }
50
50
51
    $self->{days_mode}       = C4::Context->preference('useDaysMode');
52
    $self->{test}            = 0;
53
    return;
54
}
55
56
57
our ( $exception_holidays, $single_holidays );
58
sub exception_holidays {
59
    my ( $self ) = @_;
60
    my $dbh = C4::Context->dbh;
61
    my $branch = $self->{branchcode};
62
    if ( $exception_holidays ) {
63
        $self->{exception_holidays} = $exception_holidays;
64
        return $exception_holidays;
65
    }
51
    my $exception_holidays_sth = $dbh->prepare(
66
    my $exception_holidays_sth = $dbh->prepare(
52
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1'
67
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1'
53
    );
68
    );
Lines 64-75 sub _init { Link Here
64
    }
79
    }
65
    $self->{exception_holidays} =
80
    $self->{exception_holidays} =
66
      DateTime::Set->from_datetimes( dates => $dates );
81
      DateTime::Set->from_datetimes( dates => $dates );
82
    $exception_holidays = $self->{exception_holidays};
83
    return $exception_holidays;
84
}
67
85
86
sub single_holidays {
87
    my ( $self ) = @_;
88
    my $dbh = C4::Context->dbh;
89
    my $branch = $self->{branchcode};
90
    if ( $single_holidays ) {
91
        $self->{single_holidays} = $single_holidays;
92
        return $single_holidays;
93
    }
68
    my $single_holidays_sth = $dbh->prepare(
94
    my $single_holidays_sth = $dbh->prepare(
69
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
95
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
70
    );
96
    );
71
    $single_holidays_sth->execute( $branch );
97
    $single_holidays_sth->execute( $branch );
72
    $dates = [];
98
    my $dates = [];
73
    while ( my ( $day, $month, $year ) = $single_holidays_sth->fetchrow ) {
99
    while ( my ( $day, $month, $year ) = $single_holidays_sth->fetchrow ) {
74
        push @{$dates},
100
        push @{$dates},
75
          DateTime->new(
101
          DateTime->new(
Lines 80-90 sub _init { Link Here
80
          )->truncate( to => 'day' );
106
          )->truncate( to => 'day' );
81
    }
107
    }
82
    $self->{single_holidays} = DateTime::Set->from_datetimes( dates => $dates );
108
    $self->{single_holidays} = DateTime::Set->from_datetimes( dates => $dates );
83
    $self->{days_mode}       = C4::Context->preference('useDaysMode');
109
    $single_holidays = $self->{single_holidays};
84
    $self->{test}            = 0;
110
    return $single_holidays;
85
    return;
86
}
111
}
87
88
sub addDate {
112
sub addDate {
89
    my ( $self, $startdate, $add_duration, $unit ) = @_;
113
    my ( $self, $startdate, $add_duration, $unit ) = @_;
90
114
Lines 184-190 sub is_holiday { Link Here
184
208
185
    $localdt->truncate( to => 'day' );
209
    $localdt->truncate( to => 'day' );
186
210
187
    if ( $self->{exception_holidays}->contains($localdt) ) {
211
    if ( $self->exception_holidays->contains($localdt) ) {
188
        # exceptions are not holidays
212
        # exceptions are not holidays
189
        return 0;
213
        return 0;
190
    }
214
    }
Lines 204-210 sub is_holiday { Link Here
204
        return 1;
228
        return 1;
205
    }
229
    }
206
230
207
    if ( $self->{single_holidays}->contains($localdt) ) {
231
    if ( $self->single_holidays->contains($localdt) ) {
208
        return 1;
232
        return 1;
209
    }
233
    }
210
234
Lines 313-319 sub clear_weekly_closed_days { Link Here
313
sub add_holiday {
337
sub add_holiday {
314
    my $self = shift;
338
    my $self = shift;
315
    my $new_dt = shift;
339
    my $new_dt = shift;
316
    my @dt = $self->{single_holidays}->as_list;
340
    my @dt = $self->single_holidays->as_list;
317
    push @dt, $new_dt;
341
    push @dt, $new_dt;
318
    $self->{single_holidays} =
342
    $self->{single_holidays} =
319
      DateTime::Set->from_datetimes( dates => \@dt );
343
      DateTime::Set->from_datetimes( dates => \@dt );
320
- 

Return to bug 11112