Lines 51-145
sub _init {
Link Here
|
51 |
return; |
51 |
return; |
52 |
} |
52 |
} |
53 |
|
53 |
|
54 |
sub exception_holidays { |
54 |
sub _holidays { |
55 |
my ($self) = @_; |
55 |
my ($self) = @_; |
56 |
|
56 |
|
57 |
my $cache = Koha::Caches->get_instance(); |
57 |
my $key = $self->{branchcode} . "_holidays"; |
58 |
my $exception_holidays = $cache->get_from_cache('exception_holidays'); |
58 |
my $cache = Koha::Caches->get_instance(); |
|
|
59 |
my $holidays = $cache->get_from_cache($key); |
59 |
|
60 |
|
60 |
# Populate the cache is necessary |
61 |
# $holidays looks like: |
61 |
unless ($exception_holidays) { |
|
|
62 |
my $dbh = C4::Context->dbh; |
63 |
$exception_holidays = {}; |
64 |
|
65 |
# Push holidays for each branch |
66 |
my $exception_holidays_sth = $dbh->prepare( |
67 |
'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 1' |
68 |
); |
69 |
$exception_holidays_sth->execute(); |
70 |
my $dates = []; |
71 |
while ( my ( $day, $month, $year, $branch ) = |
72 |
$exception_holidays_sth->fetchrow ) |
73 |
{ |
74 |
my $datestring = |
75 |
sprintf( "%04d", $year ) |
76 |
. sprintf( "%02d", $month ) |
77 |
. sprintf( "%02d", $day ); |
78 |
|
79 |
$exception_holidays->{$branch}->{$datestring} = 1; |
80 |
} |
81 |
$cache->set_in_cache( 'exception_holidays', $exception_holidays, |
82 |
{ expiry => 76800 } ); |
83 |
} |
84 |
|
85 |
return $exception_holidays->{ $self->{branchcode} } // {}; |
86 |
} |
87 |
|
88 |
sub is_exception_holiday { |
89 |
my ( $self, $date ) = @_; |
90 |
|
91 |
return 1 if ( $self->exception_holidays->{$date} ); |
92 |
return 0; |
93 |
} |
94 |
|
95 |
sub single_holidays { |
96 |
my ($self) = @_; |
97 |
|
98 |
my $cache = Koha::Caches->get_instance(); |
99 |
my $single_holidays = $cache->get_from_cache('single_holidays'); |
100 |
|
101 |
# $single_holidays looks like: |
102 |
# { |
62 |
# { |
103 |
# CPL => [ |
63 |
# 20131122 => 1, # single_holiday |
104 |
# [0] 20131122, |
64 |
# 20131123 => 0, # exception_holiday |
105 |
# ... |
65 |
# ... |
106 |
# ], |
|
|
107 |
# ... |
108 |
# } |
66 |
# } |
109 |
|
67 |
|
110 |
# Populate the cache if necessary |
68 |
# Populate the cache if necessary |
111 |
unless ($single_holidays) { |
69 |
unless ($holidays) { |
112 |
my $dbh = C4::Context->dbh; |
70 |
my $dbh = C4::Context->dbh; |
113 |
$single_holidays = {}; |
71 |
$holidays = {}; |
114 |
|
72 |
|
115 |
# Push holidays for each branch |
73 |
# Add holidays for each branch |
116 |
my $single_holidays_sth = $dbh->prepare( |
74 |
my $holidays_sth = $dbh->prepare( |
117 |
'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 0' |
75 |
'SELECT day, month, year, isexception FROM special_holidays WHERE branchcode = ?' |
118 |
); |
76 |
); |
119 |
$single_holidays_sth->execute(); |
77 |
$holidays_sth->execute($self->{branchcode}); |
120 |
|
78 |
|
121 |
while ( my ( $day, $month, $year, $branch ) = |
79 |
while ( my ( $day, $month, $year, $exception ) = |
122 |
$single_holidays_sth->fetchrow ) |
80 |
$holidays_sth->fetchrow ) |
123 |
{ |
81 |
{ |
124 |
my $datestring = |
82 |
my $datestring = |
125 |
sprintf( "%04d", $year ) |
83 |
sprintf( "%04d", $year ) |
126 |
. sprintf( "%02d", $month ) |
84 |
. sprintf( "%02d", $month ) |
127 |
. sprintf( "%02d", $day ); |
85 |
. sprintf( "%02d", $day ); |
128 |
|
86 |
|
129 |
$single_holidays->{$branch}->{$datestring} = 1; |
87 |
$holidays->{$datestring} = !$exception; |
130 |
} |
88 |
} |
131 |
$cache->set_in_cache( 'single_holidays', $single_holidays, |
89 |
$cache->set_in_cache( $key, $holidays, { expiry => 76800 } ); |
132 |
{ expiry => 76800 } ); |
|
|
133 |
} |
90 |
} |
134 |
|
91 |
|
135 |
return $single_holidays->{ $self->{branchcode} } // {}; |
92 |
return $holidays // {}; |
136 |
} |
|
|
137 |
|
138 |
sub is_single_holiday { |
139 |
my ( $self, $date ) = @_; |
140 |
|
141 |
return 1 if ( $self->single_holidays->{$date} ); |
142 |
return 0; |
143 |
} |
93 |
} |
144 |
|
94 |
|
145 |
sub addDate { |
95 |
sub addDate { |
Lines 258-274
sub is_holiday {
Link Here
|
258 |
my $localdt = $dt->clone(); |
208 |
my $localdt = $dt->clone(); |
259 |
my $day = $localdt->day; |
209 |
my $day = $localdt->day; |
260 |
my $month = $localdt->month; |
210 |
my $month = $localdt->month; |
261 |
my $ymd = $localdt->ymd('') ; |
211 |
my $ymd = $localdt->ymd(''); |
262 |
|
212 |
|
263 |
#Change timezone to "floating" before doing any calculations or comparisons |
213 |
#Change timezone to "floating" before doing any calculations or comparisons |
264 |
$localdt->set_time_zone("floating"); |
214 |
$localdt->set_time_zone("floating"); |
265 |
$localdt->truncate( to => 'day' ); |
215 |
$localdt->truncate( to => 'day' ); |
266 |
|
216 |
|
267 |
|
217 |
return $self->_holidays->{$ymd} if defined($self->_holidays->{$ymd}); |
268 |
if ( $self->is_exception_holiday( $ymd ) == 1 ) { |
|
|
269 |
# exceptions are not holidays |
270 |
return 0; |
271 |
} |
272 |
|
218 |
|
273 |
my $dow = $localdt->day_of_week; |
219 |
my $dow = $localdt->day_of_week; |
274 |
# Representation fix |
220 |
# Representation fix |
Lines 286-295
sub is_holiday {
Link Here
|
286 |
return 1; |
232 |
return 1; |
287 |
} |
233 |
} |
288 |
|
234 |
|
289 |
if ($self->is_single_holiday( $ymd ) == 1 ) { |
|
|
290 |
return 1; |
291 |
} |
292 |
|
293 |
# damn have to go to work after all |
235 |
# damn have to go to work after all |
294 |
return 0; |
236 |
return 0; |
295 |
} |
237 |
} |
Lines 485-509
C<$unit> is a string value 'days' or 'hours' toflag granularity of duration
Link Here
|
485 |
Currently unit is only used to invoke Staffs return Monday at 10 am rule this |
427 |
Currently unit is only used to invoke Staffs return Monday at 10 am rule this |
486 |
parameter will be removed when issuingrules properly cope with that |
428 |
parameter will be removed when issuingrules properly cope with that |
487 |
|
429 |
|
488 |
|
|
|
489 |
=head2 single_holidays |
490 |
|
491 |
my $rc = $self->single_holidays( $ymd ); |
492 |
|
493 |
Passed a $date in Ymd (yyyymmdd) format - returns 1 if date is a single_holiday, or 0 if not. |
494 |
|
495 |
=head2 exception_holidays |
496 |
|
497 |
my $exceptions = $self->exception_holidays; |
498 |
|
499 |
Returns a hashref of exception holidays for the branch |
500 |
|
501 |
=head2 is_exception_holiday |
502 |
|
503 |
my $rc = $self->is_exception_holiday( $ymd ); |
504 |
|
505 |
Passed a $date in Ymd (yyyymmdd) format - returns 1 if the date is an exception_holiday, or 0 if not. |
506 |
|
507 |
=head2 is_holiday |
430 |
=head2 is_holiday |
508 |
|
431 |
|
509 |
$yesno = $calendar->is_holiday($dt); |
432 |
$yesno = $calendar->is_holiday($dt); |
510 |
- |
|
|