Added hook to permit registrations or other add-on to get more detail on recurrencces...
authorChuck Scott <cscott@gaslightmedia.com>
Mon, 28 Aug 2017 19:10:11 +0000 (15:10 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Mon, 28 Aug 2017 19:10:11 +0000 (15:10 -0400)
Fixed incorrect check to see if the hook that permits other add-ons to add an action button to the event list returned any data.

classes/data/dataRecurrences.php
classes/data/dataTimes.php
setup/adminHooks.php
views/admin/events/list.html

index e85fb77..fefcce7 100644 (file)
@@ -561,6 +561,39 @@ class GlmDataEventsRecurrences extends GlmDataAbstract
 
         return $timesData;
     }
+    
+    /**
+     * Get recurances along with all times entries for a particular event ID
+     *
+     * @param integer $eventID Event ID
+     *
+     * @return object Class object
+     *
+     */
+    public function getRecurWithTimes($eventID)
+    {
+        
+        // Check for positive integer event ID
+        $eventID = ($eventID-0);
+        if ($eventID == 0) {
+            return false;
+        }
+        
+        // Get all recurrences
+        $recurrences = $this->getList("T.event = $eventID", 'start_time');
+
+        // If we have recurrences, try to get times for each
+        if ($recurrences) {
+            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']);
+            }
+        }
+    
+        return $recurrences;
+        
+    }
 
 }
 
index 8367a0f..5f45881 100644 (file)
@@ -283,6 +283,49 @@ class GlmDataEventsTimes extends GlmDataAbstract
 
     }
 
+    /**
+     * Get event times simplified by Recurrence
+     * This returns less data than the function above because it's already
+     * known what the event and recurrence is.
+     *
+     * @param integer $recurrenceID ID of recurrence
+     * @param string $startDate Date formatted to be used in MySQL - optional
+     * @param string $endDate Date formatted to be used in MySQL - optional
+     *
+     * @return object Class object
+     */
+    public function getEventTimesByRecurrenceSimplified($recurrenceID = false, $startDate = false, $endDate = false)
+    {
+        
+        $savedFields = $this->fields;
+        
+        $this->fields = array(
+            'id' => $savedFields['id'],
+            'start_time' => $savedFields['start_time'],
+            'end_time' => $savedFields['end_time'],
+            'all_day' => $savedFields['all_day']
+        );
+        
+        $where = " T.recur_id = $recurrenceID ";
+        
+        // Only display times from startDate to endDate
+        if (!$startDate) {
+            $startDate = date('Y-m-d H:i:s');
+        }
+        $where .= " AND T.start_time >= '$startDate' ";
+        if ($endDate) {
+            $where .= " AND T.start_time <= '$endDate' ";
+        }
+        
+        $timesSimplified = $this->getList($where, 'start_time');
+
+        $this->fields = $savedFields;
+        
+        return $timesSimplified;
+        
+    }
+    
+    
 }
 
 ?>
index a8795d5..3896b8b 100644 (file)
@@ -84,6 +84,7 @@ add_filter( 'glm-member-db-events-get-event', function( $eventID ){
     return $eventId;
 
 } );
+
 if (isset($this->config['loggedInUser']) && isset($this->config['loggedInUser']['contactUser']) && $this->config['loggedInUser']['contactUser']) {
     // check the settings to see if members are allow to manage events
     $memberEventsAllowed = isset( $this->config['settings']['member_events_allowed'] )
@@ -113,6 +114,35 @@ if ( $memberEventsAllowed ) {
     );
 }
 
+// Add hook to return event recurrences and times data for a specific event ID
+add_filter( 'glm-member-db-events-get-event-times', function( $eventID ){
+    
+    // Check for positive integer event ID
+    $eventId = ($eventID-0);
+    if ($eventId == 0) {
+        return $eventID;
+    }
+    
+    // Call dedicated model to get event base data
+    require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataEvents.php';
+    $EventData = new GlmDataEvents($this->wpdb, $this->config);
+    $eventData = $EventData->getEntry($eventId);
+    
+    // If we didn't get a good event, just pass on supplied data
+    if (!$eventData) {
+        return $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);
+   
+    return $recurrences;
+    
+} );
+    
+
 
 
 /*
index 67b53b5..a34f5bb 100644 (file)
                     <td class="glm-nowrap">
                         {$e.status.name}
                     </td>
-                    <td>
+                    <td>                             
                         {$e.firstDate}
                     </td>
                     <td>
-                        {$e.lastDate}
+                       {$e.lastDate}
                     </td>
                     <td>
                         <a class="button button-secondary glm-button-small" href="{$thisUrl}?page=glm-members-admin-menu-events-list&glm_action=list&member={$memberID}&option=clone&event={$e.id}">Clone</a>
                     </td>
                     <td>
                         <a class="button button-secondary glm-button-small" href="{$siteBaseUrl}event-detail/{$e.name_slug}/" target="_blank">View Event</a>
-                                               <!-- Filter to pick up buttons from other add-ons - $e_link expects array( 'title' => 'some title', 'url' => 'some url' ) -->                        
-                                               {$e_link = apply_filters('glm_members_add_link_to_event_list_entry', $e.id)}
-                                               {if $e_link}
-                                                       <a class="button button-secondary glm-button-small" href="{$e_link.url|escape:'string'}">{$e_link.title}</a>
-                                               {/if}
+                        {$e_link = apply_filters('glm_members_add_link_to_event_list_entry', $e.id)}
+                         {if is_array($e_link)}
+                            <a class="button button-secondary glm-button-small" href="{$e_link.url|escape:'string'}">{$e_link.title}</a>
+                         {/if}
                     </td>
                 </tr>
         {/foreach}
         });
     </script>
 
-
+          
 {include file='admin/footer.html'}