From 2973497350b89f8f916c0e47191b3ab87bfc0765 Mon Sep 17 00:00:00 2001
From: Chuck Scott ";
// Make all arrays of arrays non-associative to make Backbone happy
if (is_array($regEvent['reg_class'])) {
@@ -422,6 +427,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
'regEvent' => $regEvent,
'haveRegEvent' => $haveRegEvent,
'haveRegEventRecurrences' => $haveRegEventRecurrences,
+ 'earliestDate' => $earliestDate,
'haveRegEventTimes' => $haveRegEventTimes,
'regEventFirstTime' => $regEventFirstTime,
'regEventLastTime' => $regEventLastTime,
diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php
index 12e059a..1ea17e0 100644
--- a/models/front/registrations/registration.php
+++ b/models/front/registrations/registration.php
@@ -150,30 +150,12 @@
switch ( $option ) {
default:
+
// Get the RegEvent entry
$this->postProcAddedEventData = true;
- $regEvent = $this->getEventConfig( $eventRegID, true, false, true );
-
- if ( $regEvent ) {
- if ( is_array( $regEvent['recurrences'] ) && count( $regEvent['recurrences'] ) ) {
- // Loop through all of the event recurrences to pull out times.
- foreach ($regEvent['recurrences'] as $k=>$v) {
- // Set the $first time.
- $first = current($v['times']);
- // Set the $last time
- $last = end($v['times']);
-
- // Pass first and last times into regEvent
- $regEvent['recurrences'][$k]['first_time'] = $first;
- $regEvent['recurrences'][$k]['lastTime'] = $last;
- if ($v['times'] && count($v['times']) > 0) {
- if (!$regEventFirstTime || ( isset( $regEventFirstTime['timestamp'] ) && $regEventFirstTime['timestamp'] < $first ) ) {
- $regEventFirstTime = $first;
- }
- }
- }
- }
- }
+ $regEvent = $this->getEventForRegistration($eventRegID);
+
+//echo "".print_r($this->regEventData,1)."
";
+ // echo "".print_r($this->regEventData,1)."
";
return $this->regEventData;
}
+ /**
+ * Check event for use with front-end registration
+ *
+ * Check that an event has enough data to support a registration for dates in the future.
+ *
+ * getEventConfig() must have been run first to get the event configuration
+ *
+ *
+ */
+ public function getEventForRegistration($regEventId = false)
+ {
+
+ // Get the event data
+ $this->getEventConfig($regEventId);
+//echo "".print_r($this->regEventData,1)."
";
+
+ // Make sure we have an event
+ if (!$this->regEventData) {
+ return false;
+ }
+
+ // Check if event is active or is active for admin users and user has members admin capability
+ $isActive = false;
+ if ( $this->regEventData['active']['value'] || ($this->regEventData['admin_active']['value'] && !apply_filters('glm_members_menu_members', false)) ) {
+ $isActive = true;
+ }
+ if (!$isActive) {
+ return false;
+ }
+
+ // If we don't have any time entries
+ if (!is_array($this->regEventData['reg_time']) || count($this->regEventData['reg_time']) == 0) {
+ return false;
+ }
+
+ // Check reg_time array
+ $timeSpecific = $this->regEventData['time_specific']['value'];
+ foreach ($this->regEventData['reg_time'] as $k=>$v) {
+
+ // if event is time specific
+ if ($timeSpecific) {
+
+ // Remove entry if it's not time specific or is in the past
+ if ($v['event_time'] == 0 || $v['start_datetime']['timestamp'] < time()) {
+ unset($this->regEventData['reg_time'][$k]);
+ }
+
+ // Otherwise event is non time specific
+ } else {
+
+ // Remove any time specific entries
+ if ($v['event_time'] > 0) {
+ unset($this->regEventData['reg_time'][$k]);
+ }
+
+ }
+
+ }
+
+ // If now we don't have any time entries
+ if (count($this->regEventData['reg_time']) == 0) {
+ return false;
+ }
+
+ // If it's too late to register for this event
+ if ($this->regEventData['lastTime']['start_time']['timestamp'] - time() < ($this->regEventData['reg_hours_before'] & 3600)) {
+ return false;
+ }
+
+ // Make sure we have classes (registration levels)
+ if (!is_array($this->regEventData['reg_class']) || count($this->regEventData['reg_class']) == 0) {
+ return false;
+ }
+
+ // For each class
+ foreach ($this->regEventData['reg_class'] as $ck=>$cv) {
+
+ // If we don't have any rates for this class, remove the class
+ if (!is_array($cv['reg_rate']) || count($cv['reg_rate']) == 0) {
+ unset($this->regEventData['reg_class'][$ck]);
+ } else {
+
+ $this->regEventData['reg_class'][$ck]['times'] = array();
+
+ // For each event time
+ foreach ($this->regEventData['reg_time'] as $tk=>$tv) {
+
+ // If event is time specific - rates days are per the selected time
+ if ($this->regEventData['time_specific']['value']) {
+
+ // If event time is for time-specific event (might be either mixed in)
+ if ($tv['event_time']) {
+
+ // Try to find a current rate for this time - within the start and end days before this time
+ foreach ($cv['reg_rate'] as $rk=>$rv) {
+
+ $earliestTime = strtotime(date('m/d/Y', $tv['start_datetime']['timestamp']).' -'.$rv['start_days'].' days');
+ $latestTime = strtotime(date('m/d/Y', $tv['start_datetime']['timestamp']).' -'.($rv['end_days']-1).' days');
+
+ // If it's time to register with this time/rate - Add it to the class data
+ if (time() > $earliestTime && time() < $latestTime) {
+ $this->regEventData['reg_class'][$ck]['times'][$tv['event_time']] = array_merge($tv, $rv);
+ }
+
+ }
+
+ }
+
+ // Otherwise for non time specific eventes - rate days are per the first event date
+ } else {
+
+ // If event time is for non time specific event (might be either mixed in)
+ if (!$tv['event_time']) {
+
+ }
+
+ }
+
+ } // each event time
+
+ } // Have rates for this class
+
+ // Drop the rate supplied rate data that's now merged with time and saved with the class.
+ unset($this->regEventData['reg_class'][$ck]['reg_rate']);
+
+ } // for each class
+
+ // Get rid of all of the recurrence data - No longer needed
+ unset($this->regEventData['recurrences']);
+
+ // Get rid of the provided reg_time entries
+ unset($this->regEventData['reg_time']);
+
+ // echo "".print_r($this->regEventData,1)."
";
+
+ return $this->regEventData;
+ }
+
/**
* Check times entries for event and add as needed
*
@@ -533,9 +734,6 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
$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);
@@ -554,30 +752,9 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
// 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['start_time']['timestamp'] > $first['start_time']['timestamp'] ) {
- $regEventFirstTime = $first;
- }
- if (!$regEventLastTime || $regEventLastTime['end_time']['timestamp'] < $last['end_time']['timestamp'] ) {
- $regEventLastTime = $last;
- }
-
// If this is a time specific event
if ($this->regEventData['time_specific']['value']) {
@@ -622,6 +799,7 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
'attendees_pending' => 0,
'attendees_available' => $this->regEventData['attendee_max'],
'total_base_charge' => 0,
+
'total_per_attendee' => 0,
'total_other' => 0,
'total_taxes' => 0,
@@ -655,23 +833,11 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
} // 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']) {
@@ -757,6 +923,8 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
}
+ // echo "
".print_r($this->regEventData,1)."
";
+
return $this->regEventData;
}
diff --git a/index.php b/index.php
index 43df332..201290c 100644
--- a/index.php
+++ b/index.php
@@ -44,7 +44,7 @@ if (!defined('ABSPATH')) {
* version from this plugin.
*/
define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION', '0.0.1');
-define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_VERSION', '0.0.13');
+define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_VERSION', '0.0.14');
// This is the minimum version of the GLM Members DB plugin require for this plugin.
define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.10.10');
diff --git a/js/adminRegApp.js b/js/adminRegApp.js
index c11370b..ef66a77 100644
--- a/js/adminRegApp.js
+++ b/js/adminRegApp.js
@@ -379,6 +379,8 @@ app.Views.Admin.RegEvent = Backbone.View.extend({
// js/views/regRate.js
+var calendar = false;
+
app.Views.Admin.RegRate = Backbone.View.extend({
tagName: 'div',
@@ -467,6 +469,9 @@ app.Views.Admin.RegRate = Backbone.View.extend({
glmSubmitRequired -= 1;
+ calendar.fullCalendar('destroy');
+
+
},
delete: function() {
@@ -510,8 +515,14 @@ app.Views.Admin.RegRate = Backbone.View.extend({
update: function() {
console.log('update called');
-
+
var formData = this.getInputData();
+
+ var datesError = this.checkDates(this.model, formData);
+ if (datesError != '') {
+ alert(datesError);
+ return false;
+ }
formData.option = 'update';
if (!this.model.save(
@@ -525,6 +536,8 @@ app.Views.Admin.RegRate = Backbone.View.extend({
this.$('.rate-edit-template').hide();
this.$('.rate-delete').show();
glmSubmitRequired -= 1;
+
+ calendar.fullCalendar('destroy');
},
@@ -549,9 +562,41 @@ app.Views.Admin.RegRate = Backbone.View.extend({
this.$('.rate-name').focus();
this.newRate = true;
glmSubmitRequired += 1;
-
+
}
return this;
+ },
+
+ checkDates: function(model, current) {
+
+ var datesError = '';
+
+ var cur = model.cid; // ID of current rate
+ var start = current.start_days;
+ var end = current.end_days;
+
+ if (start < end) {
+ datesError += 'Start days must be greater than end days. ';
+ } else {
+
+ // For each rate
+ Object.entries(model.collection.models).forEach(([key, value]) => {
+
+ // Don't compare with self
+ if (cur != value.cid) {
+
+ // If the sumbitted days overlap this rate
+ if ((end - value.attributes.start_days) * (value.attributes.end_days - start) >= 0) {
+ datesError += 'Days for this rate overlap another rate. Each rate must cover a separate days range';
+ }
+
+ }
+
+ });
+
+ }
+
+ return datesError;
}
});
diff --git a/js/views/admin/regRate.js b/js/views/admin/regRate.js
index 6efa350..8311adb 100644
--- a/js/views/admin/regRate.js
+++ b/js/views/admin/regRate.js
@@ -1,5 +1,7 @@
// js/views/regRate.js
+var calendar = false;
+
app.Views.Admin.RegRate = Backbone.View.extend({
tagName: 'div',
@@ -88,6 +90,9 @@ app.Views.Admin.RegRate = Backbone.View.extend({
glmSubmitRequired -= 1;
+ calendar.fullCalendar('destroy');
+
+
},
delete: function() {
@@ -131,8 +136,14 @@ app.Views.Admin.RegRate = Backbone.View.extend({
update: function() {
console.log('update called');
-
+
var formData = this.getInputData();
+
+ var datesError = this.checkDates(this.model, formData);
+ if (datesError != '') {
+ alert(datesError);
+ return false;
+ }
formData.option = 'update';
if (!this.model.save(
@@ -146,6 +157,8 @@ app.Views.Admin.RegRate = Backbone.View.extend({
this.$('.rate-edit-template').hide();
this.$('.rate-delete').show();
glmSubmitRequired -= 1;
+
+ calendar.fullCalendar('destroy');
},
@@ -170,9 +183,41 @@ app.Views.Admin.RegRate = Backbone.View.extend({
this.$('.rate-name').focus();
this.newRate = true;
glmSubmitRequired += 1;
-
+
}
return this;
+ },
+
+ checkDates: function(model, current) {
+
+ var datesError = '';
+
+ var cur = model.cid; // ID of current rate
+ var start = current.start_days;
+ var end = current.end_days;
+
+ if (start < end) {
+ datesError += 'Start days must be greater than end days. ';
+ } else {
+
+ // For each rate
+ Object.entries(model.collection.models).forEach(([key, value]) => {
+
+ // Don't compare with self
+ if (cur != value.cid) {
+
+ // If the sumbitted days overlap this rate
+ if ((end - value.attributes.start_days) * (value.attributes.end_days - start) >= 0) {
+ datesError += 'Days for this rate overlap another rate. Each rate must cover a separate days range';
+ }
+
+ }
+
+ });
+
+ }
+
+ return datesError;
}
});
diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php
index a5fa9c7..aa4736e 100644
--- a/models/admin/registrations/events.php
+++ b/models/admin/registrations/events.php
@@ -104,6 +104,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
$haveRegEvent = false;
$haveRegEventRecurrences = false;
$haveRegEventTimes = false;
+ $earliestDate = false;
$regEventFirstTime = false;
$regEventLastTime = false;
$regEventUpdated = false;
@@ -160,6 +161,10 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
// Get all current registration event data
$regEvent = $this->getEventConfig($regEventID, false, false, true);
+$re = $this->checkEventTimes();
+echo "".print_r($re['firstTime']['start_time']['timestamp'],1)."
";
+$earliestDate = date('m/d/y', $re['firstTime']['start_time']['timestamp']);
+echo "EarliestDate = $earliestDate".print_r($regEvent,1)."
";
// Create an $event array with the event data.
$event = array(
@@ -321,6 +303,8 @@
} // - End loop through events.
}
+ // echo '$regEvent: ' . print_r( $regEvent, true ) . '
';
+
// Compile template data
$templateData = array(
'haveCart' => $haveCart,
diff --git a/setup/databaseScripts/create_database_V0.0.13.sql b/setup/databaseScripts/create_database_V0.0.14.sql
similarity index 98%
rename from setup/databaseScripts/create_database_V0.0.13.sql
rename to setup/databaseScripts/create_database_V0.0.14.sql
index dd6a5b5..6d4e585 100644
--- a/setup/databaseScripts/create_database_V0.0.13.sql
+++ b/setup/databaseScripts/create_database_V0.0.14.sql
@@ -313,6 +313,7 @@ CREATE TABLE {prefix}reg_event (
attendee_max_per_reg TINYINT NULL, -- Maximum attendees per registration submission - 0 = unlimited
reg_hold_minutes MEDIUMINT NULL, -- Number of minutes hold time for an inactive cart before registrant count hold expires (after which cart attempts to hold again on next access)
cart_hold_days MEDIUMINT NULL, -- Number of days hold time for inactive cart before cart is purged
+ reg_hours_before MEDIUMINT NULL, -- Number of hours before an event that is the latest a registration may be submitted.
registration_account_options SMALLINT NULL, -- Bitmap of how user accounts may be used for this event - See registration_account_option in plugin.ini
payment_methods SMALLINT NULL, -- Bitmap of payment methods available to users for this event - See payment_method in plugin.ini
restricted_payment_methods SMALLINT NULL, -- Bitmap of restricted (admin use only) payment methods for this event - see payment_method
@@ -397,7 +398,7 @@ CREATE TABLE {prefix}reg_rate (
reg_event INT NULL, -- Pointer to reg_event table
reg_class INT NULL, -- Pointer to reg_class table
name TINYTEXT NULL, -- Namme of this rate
- start_days INT NULL, -- # of days before event time rate becomes available - may be entered as a date then coverted for storage
+ start_days INT NULL, -- # of days before event time rate becomes available - may be selected as a date then coverted for storage
end_days INT NULL, -- # of days before event time rate becomes unavailable
base_rate FLOAT, -- Base rate to register
per_registrant FLOAT, -- Rate per registrant
@@ -548,7 +549,6 @@ CREATE TABLE {prefix}reg_request_event (
CREATE TABLE {prefix}reg_request_class (
id INT NOT NULL AUTO_INCREMENT,
reg_event INT NULL, -- Pointer to reg_event entry
--- **** event_name TINYTEXT NULL, -- Name of Event so it will always be in the cart data
event_datetime DATETIME NULL, -- Date and time of event time selected so it will always be in the cart
reg_request INT NULL, -- Pointer to the registration request record
reg_request_event INT NULL, -- Pointer to reg_request_event table entry
@@ -569,7 +569,6 @@ CREATE TABLE {prefix}reg_request_class (
CREATE TABLE {prefix}reg_request_rate (
id INT NOT NULL AUTO_INCREMENT,
reg_event INT NULL, -- Pointer to reg_event entry
--- **** event_name TINYTEXT NULL, -- Name of Event so it will always be in the cart data
event_datetime DATETIME NULL, -- Date and time of event time selected so it will always be in the cart
reg_request INT NULL, -- Pointer to the registration request record
reg_request_event INT NULL, -- Pointer to reg_request_event table entry
@@ -595,7 +594,6 @@ CREATE TABLE {prefix}reg_request_registrant (
id INT NOT NULL AUTO_INCREMENT,
account INT NULL, -- Pointer to the account entry for the person being registered - False (0) if account no longer exists or registrant account not needed
reg_event INT NULL, -- Pointer to reg_event entry
--- **** event_name TINYTEXT NULL, -- Name of Event so it will always be in the cart data
reg_time INT NULL, -- Pointer reg_time entry
event_datetime DATETIME NULL, -- Date and time of event time selected so it will always be in the cart
reg_request INT NULL, -- Pointer to the registration request record
diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php
index 84e91bb..dcacaa2 100644
--- a/setup/databaseScripts/dbVersions.php
+++ b/setup/databaseScripts/dbVersions.php
@@ -26,7 +26,8 @@ $glmMembersRegistrationsDbVersions = array(
'0.0.10' => array('version' => '0.0.10', 'tables' => 20, 'date' => '04/25/2017'),
'0.0.11' => array('version' => '0.0.11', 'tables' => 20, 'date' => '04/29/2017'),
'0.0.12' => array('version' => '0.0.12', 'tables' => 20, 'date' => '09/11/2017'),
- '0.0.13' => array('version' => '0.0.13', 'tables' => 20, 'date' => '10/03/2017')
+ '0.0.13' => array('version' => '0.0.13', 'tables' => 20, 'date' => '10/03/2017'),
+ '0.0.14' => array('version' => '0.0.14', 'tables' => 20, 'date' => '10/13/2017')
);
diff --git a/setup/databaseScripts/drop_database_V0.0.13.sql b/setup/databaseScripts/drop_database_V0.0.14.sql
similarity index 100%
rename from setup/databaseScripts/drop_database_V0.0.13.sql
rename to setup/databaseScripts/drop_database_V0.0.14.sql
diff --git a/setup/databaseScripts/update_database_V0.0.14.sql b/setup/databaseScripts/update_database_V0.0.14.sql
new file mode 100644
index 0000000..870cd23
--- /dev/null
+++ b/setup/databaseScripts/update_database_V0.0.14.sql
@@ -0,0 +1,21 @@
+-- Gaslight Media Members Database - Registratiuons Add-On
+-- File Created: 10/03/17 11:00:00
+-- Database Version: 0.0.13
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+ALTER TABLE {prefix}reg_event ADD COLUMN reg_hours_before MEDIUMINT;
+
+----
+
+ALTER TABLE {prefix}reg_request_class DROP COLUMN event_name;
+
+----
+
+ALTER TABLE {prefix}reg_request_rate DROP COLUMN event_name;
+
+----
+
+ALTER TABLE {prefix}reg_request_registrant DROP COLUMN event_name;
diff --git a/views/admin/registrations/eventDashboard.html b/views/admin/registrations/eventDashboard.html
index 077016e..0da391c 100644
--- a/views/admin/registrations/eventDashboard.html
+++ b/views/admin/registrations/eventDashboard.html
@@ -70,7 +70,7 @@
{if $haveRegEvent}
Dates and Availability
*** NEED TO ADD POP-UP FOR EDITING OF MAX ATTENDEES AND ATTENDEE LIST FOR EACH DATE ***
Availability guide: (limit)-(registered)-(pending)-(available)
@@ -81,7 +81,7 @@ - {else} + {else}Event occurs every day from first day to last day at the times shown.
{$regEvent.fieldFail.cart_hold_days}
{/if}{$regEvent.fieldFail.reg_hours_before}
{/if}