- $special->execute( $branch, 0 );
- $dates = [];
- while ( my ( $day, $month, $year ) = $special->fetchrow ) {
- push @{$dates},
- DateTime->new(
- day => $day,
- month => $month,
- year => $year,
- time_zone => C4::Context->tz()
- )->truncate( to => 'day' );
+sub single_holidays {
+ my ( $self, $date ) = @_;
+ my $branchcode = $self->{branchcode};
+ my $cache = Koha::Cache->get_instance();
+ my $single_holidays = $cache->get_from_cache('single_holidays');
+
+ # $single_holidays looks like:
+ # {
+ # CPL => [
+ # [0] 20131122,
+ # ...
+ # ],
+ # ...
+ # }
+
+ unless ($single_holidays) {
+ my $dbh = C4::Context->dbh;
+ $single_holidays = {};
+
+ # push holidays for each branch
+ my $branches_sth =
+ $dbh->prepare('SELECT distinct(branchcode) FROM special_holidays');
+ $branches_sth->execute();
+ while ( my $br = $branches_sth->fetchrow ) {
+ my $single_holidays_sth = $dbh->prepare(
+'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
+ );
+ $single_holidays_sth->execute($branchcode);
+
+ my @ymd_arr;
+ while ( my ( $day, $month, $year ) =
+ $single_holidays_sth->fetchrow )
+ {
+ my $dt = DateTime->new(
+ day => $day,
+ month => $month,
+ year => $year,
+ time_zone => C4::Context->tz()
+ )->truncate( to => 'day' );
+ push @ymd_arr, $dt->ymd('');
+ }
+ $single_holidays->{$br} = \@ymd_arr;
+ } # br
+ $cache->set_in_cache( 'single_holidays', $single_holidays,
+ 76800 ) #24 hrs ;