Storing of times now working again after recurrences updates.
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 8 Apr 2016 17:02:34 +0000 (13:02 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 8 Apr 2016 17:02:34 +0000 (13:02 -0400)
classes/data/dataRecurrences.php
views/admin/events/edit.html
views/admin/events/editSchedule.html

index 6c3e3c5..7af7a69 100644 (file)
@@ -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;
     }
 
-
-
-
 }
 
 ?>
index 9eb0c36..af6af07 100644 (file)
                 // 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({
                         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(
+                                    '<span id="recurSpecDate_' + recurID + '" class="button glm-button-small"><input name="recurSpecDate_' + recurID + '" type="hidden" value="' + date.format() + '">' + date.format() + '</span>'
+                                );
+                            } 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;
+                            }
+                        })()
+                        
                     });
                 });
                 
index efc3759..7950c66 100644 (file)
@@ -4,7 +4,7 @@
 <table id="glm-table-recurrence" class="glm-admin-table glm-hidden glm-event-table">
     <tr>
         <td id="placeRecurDeletesHere" colspan="2">
-            <a id="addRecurrence" class="button button-secondary glm-button glm-right">Add an Event Schedule</a>
+            <a id="addRecurrence" class="button button-secondary glm-button">Add an Event Schedule</a>
         </td>
     </tr>
     <tr>
                                             <div id="recurCalendar_{$r.id}"></div>
                                             <p><div data-id="closeRecurCalendar_{$r.id}" class="button button-primary glm-set-none glm-right">Save</div></p>
                                         </div>
-                                        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.<br>
+                                        <p><span id="recurSpecDates_{$r.id}"></span></p>
                                     </td>
                                 </tr>
                             </tbody>
                         <th>Select with Calendar</th>
                         <td>
                             <div data-id="{ newRecurID }" class="button glm-button-small glm-set-none recur-calendar">Show Calendar</div>
-                            <div id="recurCalendarDialog_{ newRecurID }}" class="glm-dialog-box" title="">
+                            <div id="recurCalendarDialog_{ newRecurID }" class="glm-dialog-box" title="">
                                 <p>Click on Dates to select/remove those dates for this schedule.</p>
                                 <div id="recurCalendar_{ newRecurID }"></div>
                                 <div data-id="closeRecurCalendar_{ newRecurID }" class="button button-primary glm-set-none">Done</div>