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

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

Return to bug 14315