From: Chuck Scott Date: Fri, 8 Apr 2016 17:02:34 +0000 (-0400) Subject: Storing of times now working again after recurrences updates. X-Git-Tag: v1.0.0^2~108 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d91619b4ee3817bd886db064fadfcdc872745fc2;p=WP-Plugins%2Fglm-member-db-events.git Storing of times now working again after recurrences updates. --- diff --git a/classes/data/dataRecurrences.php b/classes/data/dataRecurrences.php index 6c3e3c5..7af7a69 100644 --- a/classes/data/dataRecurrences.php +++ b/classes/data/dataRecurrences.php @@ -374,27 +374,46 @@ class GlmDataEventsRecurrences extends GlmDataAbstract $from = new DateTime($recurData['from_date']['date'].' 00:00'); $to = new DateTime($recurData['to_date']['date'].' 00:00'); + // Determine years for scan + $fromYear = $from->format('Y'); + $toYear = $to->format('Y'); + + // Add one day to $to so matching dates should be < $to + $to->modify('+1 day'); + // Calculate interval for single event - If start time only, then start and end are the same - $start = new DateTime($recurData['start_time']['datetime']); - if ($recurData['start_time_only']) { - $end = new DateTime($recurData['start_time']['datetime']); + $start = new DateTime($recurData['from_date']['date'].$recurData['start_time']['time']); + if ($recurData['start_time_only']['value']) { + $end = new DateTime($recurData['from_date']['date'].$recurData['start_time']['time']); } else { - $end = new DateTime($recurData['end_time']['datetime']); + $end = new DateTime($recurData['from_date']['date'].$recurData['end_time']['time']); } $length = $start->diff($end); - // Determine years for scan - $fromYear = $from->format('Y'); - $toYear = $to->format('Y'); + // If negative interval assume it transitions midnight + if ($length->invert) { + + // Add 24 Hours to end dateTime + $interval24H = new DateInterval('PT24H'); + $end->add($interval24H); + + // Now get the length again + $length = $start->diff($end); + + } // Determine time each event starts at $time = $start->format('H:i'); - // If this is an All Dates event - if ($recurData['all_dates']['value']) { + // Get timestamp for start and end so we can filter unwanted dates + $startTime = $from->getTimestamp(); + $endTime = $to->getTimestamp(); + + // If this is not a recurring schedule but is All Dates from start date to end date + if (!$recurData['all_dates']['value']) { - // for each date from From through To - for ($date = clone $from ; $date <= $to ; $date->modify('+1 day')) { + // for each date from From through To + for ($date = clone $from ; $date < $to ; $date->modify('+1 day')) { $t = new DateTime($date->format('m/d/Y ').$time); $dates[$t->getTimestamp()] = $t; } @@ -414,13 +433,17 @@ class GlmDataEventsRecurrences extends GlmDataAbstract // For each specified days of the month ($dom is day of month) foreach ($recurData['day_of_month']['names'] as $kdom=>$dom) { $t = new DateTime("$month $dom $year $time"); - $dates[$t->getTimestamp()] = $t; + if ($t >= $from && $t < $to) { + $dates[$t->getTimestamp()] = $t; + } } // If last day of month is selected if ($recurData['last_day_of_month']['value']) { $t = new DateTime("last day of $month $year $time"); - $dates[$t->getTimestamp()] = $t; + if ($t >= $from && $t < $to) { + $dates[$t->getTimestamp()] = $t; + } } } else { @@ -431,7 +454,9 @@ class GlmDataEventsRecurrences extends GlmDataAbstract // For each day selected foreach ($recurData['day_of_week']['names'] as $kd=>$day) { $t = new DateTime("$week $day of $month $year $time"); - $dates[$t->getTimestamp()] = $t; + if ($t >= $from && $t < $to) { + $dates[$t->getTimestamp()] = $t; + } } } @@ -449,9 +474,8 @@ class GlmDataEventsRecurrences extends GlmDataAbstract $dates[$start->getTimestamp()] = $start; } - // Create From and to timestamp for comparison - Make to date +1 day + // Create From and to timestamp for comparison - To date is already + 1 day $fromTime = $from->getTimestamp(); - $to->modify('+1 day'); $toTime = $to->getTimestamp(); // Check for $replace, if so delete all existing entries and custom events @@ -465,13 +489,11 @@ class GlmDataEventsRecurrences extends GlmDataAbstract // For each date generated - create a times entry foreach ($dates as $k=>$v) { - $thisDate = $v->getTimestamp(); - // If date is within from and to range (we may not have checked this above) - if ($thisDate >= $fromTime && $thisDate <= $toTime ) { + if ($v >= $from && $v < $to ) { // Create text start date and time of this instance - $thisStartTime = $v->format('Y/m/d').date(' H:i:s', $recurData['start_time']['timestamp']); + $thisStartTime = $v->format('Y/m/d H:i:s'); // Create text end date and time of this instance $tet = new DateTime($thisStartTime); @@ -515,9 +537,6 @@ class GlmDataEventsRecurrences extends GlmDataAbstract return $timesData; } - - - } ?> diff --git a/views/admin/events/edit.html b/views/admin/events/edit.html index 9eb0c36..af6af07 100644 --- a/views/admin/events/edit.html +++ b/views/admin/events/edit.html @@ -508,7 +508,11 @@ // Initialize Calendar for date selection $('.recur-calendar').on('click', function() { recurID = $(this).attr('data-id'); + recurName = $('#recurSchedName_' + recurID).val(); + if (recurName == undefined || recurName == '') { + recurName = '(no schedule name)'; + } $('#recurCalendarDialog_' + recurID).attr('title', 'Select Dates for ' + recurName); $('#recurCalendarDialog_' + recurID).dialog({ @@ -528,8 +532,39 @@ timeFormat : 'h:mma', fixedWeekCount : false, dayClick: function(date, allDay, jsEvent, view) { - $(this).css('background-color', 'lightblue'); - } + c = $(this).css('background-color'); + var e = { + start: date, + title: 'New Date' + }; + if (c == 'transparent') { + $(this).css('background-color', 'lightblue'); + $('#recurSpecDates_' + recurID).append( + '' + date.format() + '' + ); + } else { + $('#recurSpecDate_' + recurID).remove(); + $(this).css('background-color', 'transparent'); + } + }, + viewRender:(function() { + + var lastViewName; + return function(view, element) { + + if(view.name === 'agendaDay' && lastViewName != view.name) { + + var newEvent = { + start: element.date, + title: 'My test meeting' + }; + $('#calendar').fullCalendar( 'renderEvent', newEvent); + } + + lastViewName = view.name; + } + })() + }); }); diff --git a/views/admin/events/editSchedule.html b/views/admin/events/editSchedule.html index efc3759..7950c66 100644 --- a/views/admin/events/editSchedule.html +++ b/views/admin/events/editSchedule.html @@ -4,7 +4,7 @@ @@ -155,7 +155,8 @@

Save

- Use to add specific dates to the schedule. Does not show other scheduled dates. + Use to add specific dates to the schedule. Does not show other scheduled dates.
+

@@ -321,7 +322,7 @@
- Add an Event Schedule + Add an Event Schedule
Select with Calendar
Show Calendar
-
+

Click on Dates to select/remove those dates for this schedule.

Done