X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FCalendar.pm;h=1e687db7aa247c39decf1f304c5aa10315df21dd;hb=1a5da08342182c739f2f5b790038c6ff04c748ea;hp=8ad363fdf99e0923aea6a05205d2b7017dd5bdc8;hpb=c5b878697e4dbe11780acd9fb6ea5b91c5312ffd;p=koha_fer diff --git a/C4/Calendar.pm b/C4/Calendar.pm index 8ad363fdf9..1e687db7aa 100644 --- a/C4/Calendar.pm +++ b/C4/Calendar.pm @@ -514,6 +514,78 @@ sub delete_holiday { } return $self; } +=head2 delete_holiday_range + + delete_holiday_range(day => $day, + month => $month, + year => $year); + +Delete a holiday range of dates for $self->{branchcode}. + +C<$day> Is the day month to make the date to delete. + +C<$month> Is month to make the date to delete. + +C<$year> Is year to make the date to delete. + +=cut + +sub delete_holiday_range { + my $self = shift; + my %options = @_; + + my $dbh = C4::Context->dbh(); + my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)"); + $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); +} + +=head2 delete_holiday_range_repeatable + + delete_holiday_range_repeatable(day => $day, + month => $month); + +Delete a holiday for $self->{branchcode}. + +C<$day> Is the day month to make the date to delete. + +C<$month> Is month to make the date to delete. + +=cut + +sub delete_holiday_range_repeatable { + my $self = shift; + my %options = @_; + + my $dbh = C4::Context->dbh(); + my $sth = $dbh->prepare("DELETE FROM repeatable_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?)"); + $sth->execute($self->{branchcode}, $options{day}, $options{month}); +} + +=head2 delete_exception_holiday_range + + delete_exception_holiday_range(weekday => $weekday + day => $day, + month => $month, + year => $year); + +Delete a holiday for $self->{branchcode}. + +C<$day> Is the day month to make the date to delete. + +C<$month> Is month to make the date to delete. + +C<$year> Is year to make the date to delete. + +=cut + +sub delete_exception_holiday_range { + my $self = shift; + my %options = @_; + + my $dbh = C4::Context->dbh(); + my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)"); + $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); +} =head2 isHoliday @@ -582,37 +654,6 @@ sub copy_to_branch { return 1; } -=head2 daysBetween - - my $daysBetween = $calendar->daysBetween($startdate, $enddate) - -C<$startdate> and C<$enddate> are C4::Dates objects that define the interval. - -Returns the number of non-holiday days in the interval. -useDaysMode syspref has no effect here. -=cut - -sub daysBetween ($$$) { - my $self = shift or return undef; - my $startdate = shift or return undef; - my $enddate = shift or return undef; - my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso')); - my ($yearTo, $monthTo, $dayTo ) = split("-", $enddate->output('iso')); - if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) { - return 0; - # we don't go backwards ( FIXME - handle this error better ) - } - my $count = 0; - while (1) { - ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day - unless ($self->isHoliday($dayFrom, $monthFrom, $yearFrom)) { - $count++; - } - ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1); - } - return($count); -} - =head2 addDate my ($day, $month, $year) = $calendar->addDate($date, $offset) @@ -660,16 +701,16 @@ Returns the number of non-holiday days in the interval. useDaysMode syspref has no effect here. =cut -sub daysBetween ($$$) { - my $self = shift or return undef; - my $startdate = shift or return undef; - my $enddate = shift or return undef; - my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso')); - my ($yearTo, $monthTo, $dayTo ) = split("-", $enddate->output('iso')); - if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) { - return 0; - # we don't go backwards ( FIXME - handle this error better ) - } +sub daysBetween { + my $self = shift or return; + my $startdate = shift or return; + my $enddate = shift or return; + my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso')); + my ($yearTo, $monthTo, $dayTo ) = split("-", $enddate->output('iso')); + if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) { + return 0; + # we don't go backwards ( FIXME - handle this error better ) + } my $count = 0; while (1) { ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day