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

(-)a/Koha/Calendar.pm (-9 / +32 lines)
Lines 52-57 sub _init { Link Here
52
          1;
52
          1;
53
    }
53
    }
54
54
55
    $self->{days_mode}       = C4::Context->preference('useDaysMode');
56
    $self->{test}            = 0;
57
    return;
58
}
59
60
61
our ( $exception_holidays, $single_holidays );
62
sub exception_holidays {
63
    my ( $self ) = @_;
64
    my $dbh = C4::Context->dbh;
65
    my $branch = $self->{branchcode};
66
    if ( $exception_holidays ) {
67
        $self->{exception_holidays} = $exception_holidays;
68
        return $exception_holidays;
69
    }
55
    my $exception_holidays_sth = $dbh->prepare(
70
    my $exception_holidays_sth = $dbh->prepare(
56
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1'
71
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1'
57
    );
72
    );
Lines 68-79 sub _init { Link Here
68
    }
83
    }
69
    $self->{exception_holidays} =
84
    $self->{exception_holidays} =
70
      DateTime::Set->from_datetimes( dates => $dates );
85
      DateTime::Set->from_datetimes( dates => $dates );
86
    $exception_holidays = $self->{exception_holidays};
87
    return $exception_holidays;
88
}
71
89
90
sub single_holidays {
91
    my ( $self ) = @_;
92
    my $dbh = C4::Context->dbh;
93
    my $branch = $self->{branchcode};
94
    if ( $single_holidays ) {
95
        $self->{single_holidays} = $single_holidays;
96
        return $single_holidays;
97
    }
72
    my $single_holidays_sth = $dbh->prepare(
98
    my $single_holidays_sth = $dbh->prepare(
73
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
99
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
74
    );
100
    );
75
    $single_holidays_sth->execute( $branch );
101
    $single_holidays_sth->execute( $branch );
76
    $dates = [];
102
    my $dates = [];
77
    while ( my ( $day, $month, $year ) = $single_holidays_sth->fetchrow ) {
103
    while ( my ( $day, $month, $year ) = $single_holidays_sth->fetchrow ) {
78
        push @{$dates},
104
        push @{$dates},
79
          DateTime->new(
105
          DateTime->new(
Lines 84-94 sub _init { Link Here
84
          )->truncate( to => 'day' );
110
          )->truncate( to => 'day' );
85
    }
111
    }
86
    $self->{single_holidays} = DateTime::Set->from_datetimes( dates => $dates );
112
    $self->{single_holidays} = DateTime::Set->from_datetimes( dates => $dates );
87
    $self->{days_mode}       = C4::Context->preference('useDaysMode');
113
    $single_holidays = $self->{single_holidays};
88
    $self->{test}            = 0;
114
    return $single_holidays;
89
    return;
90
}
115
}
91
92
sub addDate {
116
sub addDate {
93
    my ( $self, $startdate, $add_duration, $unit ) = @_;
117
    my ( $self, $startdate, $add_duration, $unit ) = @_;
94
118
Lines 188-194 sub is_holiday { Link Here
188
212
189
    $localdt->truncate( to => 'day' );
213
    $localdt->truncate( to => 'day' );
190
214
191
    if ( $self->{exception_holidays}->contains($localdt) ) {
215
    if ( $self->exception_holidays->contains($localdt) ) {
192
        # exceptions are not holidays
216
        # exceptions are not holidays
193
        return 0;
217
        return 0;
194
    }
218
    }
Lines 208-214 sub is_holiday { Link Here
208
        return 1;
232
        return 1;
209
    }
233
    }
210
234
211
    if ( $self->{single_holidays}->contains($localdt) ) {
235
    if ( $self->single_holidays->contains($localdt) ) {
212
        return 1;
236
        return 1;
213
    }
237
    }
214
238
Lines 342-348 sub clear_weekly_closed_days { Link Here
342
sub add_holiday {
366
sub add_holiday {
343
    my $self = shift;
367
    my $self = shift;
344
    my $new_dt = shift;
368
    my $new_dt = shift;
345
    my @dt = $self->{single_holidays}->as_list;
369
    my @dt = $self->single_holidays->as_list;
346
    push @dt, $new_dt;
370
    push @dt, $new_dt;
347
    $self->{single_holidays} =
371
    $self->{single_holidays} =
348
      DateTime::Set->from_datetimes( dates => \@dt );
372
      DateTime::Set->from_datetimes( dates => \@dt );
349
- 

Return to bug 11112