* @access public
*/
public $table;
+ /**
+ * Event Data Array
+ *
+ * @var $regEventData
+ * @access public
+ */
+ public $regEventData = false;
/**
* Field definitions
*
// 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;
}
}
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;
+ }
}
;";
$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.";
}
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'];
}