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 268-284
sub is_holiday {
Link Here
|
268 |
my $localdt = $dt->clone(); |
218 |
my $localdt = $dt->clone(); |
269 |
my $day = $localdt->day; |
219 |
my $day = $localdt->day; |
270 |
my $month = $localdt->month; |
220 |
my $month = $localdt->month; |
271 |
my $ymd = $localdt->ymd('') ; |
221 |
my $ymd = $localdt->ymd(''); |
272 |
|
222 |
|
273 |
#Change timezone to "floating" before doing any calculations or comparisons |
223 |
#Change timezone to "floating" before doing any calculations or comparisons |
274 |
$localdt->set_time_zone("floating"); |
224 |
$localdt->set_time_zone("floating"); |
275 |
$localdt->truncate( to => 'day' ); |
225 |
$localdt->truncate( to => 'day' ); |
276 |
|
226 |
|
277 |
|
227 |
return $self->_holidays->{$ymd} if defined($self->_holidays->{$ymd}); |
278 |
if ( $self->is_exception_holiday( $ymd ) == 1 ) { |
|
|
279 |
# exceptions are not holidays |
280 |
return 0; |
281 |
} |
282 |
|
228 |
|
283 |
my $dow = $localdt->day_of_week; |
229 |
my $dow = $localdt->day_of_week; |
284 |
# Representation fix |
230 |
# Representation fix |
Lines 296-305
sub is_holiday {
Link Here
|
296 |
return 1; |
242 |
return 1; |
297 |
} |
243 |
} |
298 |
|
244 |
|
299 |
if ($self->is_single_holiday( $ymd ) == 1 ) { |
|
|
300 |
return 1; |
301 |
} |
302 |
|
303 |
# damn have to go to work after all |
245 |
# damn have to go to work after all |
304 |
return 0; |
246 |
return 0; |
305 |
} |
247 |
} |
Lines 506-530
C<$unit> is a string value 'days' or 'hours' toflag granularity of duration
Link Here
|
506 |
Currently unit is only used to invoke Staffs return Monday at 10 am rule this |
448 |
Currently unit is only used to invoke Staffs return Monday at 10 am rule this |
507 |
parameter will be removed when issuingrules properly cope with that |
449 |
parameter will be removed when issuingrules properly cope with that |
508 |
|
450 |
|
509 |
|
|
|
510 |
=head2 single_holidays |
511 |
|
512 |
my $rc = $self->single_holidays( $ymd ); |
513 |
|
514 |
Passed a $date in Ymd (yyyymmdd) format - returns 1 if date is a single_holiday, or 0 if not. |
515 |
|
516 |
=head2 exception_holidays |
517 |
|
518 |
my $exceptions = $self->exception_holidays; |
519 |
|
520 |
Returns a hashref of exception holidays for the branch |
521 |
|
522 |
=head2 is_exception_holiday |
523 |
|
524 |
my $rc = $self->is_exception_holiday( $ymd ); |
525 |
|
526 |
Passed a $date in Ymd (yyyymmdd) format - returns 1 if the date is an exception_holiday, or 0 if not. |
527 |
|
528 |
=head2 is_holiday |
451 |
=head2 is_holiday |
529 |
|
452 |
|
530 |
$yesno = $calendar->is_holiday($dt); |
453 |
$yesno = $calendar->is_holiday($dt); |
531 |
- |
|
|