From cdfd12982c5991495021d8b7e44d1bd3ad688b5d Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 2 Oct 2017 14:32:51 -0400 Subject: [PATCH] Updating the registrations front and model Pulling class data for the regEvent from the dataabstract now. --- js/frontRegApp.js | 55 ++++++++------- js/views/front/regClass.js | 55 ++++++++------- models/front/registrations/registration.php | 74 +++++---------------- 3 files changed, 80 insertions(+), 104 deletions(-) diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 8e492bc..4023207 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -768,34 +768,36 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, addAccount: function(){ - console.log( 'Add Account Called' ); - console.log( loginAccount ); // Check to make sure the loginAccount is not empty if ( loginAccount !== '' ) { var regRequest = cart.get( 'request' ); var accountEmail = loginAccount.get( 'email' ); var accountId = loginAccount.get( 'id' ); if ( accountId && accountEmail ) { - this.model.registrants.create({ - option: 'add', - account: accountId, - reg_request: regRequest.id, - reg_event: this.model.get( 'reg_event' ), - reg_class: this.model.get( 'id' ), - reg_rate: this.model.get('reg_rate_id'), - email: accountEmail, - fname: loginAccount.get('fname'), - lname: loginAccount.get('lname') - }); + // If the model is already there then don't add + var findById = this.model.registrants.where({account: accountId}); + if ( findById.length === 0 ) { + this.model.registrants.create({ + option: 'add', + account: accountId, + reg_request: regRequest.id, + reg_event: this.model.get( 'reg_event' ), + reg_class: this.model.get( 'id' ), + reg_rate: this.model.get('reg_rate_id'), + email: accountEmail, + fname: loginAccount.get('fname'), + lname: loginAccount.get('lname') + }); + } } } }, addNew: function(){ + var findByEmail = []; console.log( 'called addNew in regClass view' ); var fname = this.$('.reg_fname').val().trim(); var lname = this.$('.reg_lname').val().trim(); var email = this.$('.reg_email').val().trim(); - //console.log( 'email: ' + email + ' fname: ' + fname + ' lname: ' + lname ); if ( fname === '' || lname === '' ) { alert( 'First and Last name required!' ); return; @@ -805,18 +807,23 @@ app.Views.Front.RegClass = Backbone.View.extend({ if ( !confAnsw ) { return; } + } else { + findByEmail = this.model.registrants.where({email: email}); } + console.log(findByEmail); var regRequest = cart.get( 'request' ); - this.model.registrants.create({ - option: 'add', - reg_request: regRequest.id, - reg_event: this.model.get( 'reg_event' ), - reg_class: this.model.get( 'id' ), - reg_rate: this.model.get( 'reg_rate_id' ), - email: email, - fname: fname, - lname: lname, - }); + if ( findByEmail.length === 0 ) { + this.model.registrants.create({ + option: 'add', + reg_request: regRequest.id, + reg_event: this.model.get( 'reg_event' ), + reg_class: this.model.get( 'id' ), + reg_rate: this.model.get( 'reg_rate_id' ), + email: email, + fname: fname, + lname: lname, + }); + } this.newRegAccount.destroy(); this.newRegAccountView.remove(); }, diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index c4198ff..92ddee8 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -47,34 +47,36 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, addAccount: function(){ - console.log( 'Add Account Called' ); - console.log( loginAccount ); // Check to make sure the loginAccount is not empty if ( loginAccount !== '' ) { var regRequest = cart.get( 'request' ); var accountEmail = loginAccount.get( 'email' ); var accountId = loginAccount.get( 'id' ); if ( accountId && accountEmail ) { - this.model.registrants.create({ - option: 'add', - account: accountId, - reg_request: regRequest.id, - reg_event: this.model.get( 'reg_event' ), - reg_class: this.model.get( 'id' ), - reg_rate: this.model.get('reg_rate_id'), - email: accountEmail, - fname: loginAccount.get('fname'), - lname: loginAccount.get('lname') - }); + // If the model is already there then don't add + var findById = this.model.registrants.where({account: accountId}); + if ( findById.length === 0 ) { + this.model.registrants.create({ + option: 'add', + account: accountId, + reg_request: regRequest.id, + reg_event: this.model.get( 'reg_event' ), + reg_class: this.model.get( 'id' ), + reg_rate: this.model.get('reg_rate_id'), + email: accountEmail, + fname: loginAccount.get('fname'), + lname: loginAccount.get('lname') + }); + } } } }, addNew: function(){ + var findByEmail = []; console.log( 'called addNew in regClass view' ); var fname = this.$('.reg_fname').val().trim(); var lname = this.$('.reg_lname').val().trim(); var email = this.$('.reg_email').val().trim(); - //console.log( 'email: ' + email + ' fname: ' + fname + ' lname: ' + lname ); if ( fname === '' || lname === '' ) { alert( 'First and Last name required!' ); return; @@ -84,18 +86,23 @@ app.Views.Front.RegClass = Backbone.View.extend({ if ( !confAnsw ) { return; } + } else { + findByEmail = this.model.registrants.where({email: email}); } + console.log(findByEmail); var regRequest = cart.get( 'request' ); - this.model.registrants.create({ - option: 'add', - reg_request: regRequest.id, - reg_event: this.model.get( 'reg_event' ), - reg_class: this.model.get( 'id' ), - reg_rate: this.model.get( 'reg_rate_id' ), - email: email, - fname: fname, - lname: lname, - }); + if ( findByEmail.length === 0 ) { + this.model.registrants.create({ + option: 'add', + reg_request: regRequest.id, + reg_event: this.model.get( 'reg_event' ), + reg_class: this.model.get( 'id' ), + reg_rate: this.model.get( 'reg_rate_id' ), + email: email, + fname: fname, + lname: lname, + }); + } this.newRegAccount.destroy(); this.newRegAccountView.remove(); }, diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index 0d64a17..ef5e848 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -41,10 +41,8 @@ $loginAccount = ''; $cartId = false; - // var_dump( $_SESSION ); // Have Backbone.js loaded $scripts = array( - //'backbone-local' => 'js/lib/backbone.localStorage.min.js', 'regApp' => 'js/frontRegApp.js', ); foreach ( $scripts as $scriptName => $scriptPath ) { @@ -107,18 +105,15 @@ if ( isset( $cartId ) && filter_var( $cartId, FILTER_VALIDATE_INT ) ) { $cart = $RegCart->getRegistrationCart( $cartId ); - //echo '
$cart: ' . print_r( $cart, true ) . '
'; $regRequestJSON = json_encode( $cart['request'], JSON_NUMERIC_CHECK ); } - //echo '
$_SESSION: ' . print_r( $_SESSION, true ) . '
'; switch ( $option ) { default: - // Get the RegEvent entry - $regEvent = $this->getEntry( $eventRegID ); - //echo '
$regEvent: ' . print_r( $regEvent, true ) . '
'; + $regEvent = $this->getEventConfig( $eventRegID ); + // echo '
$regEvent: ' . print_r( $regEvent, true ) . '
'; $event = array( 'id' => $regEvent['id'], 'event' => $regEvent['event'], @@ -132,52 +127,27 @@ 'terms' => $regEvent['terms'], ); - // get the reg_classes - $RegClass = new GlmDataRegistrationsRegClass( $this->wpdb, $this->config ); - $where = " T.reg_event = $eventRegID"; - $regClass = $RegClass->getList( $where ); - //echo '
$regClass: ' . print_r( $regClass, true ) . '
'; - $RegRate = new GlmDataRegistrationsRegRate( $this->wpdb, $this->config); - if ( isset( $regClass ) && is_array( $regClass ) ) { - foreach ( $regClass as &$rClass ) { - // grab the reg rate for this class - $rates = $RegRate->getList( "T.reg_class = " . $rClass['id'] ); - //echo '
$rates: ' . print_r( $rates, true ) . '
'; - if ( isset( $rates ) && is_array( $rates ) ) { - foreach ( $rates as $rate ) { - $rClass['loggedIn'] = ( isset($_SESSION['LoginAccount']) ) ? true : false; - $rClass['reg_rate_id'] = $rate['id']; - $rClass['reg_rate_name'] = $rate['name']; - $rClass['reg_rate_base_price'] = $rate['base_rate']; - $rClass['reg_rate_per_reg'] = $rate['per_registrant']; - } - } - } - } - //echo '
$regClass: ' . print_r( $regClass, true ) . '
'; - break; } - // including test data for now - include GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH . '/data/event_setup.php'; - - //$regClass = $regEventSample['reg_class']; - - // Find the regClass rate to be used - // There will only be one as this is based on the date. - //$regClassRate - $eventData = array(); - unset($regClass['reg_rate']); - // Build the Class array of json objects for the classes. $jsonClasses = array(); - if ( isset( $regClass ) && is_array( $regClass ) ) { - foreach ( $regClass as $rClass ) { + if ( isset( $regEvent['reg_class'] ) && is_array( $regEvent['reg_class'] ) ) { + foreach ( $regEvent['reg_class'] as $rClass ) { + // Pull the rate data + if ( isset( $rClass['reg_rate'] ) && is_array( $rClass['reg_rate'] ) ) { + foreach ( $rClass['reg_rate'] as &$rate ) { + $rClass['loggedIn'] = ( isset($_SESSION['LoginAccount']) ) ? true : false; + $rClass['reg_rate_id'] = $rate['id']; + $rClass['reg_rate_name'] = $rate['name']; + $rClass['reg_rate_base_price'] = $rate['base_rate']; + $rClass['reg_rate_per_reg'] = $rate['per_registrant']; + } + } $jsonClasses[] = json_encode( $rClass, JSON_NUMERIC_CHECK ); } } @@ -186,28 +156,23 @@ // Get terms into JSON $termsJSON = json_encode( $this->config['terms'] ); - //echo '
$this->config[terms]: ' . print_r( $this->config['terms'], true ) . '
'; // check to see if there's a user logged in if ( isset( $_SESSION['LoginAccount'] ) && filter_var( $_SESSION['LoginAccount']['id'], FILTER_VALIDATE_INT ) ) { $loginAccount = json_encode( $_SESSION['LoginAccount'], JSON_NUMERIC_CHECK ); - //unset( $_SESSION['LoginAccount'] ); } - // echo '
$_SESSION: ' . print_r( $_SESSION, true ) . '
'; - // If there's a cart then pull any registrants for it // If there classes in the cart with rates and registrants they'll need // be setup. - // echo '
$cart: ' . print_r( $cart, true ) . '
'; $registrants = array(); - //echo '
$cart[events]: ' . print_r( $cart['events'], true ) . '
'; + // Looping through to grab out registrants from the cart. if ( isset( $cart['events'] ) && is_array( $cart['events'] ) ) { - foreach ( $cart['events'] as $event ) { - if ( isset( $event['classes'] ) && is_array( $event['classes'] ) ) { - foreach ( $event['classes'] as $class ) { + foreach ( $cart['events'] as $rEvent ) { + if ( isset( $rEvent['classes'] ) && is_array( $rEvent['classes'] ) ) { + foreach ( $rEvent['classes'] as $class ) { if ( isset( $class['rates'] ) && is_array( $class['rates'] ) ) { foreach ( $class['rates'] as $rate ) { if ( isset( $rate['registrants'] ) && is_array( $rate['registrants'] ) ) { @@ -242,11 +207,8 @@ } } - // echo '
$registrants: ' . print_r( $registrants, true ) . '
'; - // Compile template data $templateData = array( - 'entry' => $regEventSample, 'thisJsUrl' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js', 'regEventJSON' => json_encode( $event, JSON_NUMERIC_CHECK ), 'regClassesJSON' => $regClassJSON, -- 2.17.1