Lines 50-144
sub _init {
Link Here
|
50 |
return; |
50 |
return; |
51 |
} |
51 |
} |
52 |
|
52 |
|
53 |
sub exception_holidays { |
53 |
sub _holidays { |
54 |
my ($self) = @_; |
54 |
my ($self) = @_; |
55 |
|
55 |
|
56 |
my $cache = Koha::Caches->get_instance(); |
56 |
my $key = $self->{branchcode} . "_holidays"; |
57 |
my $exception_holidays = $cache->get_from_cache('exception_holidays'); |
57 |
my $cache = Koha::Caches->get_instance(); |
|
|
58 |
my $holidays = $cache->get_from_cache($key); |
58 |
|
59 |
|
59 |
# Populate the cache is necessary |
60 |
# $holidays looks like: |
60 |
unless ($exception_holidays) { |
|
|
61 |
my $dbh = C4::Context->dbh; |
62 |
$exception_holidays = {}; |
63 |
|
64 |
# Push holidays for each branch |
65 |
my $exception_holidays_sth = $dbh->prepare( |
66 |
'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 1' |
67 |
); |
68 |
$exception_holidays_sth->execute(); |
69 |
my $dates = []; |
70 |
while ( my ( $day, $month, $year, $branch ) = |
71 |
$exception_holidays_sth->fetchrow ) |
72 |
{ |
73 |
my $datestring = |
74 |
sprintf( "%04d", $year ) |
75 |
. sprintf( "%02d", $month ) |
76 |
. sprintf( "%02d", $day ); |
77 |
|
78 |
$exception_holidays->{$branch}->{$datestring} = 1; |
79 |
} |
80 |
$cache->set_in_cache( 'exception_holidays', $exception_holidays, |
81 |
{ expiry => 76800 } ); |
82 |
} |
83 |
|
84 |
return $exception_holidays->{ $self->{branchcode} } // {}; |
85 |
} |
86 |
|
87 |
sub is_exception_holiday { |
88 |
my ( $self, $date ) = @_; |
89 |
|
90 |
return 1 if ( $self->exception_holidays->{$date} ); |
91 |
return 0; |
92 |
} |
93 |
|
94 |
sub single_holidays { |
95 |
my ($self) = @_; |
96 |
|
97 |
my $cache = Koha::Caches->get_instance(); |
98 |
my $single_holidays = $cache->get_from_cache('single_holidays'); |
99 |
|
100 |
# $single_holidays looks like: |
101 |
# { |
61 |
# { |
102 |
# CPL => [ |
62 |
# 20131122 => 1, # single_holiday |
103 |
# [0] 20131122, |
63 |
# 20131123 => 0, # exception_holiday |
104 |
# ... |
64 |
# ... |
105 |
# ], |
|
|
106 |
# ... |
107 |
# } |
65 |
# } |
108 |
|
66 |
|
109 |
# Populate the cache if necessary |
67 |
# Populate the cache if necessary |
110 |
unless ($single_holidays) { |
68 |
unless ($holidays) { |
111 |
my $dbh = C4::Context->dbh; |
69 |
my $dbh = C4::Context->dbh; |
112 |
$single_holidays = {}; |
70 |
$holidays = {}; |
113 |
|
71 |
|
114 |
# Push holidays for each branch |
72 |
# Add holidays for each branch |
115 |
my $single_holidays_sth = $dbh->prepare( |
73 |
my $holidays_sth = $dbh->prepare( |
116 |
'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 0' |
74 |
'SELECT day, month, year, isexception FROM special_holidays WHERE branchcode = ?' |
117 |
); |
75 |
); |
118 |
$single_holidays_sth->execute(); |
76 |
$holidays_sth->execute($self->{branchcode}); |
119 |
|
77 |
|
120 |
while ( my ( $day, $month, $year, $branch ) = |
78 |
while ( my ( $day, $month, $year, $exception ) = |
121 |
$single_holidays_sth->fetchrow ) |
79 |
$holidays_sth->fetchrow ) |
122 |
{ |
80 |
{ |
123 |
my $datestring = |
81 |
my $datestring = |
124 |
sprintf( "%04d", $year ) |
82 |
sprintf( "%04d", $year ) |
125 |
. sprintf( "%02d", $month ) |
83 |
. sprintf( "%02d", $month ) |
126 |
. sprintf( "%02d", $day ); |
84 |
. sprintf( "%02d", $day ); |
127 |
|
85 |
|
128 |
$single_holidays->{$branch}->{$datestring} = 1; |
86 |
$holidays->{$datestring} = !$exception; |
129 |
} |
87 |
} |
130 |
$cache->set_in_cache( 'single_holidays', $single_holidays, |
88 |
$cache->set_in_cache( $key, $holidays, { expiry => 76800 } ); |
131 |
{ expiry => 76800 } ); |
|
|
132 |
} |
89 |
} |
133 |
|
90 |
|
134 |
return $single_holidays->{ $self->{branchcode} } // {}; |
91 |
return $holidays // {}; |
135 |
} |
|
|
136 |
|
137 |
sub is_single_holiday { |
138 |
my ( $self, $date ) = @_; |
139 |
|
140 |
return 1 if ( $self->single_holidays->{$date} ); |
141 |
return 0; |
142 |
} |
92 |
} |
143 |
|
93 |
|
144 |
sub addDate { |
94 |
sub addDate { |
Lines 275-291
sub is_holiday {
Link Here
|
275 |
my $localdt = $dt->clone(); |
225 |
my $localdt = $dt->clone(); |
276 |
my $day = $localdt->day; |
226 |
my $day = $localdt->day; |
277 |
my $month = $localdt->month; |
227 |
my $month = $localdt->month; |
278 |
my $ymd = $localdt->ymd('') ; |
228 |
my $ymd = $localdt->ymd(''); |
279 |
|
229 |
|
280 |
#Change timezone to "floating" before doing any calculations or comparisons |
230 |
#Change timezone to "floating" before doing any calculations or comparisons |
281 |
$localdt->set_time_zone("floating"); |
231 |
$localdt->set_time_zone("floating"); |
282 |
$localdt->truncate( to => 'day' ); |
232 |
$localdt->truncate( to => 'day' ); |
283 |
|
233 |
|
284 |
|
234 |
return $self->_holidays->{$ymd} if defined($self->_holidays->{$ymd}); |
285 |
if ( $self->is_exception_holiday( $ymd ) == 1 ) { |
|
|
286 |
# exceptions are not holidays |
287 |
return 0; |
288 |
} |
289 |
|
235 |
|
290 |
my $dow = $localdt->day_of_week; |
236 |
my $dow = $localdt->day_of_week; |
291 |
# Representation fix |
237 |
# Representation fix |
Lines 303-312
sub is_holiday {
Link Here
|
303 |
return 1; |
249 |
return 1; |
304 |
} |
250 |
} |
305 |
|
251 |
|
306 |
if ($self->is_single_holiday( $ymd ) == 1 ) { |
|
|
307 |
return 1; |
308 |
} |
309 |
|
310 |
# damn have to go to work after all |
252 |
# damn have to go to work after all |
311 |
return 0; |
253 |
return 0; |
312 |
} |
254 |
} |
Lines 513-537
C<$unit> is a string value 'days' or 'hours' toflag granularity of duration
Link Here
|
513 |
Currently unit is only used to invoke Staffs return Monday at 10 am rule this |
455 |
Currently unit is only used to invoke Staffs return Monday at 10 am rule this |
514 |
parameter will be removed when issuingrules properly cope with that |
456 |
parameter will be removed when issuingrules properly cope with that |
515 |
|
457 |
|
516 |
|
|
|
517 |
=head2 single_holidays |
518 |
|
519 |
my $rc = $self->single_holidays( $ymd ); |
520 |
|
521 |
Passed a $date in Ymd (yyyymmdd) format - returns 1 if date is a single_holiday, or 0 if not. |
522 |
|
523 |
=head2 exception_holidays |
524 |
|
525 |
my $exceptions = $self->exception_holidays; |
526 |
|
527 |
Returns a hashref of exception holidays for the branch |
528 |
|
529 |
=head2 is_exception_holiday |
530 |
|
531 |
my $rc = $self->is_exception_holiday( $ymd ); |
532 |
|
533 |
Passed a $date in Ymd (yyyymmdd) format - returns 1 if the date is an exception_holiday, or 0 if not. |
534 |
|
535 |
=head2 is_holiday |
458 |
=head2 is_holiday |
536 |
|
459 |
|
537 |
$yesno = $calendar->is_holiday($dt); |
460 |
$yesno = $calendar->is_holiday($dt); |
538 |
- |
|
|