Bugzilla – Attachment 8370 Details for
Bug 7351
ability to edit a range of holidays
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
patch finalized
0001-Bug-7351-feature-that-allows-to-delete-a-range-of-da.patch (text/plain), 15.45 KB, created by
Christophe Croullebois
on 2012-03-20 16:17:49 UTC
(
hide
)
Description:
patch finalized
Filename:
MIME Type:
Creator:
Christophe Croullebois
Created:
2012-03-20 16:17:49 UTC
Size:
15.45 KB
patch
obsolete
>From 0e3ebe7fde948f6761d57a61ec2b5819fa7997fd Mon Sep 17 00:00:00 2001 >From: Christophe Croullebois <christophe.croullebois@biblibre.com> >Date: Sat, 4 Feb 2012 16:43:51 +0100 >Subject: [PATCH 1/1] Bug 7351 : feature that allows to delete a range of dates > >Four new options, one for single holidays, one for the repeatable holidays. >Note that the exceptions are not deleted. >One to create exceptions on a range of dates, one to delete exceptions in a range of dates. >--- > C4/Calendar.pm | 102 ++++++++++++++++++++ > .../prog/en/modules/tools/holidays.tt | 43 +++++++- > tools/exceptionHolidays.pl | 90 +++++++++++++++++- > tools/newHolidays.pl | 1 - > 4 files changed, 226 insertions(+), 10 deletions(-) > >diff --git a/C4/Calendar.pm b/C4/Calendar.pm >index a9d39dc..0f455ce 100644 >--- a/C4/Calendar.pm >+++ b/C4/Calendar.pm >@@ -515,6 +515,108 @@ sub delete_holiday { > return $self; > } > >+=head2 delete_holiday_range >+ >+ delete_holiday_range(weekday => $weekday >+ day => $day, >+ month => $month, >+ year => $year); >+ >+Delete a holiday for $self->{branchcode}. >+ >+C<$weekday> Is the week day to delete. >+ >+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 $isSingleHoliday = $dbh->prepare("SELECT id FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)"); >+ $isSingleHoliday->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); >+ if ($isSingleHoliday->rows) { >+ my $id = $isSingleHoliday->fetchrow; >+ $isSingleHoliday->finish; # Close the last query >+ my $deleteHoliday = $dbh->prepare("DELETE FROM special_holidays WHERE id = ?"); >+ $deleteHoliday->execute($id); >+ } >+} >+ >+=head2 delete_holiday_range_repeatable >+ >+ delete_holiday_range_repeatable(weekday => $weekday >+ day => $day, >+ month => $month, >+ year => $year); >+ >+Delete a holiday for $self->{branchcode}. >+ >+C<$weekday> Is the week day to delete. >+ >+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_repeatable { >+ my $self = shift @_; >+ my %options = @_; >+ >+ my $dbh = C4::Context->dbh(); >+ my $isDayMonthHoliday = $dbh->prepare("SELECT id FROM repeatable_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?)"); >+ $isDayMonthHoliday->execute($self->{branchcode}, $options{day}, $options{month}); >+ if ($isDayMonthHoliday->rows) { >+ my $id = $isDayMonthHoliday->fetchrow; >+ $isDayMonthHoliday->finish; >+ my $deleteHoliday = $dbh->prepare("DELETE FROM repeatable_holidays WHERE (id = ?)"); >+ $deleteHoliday->execute($id); >+ } >+} >+ >+=head2 delete_exception_holiday_range >+ >+ delete_exception_holiday_range(weekday => $weekday >+ day => $day, >+ month => $month, >+ year => $year); >+ >+Delete a holiday for $self->{branchcode}. >+ >+C<$weekday> Is the week day to delete. >+ >+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 $isDayMonthHoliday = $dbh->prepare("SELECT id FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)"); >+ $isDayMonthHoliday->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); >+ if ($isDayMonthHoliday->rows) { >+ my $id = $isDayMonthHoliday->fetchrow; >+ $isDayMonthHoliday->finish; >+ my $deleteExceptions = $dbh->prepare("DELETE FROM special_holidays WHERE (id = ?)"); >+ $deleteExceptions->execute($id); >+ } >+} >+ > =head2 isHoliday > > $isHoliday = isHoliday($day, $month $year); >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 55db32d..318fc82 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt >@@ -83,8 +83,8 @@ > function Help() { > newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes'); > } >- $(document).ready(function() { > >+ $(document).ready(function() { > [% IF ( dateformat_metric ) %] $.tablesorter.addParser({ // http://tablesorter.com/docs/example-parsers.html > id: 'shortDates', > is: function(s){ >@@ -129,6 +129,7 @@ > $(this).parent().find(".hint").toggle(); return false; > }); > $("#dateofrange").each(function () { this.value = "" }); >+ $("#datecancelrange").each(function () { this.value = "" }); > }); > //]]> > </script> >@@ -185,7 +186,7 @@ > <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 %] >@@ -196,6 +197,20 @@ > <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 %]" /> >+ <img src="[% themelang %]/lib/calendar/cal.gif" id="datecancelrange_button" alt="Show Calendar" /> >+ <script language="JavaScript" type="text/javascript"> >+ Calendar.setup( >+ { >+ inputField : "datecancelrange", >+ ifFormat : "[% DHTMLcalendar_dateformat %]", >+ button : "datecancelrange_button" >+ } >+ ); >+ </script> >+ </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> >@@ -205,14 +220,30 @@ > <input type="radio" name="showOperation" id="showOperationExc" value="exception" /> <label for="showOperationExc">Generate an exception for this repeated holiday.</label> > <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> >+ <li class="radio"><input type="radio" name="newOperation" id="newOperationFieldException" value="exceptionrange" /> >+ <label for="newOperationFieldException">Exceptions on a range</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> >+ <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 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 carefull 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" /> >diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl >index 64a4860..50f649c 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'); >@@ -36,13 +39,48 @@ if ($description) { > } else { > $description = ''; > } >- >+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]; >+} > 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' ) { >+ #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){ >+ $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 +109,51 @@ if ($input->param('showOperation') eq 'exception') { > day => $day, > month => $month, > year => $year); >+}elsif ($input->param('showOperation') eq 'deleterange') { >+ if ($year1 && $month1 && $day1){ >+ #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){ >+ $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 ($year1 && $month1 && $day1){ >+ #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){ >+ $calendar->delete_holiday_range_repeatable(weekday => $weekday, >+ day => $date->{local_c}->{day}, >+ month => $date->{local_c}->{month}); >+ } >+ } >+}elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') { >+ if ($year1 && $month1 && $day1){ >+ #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){ >+ $calendar->delete_exception_holiday_range(weekday => $weekday, >+ day => $date->{local_c}->{day}, >+ month => $date->{local_c}->{month}); >+ } >+ } > } > 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..81b60a6 100755 >--- a/tools/newHolidays.pl >+++ b/tools/newHolidays.pl >@@ -146,5 +146,4 @@ sub add_holiday { > ); > } > } >- } > } >-- >1.7.0.4 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7351
:
7459
|
7502
|
7503
|
7504
|
7505
|
8005
|
8370
|
8382
|
8506
|
8585
|
8964
|
9075
|
9621
|
9691
|
9869
|
9882
|
10862
|
11214