From: Chuck Scott Date: Mon, 28 Aug 2017 19:10:11 +0000 (-0400) Subject: Added hook to permit registrations or other add-on to get more detail on recurrencces... X-Git-Tag: v1.6.61^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=cb1c5accba2453ef40d9d9fda5413e1331a7aa78;p=WP-Plugins%2Fglm-member-db-events.git Added hook to permit registrations or other add-on to get more detail on recurrencces and times for an event 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. --- diff --git a/classes/data/dataRecurrences.php b/classes/data/dataRecurrences.php index e85fb77..fefcce7 100644 --- a/classes/data/dataRecurrences.php +++ b/classes/data/dataRecurrences.php @@ -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; + + } } diff --git a/classes/data/dataTimes.php b/classes/data/dataTimes.php index 8367a0f..5f45881 100644 --- a/classes/data/dataTimes.php +++ b/classes/data/dataTimes.php @@ -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; + + } + + } ?> diff --git a/setup/adminHooks.php b/setup/adminHooks.php index a8795d5..3896b8b 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -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; + +} ); + + /* diff --git a/views/admin/events/list.html b/views/admin/events/list.html index 67b53b5..a34f5bb 100644 --- a/views/admin/events/list.html +++ b/views/admin/events/list.html @@ -108,22 +108,21 @@ {$e.status.name} - + {$e.firstDate} - {$e.lastDate} + {$e.lastDate} Clone View Event - - {$e_link = apply_filters('glm_members_add_link_to_event_list_entry', $e.id)} - {if $e_link} - {$e_link.title} - {/if} + {$e_link = apply_filters('glm_members_add_link_to_event_list_entry', $e.id)} + {if is_array($e_link)} + {$e_link.title} + {/if} {/foreach} @@ -221,5 +220,5 @@ }); - + {include file='admin/footer.html'}