Pulling class data for the regEvent from the dataabstract now.
},
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;
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();
},
},
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;
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();
},
$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 ) {
if ( isset( $cartId ) && filter_var( $cartId, FILTER_VALIDATE_INT ) ) {
$cart = $RegCart->getRegistrationCart( $cartId );
- //echo '<pre>$cart: ' . print_r( $cart, true ) . '</pre>';
$regRequestJSON = json_encode( $cart['request'], JSON_NUMERIC_CHECK );
}
- //echo '<pre>$_SESSION: ' . print_r( $_SESSION, true ) . '</pre>';
switch ( $option ) {
default:
-
// Get the RegEvent entry
- $regEvent = $this->getEntry( $eventRegID );
- //echo '<pre>$regEvent: ' . print_r( $regEvent, true ) . '</pre>';
+ $regEvent = $this->getEventConfig( $eventRegID );
+ // echo '<pre>$regEvent: ' . print_r( $regEvent, true ) . '</pre>';
$event = array(
'id' => $regEvent['id'],
'event' => $regEvent['event'],
'terms' => $regEvent['terms'],
);
- // get the reg_classes
- $RegClass = new GlmDataRegistrationsRegClass( $this->wpdb, $this->config );
- $where = " T.reg_event = $eventRegID";
- $regClass = $RegClass->getList( $where );
- //echo '<pre>$regClass: ' . print_r( $regClass, true ) . '</pre>';
- $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 '<pre>$rates: ' . print_r( $rates, true ) . '</pre>';
- 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 '<pre>$regClass: ' . print_r( $regClass, true ) . '</pre>';
-
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 );
}
}
// Get terms into JSON
$termsJSON = json_encode( $this->config['terms'] );
- //echo '<pre>$this->config[terms]: ' . print_r( $this->config['terms'], true ) . '</pre>';
// 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 '<pre>$_SESSION: ' . print_r( $_SESSION, true ) . '</pre>';
-
// 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 '<pre>$cart: ' . print_r( $cart, true ) . '</pre>';
$registrants = array();
- //echo '<pre>$cart[events]: ' . print_r( $cart['events'], true ) . '</pre>';
+ // 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'] ) ) {
}
}
- // echo '<pre>$registrants: ' . print_r( $registrants, true ) . '</pre>';
-
// Compile template data
$templateData = array(
- 'entry' => $regEventSample,
'thisJsUrl' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js',
'regEventJSON' => json_encode( $event, JSON_NUMERIC_CHECK ),
'regClassesJSON' => $regClassJSON,