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

(-)a/Koha/Calendar.pm (-35 / +30 lines)
Lines 52-58 sub _init { Link Here
52
}
52
}
53
53
54
sub exception_holidays {
54
sub exception_holidays {
55
    my ( $self ) = @_;
55
    my ($self) = @_;
56
56
57
    my $cache              = Koha::Caches->get_instance();
57
    my $cache              = Koha::Caches->get_instance();
58
    my $exception_holidays = $cache->get_from_cache('exception_holidays');
58
    my $exception_holidays = $cache->get_from_cache('exception_holidays');
Lines 82-88 sub exception_holidays { Link Here
82
            { expiry => 76800 } );
82
            { expiry => 76800 } );
83
    }
83
    }
84
84
85
    return $exception_holidays->{$self->{branchcode}} // {};
85
    return $exception_holidays->{ $self->{branchcode} } // {};
86
}
86
}
87
87
88
sub is_exception_holiday {
88
sub is_exception_holiday {
Lines 93-100 sub is_exception_holiday { Link Here
93
}
93
}
94
94
95
sub single_holidays {
95
sub single_holidays {
96
    my ( $self, $date ) = @_;
96
    my ($self) = @_;
97
    my $branchcode = $self->{branchcode};
97
98
    my $cache           = Koha::Caches->get_instance();
98
    my $cache           = Koha::Caches->get_instance();
99
    my $single_holidays = $cache->get_from_cache('single_holidays');
99
    my $single_holidays = $cache->get_from_cache('single_holidays');
100
100
Lines 107-148 sub single_holidays { Link Here
107
    #   ...
107
    #   ...
108
    # }
108
    # }
109
109
110
    # Populate the cache if necessary
110
    unless ($single_holidays) {
111
    unless ($single_holidays) {
111
        my $dbh = C4::Context->dbh;
112
        my $dbh = C4::Context->dbh;
112
        $single_holidays = {};
113
        $single_holidays = {};
113
114
114
        # push holidays for each branch
115
        # Push holidays for each branch
115
        my $branches_sth =
116
        my $single_holidays_sth = $dbh->prepare(
116
          $dbh->prepare('SELECT distinct(branchcode) FROM special_holidays');
117
'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 0'
117
        $branches_sth->execute();
118
        );
118
        while ( my $br = $branches_sth->fetchrow ) {
119
        $single_holidays_sth->execute();
119
            my $single_holidays_sth = $dbh->prepare(
120
120
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
121
        while ( my ( $day, $month, $year, $branch ) =
121
            );
122
            $single_holidays_sth->fetchrow )
122
            $single_holidays_sth->execute($br);
123
        {
123
124
            my $datestring =
124
            my @ymd_arr;
125
                sprintf( "%04d", $year )
125
            while ( my ( $day, $month, $year ) =
126
              . sprintf( "%02d", $month )
126
                $single_holidays_sth->fetchrow )
127
              . sprintf( "%02d", $day );
127
            {
128
128
                my $dt = DateTime->new(
129
            $single_holidays->{$branch}->{$datestring} = 1;
129
                    day       => $day,
130
        }
130
                    month     => $month,
131
                    year      => $year,
132
                    time_zone => 'floating',
133
                )->truncate( to => 'day' );
134
                push @ymd_arr, $dt->ymd('');
135
            }
136
            $single_holidays->{$br} = \@ymd_arr;
137
        }    # br
138
        $cache->set_in_cache( 'single_holidays', $single_holidays,
131
        $cache->set_in_cache( 'single_holidays', $single_holidays,
139
            { expiry => 76800 } )    #24 hrs ;
132
            { expiry => 76800 } );
140
    }
133
    }
141
134
142
    my $holidays  = ( $single_holidays->{$branchcode} );
135
    return $single_holidays->{ $self->{branchcode} } // {};
143
    for my $hols  (@$holidays ) {
136
}
144
            return 1 if ( $date == $hols )   #match ymds;
137
145
    }
138
sub is_single_holiday {
139
    my ( $self, $date ) = @_;
140
141
    return 1 if ( $self->single_holidays->{$date} );
146
    return 0;
142
    return 0;
147
}
143
}
148
144
Lines 290-296 sub is_holiday { Link Here
290
        return 1;
286
        return 1;
291
    }
287
    }
292
288
293
    if ($self->single_holidays(  $ymd  ) == 1 ) {
289
    if ($self->is_single_holiday(  $ymd  ) == 1 ) {
294
        return 1;
290
        return 1;
295
    }
291
    }
296
292
297
- 

Return to bug 25723