Updated hook that provides a list of recurrences and times to other add-ons (registra...
authorChuck Scott <cscott@gaslightmedia.com>
Mon, 9 Oct 2017 15:33:35 +0000 (11:33 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Mon, 9 Oct 2017 15:33:35 +0000 (11:33 -0400)
classes/data/dataRecurrences.php
classes/data/dataTimes.php
setup/commonHooks.php

index 74fa8f2..89e20c9 100644 (file)
@@ -566,11 +566,12 @@ class GlmDataEventsRecurrences extends GlmDataAbstract
      * Get recurances along with all times entries for a particular event ID
      *
      * @param integer $eventID Event ID
+     * @param boolean $allTimes Flag to get all times entries for the event, not just current and future
      *
      * @return object Class object
      *
      */
-    public function getRecurWithTimes($eventID)
+    public function getRecurWithTimes($eventID, $allTimes = false)
     {
 
         // Check for positive integer event ID
@@ -579,6 +580,14 @@ class GlmDataEventsRecurrences extends GlmDataAbstract
             return false;
         }
 
+        // By setting fromDate to false by default we're telling getEventTimesByRecurrenceSimplified() to provide only future times.
+        $fromDate = false;
+
+        // If all times are requested, set $fromTime to our time epoch.
+        if ($allTimes) {
+            $fromDate = date('Y-m-d H:i:s', 0);
+        }
+
         // Get all recurrences
         $recurrences = $this->getList("T.event = $eventID", 'start_time');
 
@@ -587,7 +596,7 @@ class GlmDataEventsRecurrences extends GlmDataAbstract
             foreach ($recurrences as $k=>$v) {
                 require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataTimes.php';
                 $Times = new GlmDataEventsTimes($this->wpdb, $this->config);
-                $recurrences[$k]['times'] = $Times->getEventTimesByRecurrenceSimplified($v['id']);
+                $recurrences[$k]['times'] = $Times->getEventTimesByRecurrenceSimplified($v['id'], $fromDate);
             }
         }
 
index ed2fb97..cd6433d 100644 (file)
@@ -310,7 +310,10 @@ class GlmDataEventsTimes extends GlmDataAbstract
 
         // Only display times from startDate to endDate
         if (!$startDate) {
+
+            // With no start time supplied, only supply times from today forward.
             $startDate = date('Y-m-d H:i:s');
+
         }
         $where .= " AND T.start_time >= '$startDate' ";
         if ($endDate) {
index 3d8b2b2..ade13d9 100644 (file)
@@ -48,7 +48,7 @@ add_filter( 'glm-member-db-events-get-event-times', function( $eventID ){
     // Get any schedules and times for this event
     require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php';
     $RecurrenceData = new GlmDataEventsRecurrences($this->wpdb, $this->config);
-    $recurrences = $RecurrenceData->getRecurWithTimes($eventId);
+    $recurrences = $RecurrenceData->getRecurWithTimes($eventId, true);
 
     return $recurrences;