Lines 23-30
use Carp;
Link Here
|
23 |
use Date::Calc qw( Date_to_Days Today); |
23 |
use Date::Calc qw( Date_to_Days Today); |
24 |
|
24 |
|
25 |
use C4::Context; |
25 |
use C4::Context; |
|
|
26 |
use Koha::Cache; |
26 |
|
27 |
|
27 |
use constant ISO_DATE_FORMAT => "%04d-%02d-%02d"; |
28 |
use constant ISO_DATE_FORMAT => "%04d-%02d-%02d"; |
|
|
29 |
|
28 |
=head1 NAME |
30 |
=head1 NAME |
29 |
|
31 |
|
30 |
C4::Calendar::Calendar - Koha module dealing with holidays. |
32 |
C4::Calendar::Calendar - Koha module dealing with holidays. |
Lines 262-268
C<$description> Is the description to store for the holiday formed by $year/$mon
Link Here
|
262 |
sub insert_single_holiday { |
264 |
sub insert_single_holiday { |
263 |
my $self = shift @_; |
265 |
my $self = shift @_; |
264 |
my %options = @_; |
266 |
my %options = @_; |
265 |
|
|
|
266 |
@options{qw(year month day)} = ( $options{date} =~ m/(\d+)-(\d+)-(\d+)/o ) |
267 |
@options{qw(year month day)} = ( $options{date} =~ m/(\d+)-(\d+)-(\d+)/o ) |
267 |
if $options{date} && !$options{day}; |
268 |
if $options{date} && !$options{day}; |
268 |
|
269 |
|
Lines 272-278
sub insert_single_holiday {
Link Here
|
272 |
$insertHoliday->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description}); |
273 |
$insertHoliday->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description}); |
273 |
$self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title}; |
274 |
$self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title}; |
274 |
$self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; |
275 |
$self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; |
|
|
276 |
|
277 |
|
278 |
# changed the 'single_holidays' table, lets force/reset its cache |
279 |
my $cache = Koha::Cache->get_instance(); |
280 |
$cache->clear_from_cache( 'single_holidays') ; |
281 |
|
275 |
return $self; |
282 |
return $self; |
|
|
283 |
|
276 |
} |
284 |
} |
277 |
|
285 |
|
278 |
=head2 insert_exception_holiday |
286 |
=head2 insert_exception_holiday |
Lines 310-315
sub insert_exception_holiday {
Link Here
|
310 |
$insertException->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description}); |
318 |
$insertException->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description}); |
311 |
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title}; |
319 |
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title}; |
312 |
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; |
320 |
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; |
|
|
321 |
|
322 |
# changed the 'single_holidays' table, lets force/reset its cache |
323 |
my $cache = Koha::Cache->get_instance(); |
324 |
$cache->clear_from_cache( 'single_holidays') ; |
325 |
|
313 |
return $self; |
326 |
return $self; |
314 |
} |
327 |
} |
315 |
|
328 |
|
Lines 398-407
sub ModSingleholiday {
Link Here
|
398 |
|
411 |
|
399 |
my $dbh = C4::Context->dbh(); |
412 |
my $dbh = C4::Context->dbh(); |
400 |
my $isexception = 0; |
413 |
my $isexception = 0; |
401 |
my $updateHoliday = $dbh->prepare("UPDATE special_holidays SET title = ?, description = ? WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?"); |
414 |
|
|
|
415 |
my $updateHoliday = $dbh->prepare(" |
416 |
UPDATE special_holidays SET title = ?, description = ? |
417 |
WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?"); |
402 |
$updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception); |
418 |
$updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception); |
403 |
$self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title}; |
419 |
$self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title}; |
404 |
$self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; |
420 |
$self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; |
|
|
421 |
|
422 |
# changed the 'single_holidays' table, lets force/reset its cache |
423 |
my $cache = Koha::Cache->get_instance(); |
424 |
$cache->clear_from_cache( 'single_holidays') ; |
425 |
|
405 |
return $self; |
426 |
return $self; |
406 |
} |
427 |
} |
407 |
|
428 |
|
Lines 433-442
sub ModExceptionholiday {
Link Here
|
433 |
|
454 |
|
434 |
my $dbh = C4::Context->dbh(); |
455 |
my $dbh = C4::Context->dbh(); |
435 |
my $isexception = 1; |
456 |
my $isexception = 1; |
436 |
my $updateHoliday = $dbh->prepare("UPDATE special_holidays SET title = ?, description = ? WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?"); |
457 |
my $updateHoliday = $dbh->prepare(" |
437 |
$updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception); |
458 |
UPDATE special_holidays SET title = ?, description = ? |
|
|
459 |
WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?"); |
460 |
$updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception); |
438 |
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title}; |
461 |
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title}; |
439 |
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; |
462 |
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description}; |
|
|
463 |
|
464 |
# changed the 'single_holidays' table, lets force/reset its cache |
465 |
my $cache = Koha::Cache->get_instance(); |
466 |
$cache->clear_from_cache( 'single_holidays') ; |
467 |
|
440 |
return $self; |
468 |
return $self; |
441 |
} |
469 |
} |
442 |
|
470 |
|
Lines 465-471
sub delete_holiday {
Link Here
|
465 |
|
493 |
|
466 |
# Verify what kind of holiday that day is. For example, if it is |
494 |
# Verify what kind of holiday that day is. For example, if it is |
467 |
# a repeatable holiday, this should check if there are some exception |
495 |
# a repeatable holiday, this should check if there are some exception |
468 |
# for that holiday rule. Otherwise, if it is a regular holiday, it´s |
496 |
# for that holiday rule. Otherwise, if it is a regular holiday, it´s |
469 |
# ok just deleting it. |
497 |
# ok just deleting it. |
470 |
|
498 |
|
471 |
my $dbh = C4::Context->dbh(); |
499 |
my $dbh = C4::Context->dbh(); |
Lines 512-517
sub delete_holiday {
Link Here
|
512 |
} |
540 |
} |
513 |
} |
541 |
} |
514 |
} |
542 |
} |
|
|
543 |
|
544 |
# changed the 'single_holidays' table, lets force/reset its cache |
545 |
my $cache = Koha::Cache->get_instance(); |
546 |
$cache->clear_from_cache( 'single_holidays') ; |
547 |
|
515 |
return $self; |
548 |
return $self; |
516 |
} |
549 |
} |
517 |
=head2 delete_holiday_range |
550 |
=head2 delete_holiday_range |
Lines 537-542
sub delete_holiday_range {
Link Here
|
537 |
my $dbh = C4::Context->dbh(); |
570 |
my $dbh = C4::Context->dbh(); |
538 |
my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)"); |
571 |
my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)"); |
539 |
$sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); |
572 |
$sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); |
|
|
573 |
|
574 |
# changed the 'single_holidays' table, lets force/reset its cache |
575 |
my $cache = Koha::Cache->get_instance(); |
576 |
$cache->clear_from_cache( 'single_holidays') ; |
577 |
|
540 |
} |
578 |
} |
541 |
|
579 |
|
542 |
=head2 delete_holiday_range_repeatable |
580 |
=head2 delete_holiday_range_repeatable |
Lines 585-590
sub delete_exception_holiday_range {
Link Here
|
585 |
my $dbh = C4::Context->dbh(); |
623 |
my $dbh = C4::Context->dbh(); |
586 |
my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)"); |
624 |
my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)"); |
587 |
$sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); |
625 |
$sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); |
|
|
626 |
|
627 |
# changed the 'single_holidays' table, lets force/reset its cache |
628 |
my $cache = Koha::Cache->get_instance(); |
629 |
$cache->clear_from_cache( 'single_holidays') ; |
588 |
} |
630 |
} |
589 |
|
631 |
|
590 |
=head2 isHoliday |
632 |
=head2 isHoliday |
Lines 606-612
sub isHoliday {
Link Here
|
606 |
$month=$month+0; |
648 |
$month=$month+0; |
607 |
$year=$year+0; |
649 |
$year=$year+0; |
608 |
$day=$day+0; |
650 |
$day=$day+0; |
609 |
my $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7; |
651 |
my $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7; |
610 |
my $weekDays = $self->get_week_days_holidays(); |
652 |
my $weekDays = $self->get_week_days_holidays(); |
611 |
my $dayMonths = $self->get_day_month_holidays(); |
653 |
my $dayMonths = $self->get_day_month_holidays(); |
612 |
my $exceptions = $self->get_exception_holidays(); |
654 |
my $exceptions = $self->get_exception_holidays(); |
Lines 617-623
sub isHoliday {
Link Here
|
617 |
if ((exists($weekDays->{$weekday})) || |
659 |
if ((exists($weekDays->{$weekday})) || |
618 |
(exists($dayMonths->{"$month/$day"})) || |
660 |
(exists($dayMonths->{"$month/$day"})) || |
619 |
(exists($singles->{"$year/$month/$day"}))) { |
661 |
(exists($singles->{"$year/$month/$day"}))) { |
620 |
return 1; |
662 |
return 1; |
621 |
} else { |
663 |
} else { |
622 |
return 0; |
664 |
return 0; |
623 |
} |
665 |
} |