From 56695eb72b973e56d310b50eaad17b9db19b338b Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 16 Nov 2017 12:35:40 -0500 Subject: [PATCH] Fixed issues with regirants having times that were no longer available. Now have checkRegistrationRequest() in regCartSuuport.php checking for registrants for whom their selected time has been rmoved from the event. Now have checkEventTimes() in dataRegEvent.php checking for registration times that have been removed from the event. Fixed issue with gulp breaking (ask Steve, it's his stuff). Added message output to the admin event dashboard when times are added or removed due to changes in an event. Added message output check to event dashboard view. --- classes/data/dataRegEvent.php | 81 +++++++++++++------ classes/regCartSupport.php | 11 ++- gulpfile.js | 11 +-- js/frontRegApp.js | 5 +- js/models/front/regEvent.js | 5 +- models/admin/registrations/events.php | 18 +++-- models/front/registrations/registration.php | 1 + views/admin/registrations/eventDashboard.html | 17 ++-- 8 files changed, 103 insertions(+), 46 deletions(-) diff --git a/classes/data/dataRegEvent.php b/classes/data/dataRegEvent.php index f1b701d..bc41be2 100644 --- a/classes/data/dataRegEvent.php +++ b/classes/data/dataRegEvent.php @@ -572,19 +572,19 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract } // For each recurrence - foreach ($this->regEventData['recurrences'] as $k=>$v) { + foreach ($this->regEventData['recurrences'] as $recurKey=>$recurVal) { - $this->regEventData['recurrences'][$k]['haveTimes'] = false; + $this->regEventData['recurrences'][$recurKey]['haveTimes'] = false; // If we have times for this recurrence - if ($v['times'] && count($v['times']) > 0) { + if ($recurVal['times'] && count($recurVal['times']) > 0) { // Get the first and last event date/time - $first = current($v['times']); - $last = end($v['times']); + $first = current($recurVal['times']); + $last = end($recurVal['times']); - $this->regEventData['recurrences'][$k]['first_time'] = $first; - $this->regEventData['recurrences'][$k]['lastTime'] = $last; + $this->regEventData['recurrences'][$recurKey]['first_time'] = $first; + $this->regEventData['recurrences'][$recurKey]['lastTime'] = $last; // Set event first and last times if (!$regEventFirstTime || $regEventFirstTime['start_time']['timestamp'] > $first['start_time']['timestamp'] ) { @@ -679,22 +679,22 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract // Check reg_time array $timeSpecific = $this->regEventData['time_specific']['value']; - foreach ($this->regEventData['reg_time'] as $k=>$v) { + foreach ($this->regEventData['reg_time'] as $timeKey=>$timeVal) { // 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]); + if ($timeVal['event_time'] == 0 || $timeVal['start_datetime']['timestamp'] < time()) { + unset($this->regEventData['reg_time'][$timeKey]); } // Otherwise event is non time specific } else { // Remove any time specific entries - if ($v['event_time'] > 0) { - unset($this->regEventData['reg_time'][$k]); + if ($timeVal['event_time'] > 0) { + unset($this->regEventData['reg_time'][$timeKey]); } } @@ -824,6 +824,7 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract { $needTimesReloaded = false; + $message = ''; // If we've been passed a reg event id, get the configuration (with recurrence data) if ($regEventId && $regEventId > 0) { @@ -841,16 +842,16 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract } // For each recurrence - foreach ($this->regEventData['recurrences'] as $k=>$v) { + foreach ($this->regEventData['recurrences'] as $recurKey=>$recurVal) { // If we have times for this recurrence - if ($v['times'] && count($v['times']) > 0) { + if ($recurVal['times'] && count($recurVal['times']) > 0) { // 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) { + foreach ($recurVal['times'] as $eventTimeKey=>$eventTimeVal) { $id = false; @@ -859,31 +860,36 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract // Check if this time from the event 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; + foreach($this->regEventData['reg_time'] as $regTimeKey=>$regTimeVal) { + if ($regTimeVal['event_time'] == $eventTimeKey) { + + // Set ID to say we found this one. + $id = $regTimeKey; + + // Also add OK to the reg_time to say that it matches a recur time - see below + $this->regEventData['reg_time'][$regTimeKey]['OK'] = true; } } } - // If it doesn't now, then add it + // If it wasn't found, then add it if (!$id) { $needTimesReloaded = true; + $message .= "
    New dates and/or times have been added"; - $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'])); + $sTime = date('Y-m-d H:i:s',strtotime($eventTimeVal['start_time']['datetime'])); + $eTime = date('Y-m-d H:i:s',strtotime($eventTimeVal['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, + 'event_time' => $eventTimeKey, 'start_datetime' => $sTime, 'end_datetime' => $eTime, - 'all_day' => $tv['all_day']['value'], + 'all_day' => $eventTimeVal['all_day']['value'], 'attendees' => $this->regEventData['attendees']['value'], 'attendee_max' => $this->regEventData['attendee_max'], 'attendee_count' => 0, @@ -926,6 +932,29 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract } // each recurrence + // Check all reg_times we had from before to make sure they were matched with a recur time + $deleteList = ''; + $deleteSep = ''; + foreach($this->regEventData['reg_time'] as $regTimeKey=>$regTimeVal) { + if (!isset($regTimeVal['OK'])) { + + // If this time didn't match a recur time, then it must have been removed in the event so add to list + $deleteList .= $deleteSep.$regTimeKey; + $deleteSep = ','; + + } + } + + // If there's anything in the delete list, purge them now and say we need a reload + if ($deleteList != '') { + $this->wpdb->query(" + DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time + WHERE id IN ($deleteList) + "); + $needTimesReloaded = true; + $message .= '
    Old dates and/or times have been removed'; + } + // Get rid of all of the recurrence data - No longer needed unset($this->regEventData['recurrences']); @@ -1005,6 +1034,7 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract } // not times specific // Check if we need the times entries reloaded + $this->regEventData['message'] = false; if ($needTimesReloaded) { // Get all reg_time records for this event @@ -1012,6 +1042,9 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract $RegTime = new GlmDataRegistrationsRegTime($this->wpdb, $this->config); $this->regEventData['reg_time'] = $RegTime->getList('T.reg_event = '.$this->regEventData['id'], 'start_datetime', true); + $this->regEventData['message'] = 'Dates and Times have been updated due to changes in the "Dates Schedules" for this event.'.$message; + + } // echo "
".print_r($this->regEventData,1)."
"; diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index bb95f9f..84cd3a5 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -353,6 +353,9 @@ class GlmRegCartSupport $deleteEventNow = false; $haveClasses = false; + // Get reg times for this event + $regEventTimes = $RegTime->getList("reg_event = ".$event['reg_event']); + $this->cart['events'][$eventKey]['removed'] = false; // Update reg_time entries for current availability and get the event data; @@ -417,6 +420,12 @@ class GlmRegCartSupport $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['removed'] = false; + // Check if the time selected for this registrant still exists in the event + if (!isset($regEventTimes[$registrant['reg_time']])) { + $this->cart['messages'][] = "The event date and/or time selected for ".$registrant['fname'].' '.$registrant['fname']." has been dropped from the event. Registrant was removed."; + $removeRegistrant = true; + } + // Check the if registrant still has a time slot hold or can get one // if () { @@ -428,10 +437,8 @@ class GlmRegCartSupport // Check if registrant has an account if (!isset($this->cart['accounts'][$registrant['account']])) { - $this->cart['messages'][] = "Information was not stored correctly for registrant ".$registrant['fname'].' '.$registrant['fname'].". Registrant was removed."; $removeRegistrant = true; - } // If this registrant is flagged for removal from cart diff --git a/gulpfile.js b/gulpfile.js index 1049b09..9c8254f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,8 +2,8 @@ var gulp = require('gulp'), concat = require('gulp-concat'), uglify = require('gulp-uglify'), jshint = require('gulp-jshint'), - plumber = require('gulp-plumber'), - notify = require('gulp-notify'); + plumber = require('gulp-plumber'); +// notify = require('gulp-notify'); gulp.task('adminscripts', function(){ gulp.src([ @@ -27,12 +27,7 @@ gulp.task('frontscripts', function(){ .pipe(concat('frontRegApp.js')) //.pipe(uglify()) .pipe(jshint()) - .pipe(gulp.dest('js/')) - .pipe(notify({ - title: 'Gulp - Frontscripts', - message: 'compiling of js files complete', - onLast: true - })); + .pipe(gulp.dest('js/')); }); gulp.task('watch', function(){ diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 57727cc..b3a3b1d 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -156,12 +156,15 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ if ( foundClass != undefined ) { // Try looking through the class times // var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time}); +console.log(registrants[i].reg_time); var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time }); +console.log(foundClass); +console.log(registrants); if ( foundRegTime ) { foundRegTime.reg_event = foundClass.get('reg_event'); console.log(foundRegTime); } - // Now add the time if needed + // Now add the time if needed var hasRegTime = _.findWhere(foundClass, { reg_time: foundRegTime.id }); // console.log(hasRegTime); if ( !hasRegTime ) { diff --git a/js/models/front/regEvent.js b/js/models/front/regEvent.js index b72425e..7416df7 100644 --- a/js/models/front/regEvent.js +++ b/js/models/front/regEvent.js @@ -40,12 +40,15 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ if ( foundClass != undefined ) { // Try looking through the class times // var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time}); +console.log(registrants[i].reg_time); var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time }); +console.log(foundClass); +console.log(registrants); if ( foundRegTime ) { foundRegTime.reg_event = foundClass.get('reg_event'); console.log(foundRegTime); } - // Now add the time if needed + // Now add the time if needed var hasRegTime = _.findWhere(foundClass, { reg_time: foundRegTime.id }); // console.log(hasRegTime); if ( !hasRegTime ) { diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index 43cf857..7fbba8c 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -81,6 +81,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent public function modelAction($actionData = false) { + $messages = array(); $option = 'dashboard'; $view = false; $numbDisplayed = false; @@ -110,7 +111,6 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent $regEventUpdated = false; $regEventUpdateError = false; $regEventAdded = false; - $reason = false; $regEventSample = false; $regEventJSON = false; $regClassesJSON = false; @@ -191,6 +191,8 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent case 'add': case 'edit': + $problem = false; + // If we're adding a new reg event if ($option == 'add') { @@ -263,13 +265,14 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent } else { - $reason = "Trying to add an event that is already listed in Registrations."; + $messages[] = "Trying to add an event that is already listed in Registrations."; + $problem = true; } } // If there's no problem yet, try to get the regEvent data for edit - if ($reason == '') { + if (!$problem) { if ($regEventID) { $regEvent = $this->editEntry($regEventID); if ($regEvent) { @@ -312,6 +315,11 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent $regEventFirstTime = $regEvent['firstTime']; $regEventLastTime = $regEvent['lastTime']; + // if there's a user notice, add it to messages + if ($regEvent['message']) { + $messages[] = $regEvent['message']; + } + } $view = 'eventDashboard'; @@ -404,6 +412,8 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent // Compile template data $templateData = array( + 'haveMessages' => count($messages) > 0, + 'messages' => $messages, 'option' => $option, 'regEventsCount' => $regEventsCount, 'haveRegEvents' => $haveRegEvents, @@ -430,8 +440,6 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent 'regEventUpdated' => $regEventUpdated, 'regEventUpdateError' => $regEventUpdateError, 'regEventAdded' => $regEventAdded, - 'reason' => $reason, - 'entry' => $regEventSample, 'thisJsUrl' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js', 'regEventJSON' => $regEventJSON, diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index eba74a6..33c4bc8 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -226,6 +226,7 @@ } } } + // echo '
$jsonClasses: ' . print_r( $jsonClasses, true ) . '
'; // echo '
$regEvent: ' . print_r( $regEvent, true ) . '
'; diff --git a/views/admin/registrations/eventDashboard.html b/views/admin/registrations/eventDashboard.html index 0818070..ff208d2 100644 --- a/views/admin/registrations/eventDashboard.html +++ b/views/admin/registrations/eventDashboard.html @@ -2,11 +2,19 @@

Selected Event Dashboard

-
- - {if $reason} -

{$reason}

+ {if $haveMessages} +
+ Please Note: +
    + {foreach $messages as $m} +
  • {$m}
  • + {/foreach} +
+
{/if} + + +

Event

@@ -71,7 +79,6 @@

Dates and Availability

{if $regEvent.time_specific.value} -

*** NEED TO ADD POP-UP FOR EDITING OF MAX ATTENDEES AND ATTENDEE LIST FOR EACH DATE ***

Availability guide: (limit)-(registered)-(pending)-(available)

-- 2.17.1