[Koha-patches] [PATCH 1/1] [PATCH] [SIGN OFF]Bug 7351 : feature that allows to delete a range of dates
Christophe Croullebois
christophe.croullebois at biblibre.com
Sun Jul 15 17:46:18 CEST 2012
From: christophe croullebois <christophe.croullebois at biblibre.com>
Four new options, one for single holidays, one for the repeatable holidays.
One to create exceptions on a range of dates, one to delete exceptions in a range of dates.
Note that the exceptions are not deleted if you delete a range of repeatable dates.
But if you delete a range of single holidays the exeptions inside will be deleted.
Signed-off-by: Stephane Delaye <stephane.delaye at biblibre.com>
---
C4/Calendar.pm | 72 +++++++++++++++++++
.../prog/en/modules/tools/holidays.tt | 36 ++++++++--
tools/exceptionHolidays.pl | 74 ++++++++++++++++++-
tools/newHolidays.pl | 76 +++++++++-----------
4 files changed, 208 insertions(+), 50 deletions(-)
diff --git a/C4/Calendar.pm b/C4/Calendar.pm
index a9d39dc..1e687db 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
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt
index 9993c28..fa7904f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt
@@ -197,7 +197,9 @@
$(this).parent().find(".hint").toggle(); return false;
});
$("#dateofrange").datepicker();
+ $("#datecancelrange").datepicker();
$("#dateofrange").each(function () { this.value = "" });
+ $("#datecancelrange").each(function () { this.value = "" });
$("#jcalendar-container").datepicker({
beforeShowDay: function(thedate) {
var day = thedate.getDate();
@@ -276,7 +278,7 @@ td.repeatableyearly a.ui-state-default, .repeatableyearly { background: #FFFF9
<input type="hidden" id="showBranchName" name="showBranchName" />
</li>
<li>
- <strong>Date:</strong>
+ <strong>From Date:</strong>
<span id="showDaynameOutput"></span>,
[% IF ( dateformat_us ) %]<span id="showMonthOutput"></span>/<span id="showDayOutput"></span>/<span id="showYearOutput"></span>[% ELSIF ( dateformat_metric ) %]<span id="showDayOutput"></span>/<span id="showMonthOutput"></span>/<span id="showYearOutput"></span>[% ELSE %]<span id="showYearOutput"></span>/<span id="showMonthOutput"></span>/<span id="showDayOutput"></span>[% END %]
@@ -287,6 +289,10 @@ td.repeatableyearly a.ui-state-default, .repeatableyearly { background: #FFFF9
<input type="hidden" id="showMonth" name="showMonth" />
<input type="hidden" id="showYear" name="showYear" />
</li>
+ <li class="dateinsert">
+ <b>To Date : </b>
+ <input type="text" id="datecancelrange" name="datecancelrange" size="20" value="[% datecancelrange %]" class="datepicker"/>
+ </li>
<li><label for="showTitle">Title: </label><input type="text" name="showTitle" id="showTitle" size="35" /></li>
<!-- showTitle is necessary for exception radio button to work properly -->
<label for="showDescription">Description:</label>
@@ -297,13 +303,29 @@ td.repeatableyearly a.ui-state-default, .repeatableyearly { background: #FFFF9
<a href="#" class="helptext">[?]</a>
<div class="hint">You can make an exception for this holiday rule. This means that you will be able to say that for a repeatable holiday there is one day which is going to be an exception.</div>
</div></li>
+ <li class="radio"><input type="radio" name="showOperation" id="showOperationExcRange" value="exceptionrange" />
+ <label for="newOperationFieldException">Generate exceptions on a range of dates.</label>
+ <a href="#" class="helptext">[?]</a>
+ <div class="hint">You can make an exception on a range of dates repeated yearly.</div>
+ </li>
<li class="radio"><input type="radio" name="showOperation" id="showOperationDel" value="delete" /> <label for="showOperationDel" id="showOperationDelLabel">Delete this holiday</label>
<a href="#" class="helptext">[?]</a>
- <div class="hint">This will delete this holiday rule. If it is a repeatable holiday, this option checks for posible exceptions. If an exception exists, this option will remove the exception and set the date to a regular holiday.</div></li>
+ <div class="hint">This will delete this holiday rule. If it is a repeatable holiday, this option checks for possible exceptions. If an exception exists, this option will remove the exception and set the date to a regular holiday.</div></li>
+ <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRange" value="deleterange" /> <label for="showOperationDelRange" id="showOperationDelLabelRange">Delete the single holidays on a range</label>.
+ <a href="#" class="helptext">[?]</a>
+ <div class="hint">This will delete the single holidays rules only. The repeatable holidays and exceptions will not be deleted.</div>
+ </li>
+ <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRangeRepeat" value="deleterangerepeat" /> <label for="showOperationDelRangeRepeat" id="showOperationDelLabelRangeRepeat">Delete the repeated holidays on a range</label>.
+ <a href="#" class="helptext">[?]</a>
+ <div class="hint">This will delete the repeated holidays rules only. The repeatable holidays will be deleted but not the exceptions.</div>
+ </li>
+ <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRangeRepeatExcept" value="deleterangerepeatexcept" /> <label for="showOperationDelRangeRepeatExcept" id="showOperationDelLabelRangeRepeatExcept">Delete the exceptions on a range</label>.
+ <a href="#" class="helptext">[?]</a>
+ <div class="hint">This will delete the exceptions inside a given range. Be careful about your scope range if it is oversized you could slow down Koha.</div>
+ </li>
<li class="radio"><input type="radio" name="showOperation" id="showOperationEdit" value="edit" checked="checked" /> <label for="showOperationEdit">Edit this holiday</label>
- <a href="#" class="helptext">[?]</a>
- <div class="hint">This will save changes to the holiday's title and description. If the information for a repeatable holiday is modified, it affects all of the dates on which the holiday is repeated.</div></li>
-
+ <a href="#" class="helptext">[?]</a>
+ <div class="hint">This will save changes to the holiday's title and description. If the information for a repeatable holiday is modified, it affects all of the dates on which the holiday is repeated.</div></li>
</ol>
<fieldset class="action">
<input type="submit" name="submit" value="Save" />
@@ -363,12 +385,12 @@ td.repeatableyearly a.ui-state-default, .repeatableyearly { background: #FFFF9
<li class="radio"><input type="radio" name="newOperation" id="newOperationField" value="holidayrange" />
<label for="newOperationField">Holidays on a range</label>.
<a href="#" class="helptext">[?]</a>
- <div class="hint">Make a single holiday on a range. For example, selecting August 1st, 2012 and August 10st, 2012 will make all days between 1st and 10st holiday, but will not affect August 1st-10st in other years.</div>
+ <div class="hint">Make a single holiday on a range. For example, selecting August 1st, 2012 and August 10st, 2012 will make all days between 1st and 10st holiday, but will not affect August 1-10 in other years.</div>
</li>
<li class="radio"><input type="radio" name="newOperation" id="newOperationFieldyear" value="holidayrangerepeat" />
<label for="newOperationFieldyear">Holidays repeated yearly on a range</label>.
<a href="#" class="helptext">[?]</a>
- <div class="hint">Make a single holiday on a range repeated yearly. For example, selecting August 1st, 2012 and August 10st, 2012 will make all days between 1st and 10st holiday, and will affect August 1st-10st in other years.</div>
+ <div class="hint">Make a single holiday on a range repeated yearly. For example, selecting August 1st, 2012 and August 10st, 2012 will make all days between 1st and 10st holiday, and will affect August 1-10 in other years.</div>
</li>
<li class="radio">
<input type="checkbox" name="allBranches" id="allBranches" />
diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl
index 64a4860..0a36a20 100755
--- a/tools/exceptionHolidays.pl
+++ b/tools/exceptionHolidays.pl
@@ -7,7 +7,7 @@ use CGI;
use C4::Auth;
use C4::Output;
-
+use DateTime;
use C4::Calendar;
@@ -19,10 +19,13 @@ my $weekday = $input->param('showWeekday');
my $day = $input->param('showDay');
my $month = $input->param('showMonth');
my $year = $input->param('showYear');
+my $day1;
+my $month1;
+my $year1;
my $title = $input->param('showTitle');
my $description = $input->param('showDescription');
my $holidaytype = $input->param('showHolidayType');
-
+my $datecancelrange = $input->param('datecancelrange');
my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
my $isodate = C4::Dates->new($calendardate, 'iso');
$calendardate = $isodate->output('syspref');
@@ -37,12 +40,53 @@ if ($description) {
$description = '';
}
+# We format the date
+my @dateend = split(/[\/-]/, $datecancelrange);
+if (C4::Context->preference("dateformat") eq "metric") {
+ $day1 = $dateend[0];
+ $month1 = $dateend[1];
+ $year1 = $dateend[2];
+}elsif (C4::Context->preference("dateformat") eq "us") {
+ $month1 = $dateend[0];
+ $day1 = $dateend[1];
+ $year1 = $dateend[2];
+} else {
+ $year1 = $dateend[0];
+ $month1 = $dateend[1];
+ $day1 = $dateend[2];
+}
+
+# We make an array with holiday's days
+my @holiday_list;
+if ($year1 && $month1 && $day1){
+ my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
+ my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1);
+
+ for (my $dt = $first_dt->clone();
+ $dt <= $end_dt;
+ $dt->add(days => 1) )
+ {
+ push @holiday_list, $dt->clone();
+ }
+}
if ($input->param('showOperation') eq 'exception') {
$calendar->insert_exception_holiday(day => $day,
month => $month,
year => $year,
title => $title,
description => $description);
+} elsif ($input->param('showOperation') eq 'exceptionrange' ) {
+ if (@holiday_list){
+ foreach my $date (@holiday_list){
+ $calendar->insert_exception_holiday(
+ day => $date->{local_c}->{day},
+ month => $date->{local_c}->{month},
+ year => $date->{local_c}->{year},
+ title => $title,
+ description => $description
+ );
+ }
+ }
} elsif ($input->param('showOperation') eq 'edit') {
if($holidaytype eq 'weekday') {
$calendar->ModWeekdayholiday(weekday => $weekday,
@@ -71,5 +115,31 @@ if ($input->param('showOperation') eq 'exception') {
day => $day,
month => $month,
year => $year);
+}elsif ($input->param('showOperation') eq 'deleterange') {
+ if (@holiday_list){
+ foreach my $date (@holiday_list){
+ $calendar->delete_holiday_range(weekday => $weekday,
+ day => $date->{local_c}->{day},
+ month => $date->{local_c}->{month},
+ year => $date->{local_c}->{year});
+ }
+ }
+}elsif ($input->param('showOperation') eq 'deleterangerepeat') {
+ if (@holiday_list){
+ foreach my $date (@holiday_list){
+ $calendar->delete_holiday_range_repeatable(weekday => $weekday,
+ day => $date->{local_c}->{day},
+ month => $date->{local_c}->{month});
+ }
+ }
+}elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
+ if (@holiday_list){
+ foreach my $date (@holiday_list){
+ $calendar->delete_exception_holiday_range(weekday => $weekday,
+ day => $date->{local_c}->{day},
+ month => $date->{local_c}->{month},
+ year => $date->{local_c}->{year});
+ }
+ }
}
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
diff --git a/tools/newHolidays.pl b/tools/newHolidays.pl
index c36d328..ffe99a3 100755
--- a/tools/newHolidays.pl
+++ b/tools/newHolidays.pl
@@ -56,6 +56,20 @@ if ($description) {
$description = '';
}
+# We make an array with holiday's days
+my @holiday_list;
+if ($year1 && $month1 && $day1){
+ my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
+ my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1);
+
+ for (my $dt = $first_dt->clone();
+ $dt <= $end_dt;
+ $dt->add(days => 1) )
+ {
+ push @holiday_list, $dt->clone();
+ }
+}
+
if($allbranches) {
my $branch;
my @branchcodes = split(/\|/, $input->param('branchCodes'));
@@ -100,50 +114,30 @@ sub add_holiday {
}
} elsif ( $newoperation eq 'holidayrange' ) {
- #Make an array with holiday's days
- my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
- my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1);
- my @holiday_list = ();
-
- for (my $dt = $first_dt->clone();
- $dt <= $end_dt;
- $dt->add(days => 1) )
- {
- push @holiday_list, $dt->clone();
- }
-
- foreach my $date (@holiday_list){
- unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
- $calendar->insert_single_holiday(
- day => $date->{local_c}->{day},
- month => $date->{local_c}->{month},
- year => $date->{local_c}->{year},
- title => $title,
- description => $description
- );
+ if (@holiday_list){
+ foreach my $date (@holiday_list){
+ unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
+ $calendar->insert_single_holiday(
+ day => $date->{local_c}->{day},
+ month => $date->{local_c}->{month},
+ year => $date->{local_c}->{year},
+ title => $title,
+ description => $description
+ );
+ }
}
}
} elsif ( $newoperation eq 'holidayrangerepeat' ) {
- #Make an array with holiday's days
- my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
- my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1);
- my @holiday_list = ();
-
- for (my $dt = $first_dt->clone();
- $dt <= $end_dt;
- $dt->add(days => 1) )
- {
- push @holiday_list, $dt->clone();
- }
-
- foreach my $date (@holiday_list){
- unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
- $calendar->insert_day_month_holiday(
- day => $date->{local_c}->{day},
- month => $date->{local_c}->{month},
- title => $title,
- description => $description
- );
+ if (@holiday_list){
+ foreach my $date (@holiday_list){
+ unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
+ $calendar->insert_day_month_holiday(
+ day => $date->{local_c}->{day},
+ month => $date->{local_c}->{month},
+ title => $title,
+ description => $description
+ );
+ }
}
}
}
--
1.7.9.5
More information about the Koha-patches
mailing list