From: Chuck Scott Date: Mon, 9 Oct 2017 15:31:57 +0000 (-0400) Subject: Now checking for updates to reg event times entries when a reg event is added. X-Git-Tag: v1.0.0^2~368 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=268a0a386b06f1eb1c54d546af6c16bccbb3422b;p=WP-Plugins%2Fglm-member-db-registrations.git Now checking for updates to reg event times entries when a reg event is added. Fixed issues with times not being included if they are earlier than today. Fixed issue with cart link widget not properly detecting if there is no cart. --- diff --git a/classes/data/dataRegEvent.php b/classes/data/dataRegEvent.php index 3c86c00..23df53d 100644 --- a/classes/data/dataRegEvent.php +++ b/classes/data/dataRegEvent.php @@ -48,6 +48,13 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract * @access public */ public $table; + /** + * Event Data Array + * + * @var $regEventData + * @access public + */ + public $regEventData = false; /** * Field definitions * @@ -465,8 +472,8 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract // Try to get the base information - and extended data from the Event add-on if requested if ($id > 0) { - $eventData = $this->getEntry($id, 'id', ' TRUE ', $forEdit); - if (!$eventData) { + $this->regEventData = $this->getEntry($id, 'id', ' TRUE ', $forEdit); + if (!$this->regEventData) { return false; } } @@ -475,43 +482,274 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegTime.php'; $RegTime = new GlmDataRegistrationsRegTime($this->wpdb, $this->config); // If this is a time specific event, then get all times except any default entry that might be there from the event having been a non-time_specific event - if ($eventData['time_specific']['value']) { - $eventData['reg_time'] = $RegTime->getList('T.reg_event = '.$eventData['id'].' AND T.event_time > 0', 'start_datetime', true); + if ($this->regEventData['time_specific']['value']) { + $this->regEventData['reg_time'] = $RegTime->getList('T.reg_event = '.$this->regEventData['id'].' AND T.event_time > 0', 'start_datetime', true); // Otherwise if this is a non-time_specific event, we only want the default entry } else { - $eventData['reg_time'] = $RegTime->getList('T.reg_event = '.$eventData['id'].' AND T.event_time = 0', 'start_datetime', true); + $this->regEventData['reg_time'] = $RegTime->getList('T.reg_event = '.$this->regEventData['id'].' AND T.event_time = 0', 'start_datetime', true); } // Get all reg_class records for this event require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegClass.php'; $RegClass = new GlmDataRegistrationsRegClass($this->wpdb, $this->config); - $eventData['reg_class'] = $RegClass->getList("T.reg_event = ".$eventData['id'], 'name', true); + $this->regEventData['reg_class'] = $RegClass->getList("T.reg_event = ".$this->regEventData['id'], 'name', true); // If we have any reg_class results - if ($eventData['reg_class']) { + if ($this->regEventData['reg_class']) { // Get all reg_rate records for this reg_class require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRate.php'; $RegRate = new GlmDataRegistrationsRegRate($this->wpdb, $this->config); - foreach ($eventData['reg_class'] as $k=>$v) { - $eventData['reg_class'][$k]['reg_rate'] = $RegRate->getList("T.reg_class = ".$v['id'], 'start_days', true); + foreach ($this->regEventData['reg_class'] as $k=>$v) { + $this->regEventData['reg_class'][$k]['reg_rate'] = $RegRate->getList("T.reg_class = ".$v['id'], 'start_days', true); } } - // If recurrence data is requested and registration for this event is date/time specific - Get recurrence and times data - $eventData['recurrences'] = array(); - $eventData['recurrences'] = apply_filters('glm-member-db-events-get-event-times', $eventData['event']); + // Get recurrence data from the event add-on + $this->regEventData['recurrences'] = apply_filters('glm-member-db-events-get-event-times', $this->regEventData['event']); // Restore status of extended data flag $this->postProcAddedEventData = $saveExtended; - return $eventData; + return $this->regEventData; } + /** + * Check times entries for event and add as needed + * + * This function checks the event recurrence data to determine if all recurrence times have matching reg_times entries. + * The getEventConfig() method must have been called first or a reg_event ID must be passed so that we have all of the needed event data. + * + * @param integer $regEventId Optional ID of a reg event record. If provided, load all registration data using getEventConfig() above + * + * @return array updated reg_times data or false if not regEventData has been provided or no recurrence data + */ + public function checkEventTimes($regEventId = false) + { + + $needTimesReloaded = false; + $regEventFirstTime = false; + $regEventLastTime = false; + + // If we've been passed a reg event id, get the configuration + if ($regEventId && $regEventId > 0) { + $this->getEventConfig($regEventId); + } + + // If we don't have event data + if ($this->regEventData == false) { + return false; + } + + // If we don't have recurrences for the event + if (!is_array($this->regEventData['recurrences']) || count($this->regEventData['recurrences']) == 0) { + return false; + } + + // For each recurrence + foreach ($this->regEventData['recurrences'] as $k=>$v) { + + $this->regEventData['recurrences'][$k]['haveTimes'] = false; + + // If we have times for this recurrence + if ($v['times'] && count($v['times']) > 0) { + + $this->regEventData['recurrences'][$k]['haveTimes'] = false; + $haveRegEventTimes = true; + + // Get the first and last event date/time + $first = current($v['times']); + $last = end($v['times']); + + $this->regEventData['recurrences'][$k]['first_time'] = $first; + $this->regEventData['recurrences'][$k]['lastTime'] = $last; + + // Set event first and last times + if (!$regEventFirstTime || $regEventFirstTime['timestamp'] < $first ) { + $regEventFirstTime = $first; + } + if (!$regEventLastTime || $regEventLastTime['timestamp'] > $last ) { + $regEventLastTime = $last; + } + + // If this is a time specific event + if ($this->regEventData['time_specific']['value']) { + + // Check all event times for matching reg event times + foreach ($v['times'] as $tk=>$tv) { + + // Check if time already exists in reg_times array + reset($this->regEventData['reg_time']); + foreach($this->regEventData['reg_time'] as $rk=>$rv) { + if ($rv['event_time'] == $tk) { + $id = $rk; + break; + } + } + + // If it doesn't now, then add it + if (!$id) { + + $needTimesReloaded = true; + + $sTime = date('Y-m-d H:i:s',strtotime($tv['start_time']['datetime'])); + $eTime = date('Y-m-d H:i:s',strtotime($tv['end_time']['datetime'])); + + // Add reg event time + $this->wpdb->insert( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time", + array( + 'reg_event' => $this->regEventData['id'], + 'event_time' => $tk, + 'start_datetime' => $sTime, + 'end_datetime' => $eTime, + 'all_day' => $tv['all_day']['value'], + 'attendees' => $this->regEventData['attendees']['value'], + 'attendee_max' => $this->regEventData['attendee_max'], + 'attendee_count' => 0, + 'attendees_pending' => 0, + 'attendees_available' => $this->regEventData['attendee_max'], + 'total_base_charge' => 0, + 'total_per_attendee' => 0, + 'total_other' => 0, + 'total_taxes' => 0, + 'total_charges' => 0, + 'total_discounts' => 0, + 'total_payments' => 0 + ), + array( + '%d', // reg_event + '%d', // event_time record ID + '%s', // start_datetime + '%s', // end_datetime + '%d', // all_day flag + '%d', // attendees flag + '%d', // attendee_max + '%d', // attendee_count + '%d', // attendees_pending + '%d', // attendees_available + '%f', // total_base__charge + '%f', // total_per_attendee + '%f', // total_other + '%f', // total_taxes + '%f', // total_charges + '%f', // total_discounts + '%f' // total_payments + ) + ); + + } // If time isn't in reg_times + } // each recurrence times + } // time specific + } // have times for recurrence + + $recurrenceSummary[] = array( + 'firstTime' => $first, + 'lastTime' => $last + ); + + } // each recurrence + + // Save First and Last times for the entire event + $this->regEventData['firstTime'] = $regEventFirstTime; + $this->regEventData['lastTime'] = $regEventLastTime; + + // Get rid of all of the recurrence data - No longer needed + unset($this->regEventData['recurrences']); + + // Add Recurrence summary to event data + $this->regEventData['recurrenceSummary'] = $recurrenceSummary; + + // If not time specific + if (!$this->regEventData['time_specific']['value']) { + + // Do we have default reg_time entry? (event_time is 0) + $defTime = false; + if (is_array($this->regEventData['reg_time'])) { + + // Is there's a default entry for not time specific event? (might be others if time_specific had been selected before - they might switch back) + $defTime = false; + foreach($this->regEventData['reg_time'] as $r) { + + if ($r['event_time'] == 0) { + $defTime = $r; + break; + } + } + + // Get rid of other time entries and just use this one + if ($defTime !== false) { + $this->regEventData['reg_time'] = array(); + $this->regEventData['reg_time'][0] = $defTime; + } + } + + // If no default time, create one now. + if (!$defTime) { + + $this->wpdb->insert( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time", + array( + 'reg_event' => $this->regEventData['id'], + 'event_time' => 0, + 'start_datetime' => NULL, + 'end_datetime' => NULL, + 'all_day' => false, + 'attendees' => $this->regEventData['attendees']['value'], + 'attendee_max' => $this->regEventData['attendee_max'], + 'attendee_count' => 0, + 'attendees_pending' => 0, + 'attendees_available' => $this->regEventData['attendee_max'], + 'total_base_charge' => 0, + 'total_per_attendee' => 0, + 'total_other' => 0, + 'total_taxes' => 0, + 'total_charges' => 0, + 'total_discounts' => 0, + 'total_payments' => 0 + ), + array( + '%d', // reg_event + '%d', // event_time record ID + '%s', // start_datetime + '%s', // end_datetime + '%d', // all_day flag + '%d', // attendees flag + '%d', // attendee_max + '%d', // attendee_count + '%d', // attendees_pending + '%d', // attendees_available + '%f', // total_base__charge + '%f', // total_per_attendee + '%f', // total_other + '%f', // total_taxes + '%f', // total_charges + '%f', // total_discounts + '%f' // total_payments + ) + ); + + + } // no default time + + } // not times specific + + // Check if we need the times entries reloaded + if ($needTimesReloaded) { + + // Get all reg_time records for this event + require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegTime.php'; + $RegTime = new GlmDataRegistrationsRegTime($this->wpdb, $this->config); + $this->regEventData['reg_time'] = $RegTime->getList('T.reg_event = '.$regEventID, 'start_datetime', true); + + } + + return $this->regEventData; + } } diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index eff017f..49a36ae 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -251,13 +251,18 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent ;"; $this->wpdb->query($sql); $regEventID = $this->wpdb->insert_id; - if ($regEventID) { + $regEventUpdated = true; + + // Create all needed reg_time entries + $this->checkEventTimes($regEventID); + } } + } else { $reason = "Trying to add an event that is already listed in Registrations."; } @@ -299,227 +304,14 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent case 'eventDashboard': - $needTimesReloaded = false; - - // If we have an event ID - if ($regEventID) { - - // Try to get the event configuration including recurrences and times - $this->postProcAddedEventData = true; - $regEvent = $this->getEventConfig($regEventID, true, false, true); - - // If we have the event data - if ($regEvent) { - - $haveRegEvent = true; - $recurrenceSummary = array(); - - // If we have recurrences for the event - if (is_array($regEvent['recurrences']) && count($regEvent['recurrences']) > 0) { - - $haveRegEventRecurrences = true; - - // For each recurrence - foreach ($regEvent['recurrences'] as $k=>$v) { - - $regEvent['recurrences'][$k]['haveTimes'] = false; - - // If we have times for this recurrence - if ($v['times'] && count($v['times']) > 0) { - - $regEvent['recurrences'][$k]['haveTimes'] = false; - $haveRegEventTimes = true; - - // Get the first event date/time - $first = current($v['times']); - $last = end($v['times']); - $regEvent['recurrences'][$k]['first_time'] = $first; - $regEvent['recurrences'][$k]['lastTime'] = $last; - - // Set event first and last times - if (!$regEventFirstTime || $regEventFirstTime['timestamp'] < $first ) { - $regEventFirstTime = $first; - } - if (!$regEventLastTime || $regEventLastTime['timestamp'] > $last ) { - $regEventLastTime = $last; - } - - // If this is a time specific event - if ($regEvent['time_specific']['value']) { - - // Check all event times for matching reg event times - foreach ($v['times'] as $tk=>$tv) { - - // Check if time already exists in reg_times array - reset($regEvent['reg_time']); - foreach($regEvent['reg_time'] as $rk=>$rv) { - if ($rv['event_time'] == $tk) { - $id = $rk; - break; - } - } - - // If it doesn't now, then add it - if (!$id) { - - $needTimesReloaded = true; - - $sTime = date('Y-m-d H:i:s',strtotime($tv['start_time']['datetime'])); - $eTime = date('Y-m-d H:i:s',strtotime($tv['end_time']['datetime'])); - - // Add reg event time - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time", - array( - 'reg_event' => $regEvent['id'], - 'event_time' => $tk, - 'start_datetime' => $sTime, - 'end_datetime' => $eTime, - 'all_day' => $tv['all_day']['value'], - 'attendees' => $regEvent['attendees']['value'], - 'attendee_max' => $regEvent['attendee_max'], - 'attendee_count' => 0, - 'attendees_pending' => 0, - 'attendees_available' => $regEvent['attendee_max'], - 'total_base_charge' => 0, - 'total_per_attendee' => 0, - 'total_other' => 0, - 'total_taxes' => 0, - 'total_charges' => 0, - 'total_discounts' => 0, - 'total_payments' => 0 - ), - array( - '%d', // reg_event - '%d', // event_time record ID - '%s', // start_datetime - '%s', // end_datetime - '%d', // all_day flag - '%d', // attendees flag - '%d', // attendee_max - '%d', // attendee_count - '%d', // attendees_pending - '%d', // attendees_available - '%f', // total_base__charge - '%f', // total_per_attendee - '%f', // total_other - '%f', // total_taxes - '%f', // total_charges - '%f', // total_discounts - '%f' // total_payments - ) - ); - - } // If time isn't in reg_times - } // each recurrence times - } // time specific - } // have times for recurrence - - $recurrenceSummary[] = array( - 'firstTime' => $regEventFirstTime, - 'lastTime' => $regEventLastTime - ); - - } // each recurrence - - // Get rid of all of the recurrence data - No longer needed - unset($regEvent['recurrences']); - - // Add Recurrence summary to event data - $regEvent['recurrenceSummary'] = $recurrenceSummary; - - // If not time specific - if (!$regEvent['time_specific']['value']) { - - // Do we have default reg_time entry? (event_time is 0) - $defTime = false; - if (is_array($regEvent['reg_time'])) { - - // Is there's a default entry for not time specific event? (might be others if time_specific had been selected before - they might switch back) - $defTime = false; - foreach($regEvent['reg_time'] as $r) { - - if ($r['event_time'] == 0) { - $defTime = $r; - break; - } - } - - // Get rid of other time entries and just use this one - if ($defTime !== false) { - $regEvent['reg_time'] = array(); - $regEvent['reg_time'][0] = $defTime; - } - - } - - // If no default time, create one now. - if (!$defTime) { - - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time", - array( - 'reg_event' => $regEvent['id'], - 'event_time' => 0, - 'start_datetime' => NULL, - 'end_datetime' => NULL, - 'all_day' => false, - 'attendees' => $regEvent['attendees']['value'], - 'attendee_max' => $regEvent['attendee_max'], - 'attendee_count' => 0, - 'attendees_pending' => 0, - 'attendees_available' => $regEvent['attendee_max'], - 'total_base_charge' => 0, - 'total_per_attendee' => 0, - 'total_other' => 0, - 'total_taxes' => 0, - 'total_charges' => 0, - 'total_discounts' => 0, - 'total_payments' => 0 - ), - array( - '%d', // reg_event - '%d', // event_time record ID - '%s', // start_datetime - '%s', // end_datetime - '%d', // all_day flag - '%d', // attendees flag - '%d', // attendee_max - '%d', // attendee_count - '%d', // attendees_pending - '%d', // attendees_available - '%f', // total_base__charge - '%f', // total_per_attendee - '%f', // total_other - '%f', // total_taxes - '%f', // total_charges - '%f', // total_discounts - '%f' // total_payments - ) - ); - - - } - - } // not time specific - - } else { // no recurrences - $reaon[] = 'Event has no recurrence data!'; - } - - } // have event data - - } else { - $reason = 'Unable to load registration event data or registration event not selected.'; - } + $regEvent = $this->getEventConfig($regEventID, true, false, true); + $regEvent = $this->checkEventTimes(); - // Check if we need the times entries reloaded - if ($needTimesReloaded) { + if ($regEvent !== false) { - // Get all reg_time records for this event - require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegTime.php'; - $RegTime = new GlmDataRegistrationsRegTime($this->wpdb, $this->config); - $regEvent['reg_time'] = $RegTime->getList('T.reg_event = '.$regEventID, 'start_datetime', true); + $haveRegEvent = true; + $regEventFirstTime = $regEvent['firstTime']; + $regEventLastTime = $regEvent['lastTime']; } diff --git a/models/front/registrations/cartLinkWidget.php b/models/front/registrations/cartLinkWidget.php index 2bacefc..4951de7 100644 --- a/models/front/registrations/cartLinkWidget.php +++ b/models/front/registrations/cartLinkWidget.php @@ -83,7 +83,7 @@ class GlmMembersFront_registrations_cartLinkWidget $cartData = apply_filters('glm_members_registrations_cart_summary_data', false, false); - if (is_array($cartData)) { + if (is_array($cartData) && $cartData['status']) { $haveCart = true; } @@ -94,6 +94,7 @@ class GlmMembersFront_registrations_cartLinkWidget //echo "
".print_r($templateData,1)."
"; $view = 'cartLinkWidget'; +echo "
".print_r($cartData,1).print_r($haveCart,1)."
"; // Return status, any suggested view, and any data to controller return array( diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 9e95a53..08fd77e 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -53,6 +53,12 @@ add_filter( $RegCartSupport = new GlmRegCartSupport($this->wpdb, $this->config); $regCartSummary = $RegCartSupport->regCartSummary(); + if (!is_array($regCartSummary)) { + $regCartSummary = array('status' => false); + } else { + $regCartSummary['status'] = true; + } + // Add in the current link url for the cart page $regCartSummary['cartUrl'] = GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/?page=cart'; diff --git a/views/front/registrations/cartLinkWidget.html b/views/front/registrations/cartLinkWidget.html index cc3eb70..a80d598 100644 --- a/views/front/registrations/cartLinkWidget.html +++ b/views/front/registrations/cartLinkWidget.html @@ -16,7 +16,9 @@ {else} -

No current cart

+
+

No current cart

+
{/if}