From 95cbca648cf4e9853bf30cf78c9bdc8cf4597896 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 17 Oct 2017 13:03:57 -0400 Subject: [PATCH] Adding code comments Code comments for the registration and register models. --- models/front/registrations/register.php | 9 +++- models/front/registrations/registration.php | 57 +++++++++++++++------ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/models/front/registrations/register.php b/models/front/registrations/register.php index 625aa9a..909bcbb 100644 --- a/models/front/registrations/register.php +++ b/models/front/registrations/register.php @@ -40,7 +40,8 @@ { $view = 'register'; $emailError = ''; - // Create dummy reg array + + // Create dummy reg array $reg for the template data. $reg = array( 'fname' => '', 'lname' => '', @@ -52,11 +53,12 @@ 'country' => '', ); - // Check for $option + // Check for $option (Filtered) $option = ( isset( $_REQUEST['option'] ) ) ? filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING) : null; switch ( $option ) { case 'submit': + // Filter the form variables for use in db insert. $email = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL ); $password = filter_var( $_REQUEST['password'], FILTER_SANITIZE_STRING ); $fname = filter_var( $_REQUEST['fname'], FILTER_SANITIZE_STRING ); @@ -68,6 +70,7 @@ $zip = filter_var( $_REQUEST['zip'], FILTER_SANITIZE_STRING ); $country = filter_var( $_REQUEST['country'], FILTER_SANITIZE_STRING ); if ( $email ) { + // Check to see if we have an account with that email already. $accountId = $this->wpdb->get_var( $this->wpdb->prepare( "SELECT id @@ -79,6 +82,7 @@ if ( $accountId ) { // Already an account with that email address $emailError = 'Already an account with that email address!'; + // Setup $reg variable for the template form data. $reg = array( 'fname' => $fname, 'lname' => $lname, @@ -118,6 +122,7 @@ 'fname' => $fname, 'lname' => $lname, ); + // Redirect to the start of registrations. wp_redirect( GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/' ); } break; diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index 86dfca2..12e059a 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -37,18 +37,22 @@ public function modelAction($actionData = false) { - + // Clear the headers for wordpress. nocache_headers(); + + // Setup default variables $loginAccount = ''; $cartId = false; $haveCart = false; $isNewCart = false; $regEventFirstTime = false; - // Have Backbone.js loaded + // Setup scripts array for needed js files. $scripts = array( 'regApp' => 'js/frontRegApp.js', ); + + // Loop through our scripts array and register them. foreach ( $scripts as $scriptName => $scriptPath ) { wp_register_script( $scriptName, @@ -58,7 +62,10 @@ true ); } + // Load Backbone.sj and jQuery. wp_enqueue_script( array( 'backbone', 'jquery' ) ); + + // Load our scripts. wp_enqueue_script( array_keys( $scripts ) ); $regEvent = array(); @@ -88,6 +95,8 @@ $eventRegID = false; } } + + // Set the $view to registration $view = 'registration'; // Load cart support class @@ -144,14 +153,17 @@ // Get the RegEvent entry $this->postProcAddedEventData = true; $regEvent = $this->getEventConfig( $eventRegID, true, false, true ); - // echo '
$regEvent: ' . print_r( $regEvent, 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']); - // $first = current($v['times']); - // echo '
$first: ' . print_r( $first, true ) . '
'; + // 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) { @@ -163,6 +175,7 @@ } } + // Create an $event array with the event data. $event = array( 'id' => $regEvent['id'], 'event' => $regEvent['event'], @@ -178,7 +191,6 @@ 'terms' => $regEvent['terms'], ); - // echo '
$event: ' . print_r( $event, true ) . '
'; break; } @@ -189,6 +201,8 @@ $jsonClasses = array(); if ( isset( $regEvent['reg_class'] ) && is_array( $regEvent['reg_class'] ) ) { + + // Loop through the $regEvent['reg_class'] array to build $rClass array foreach ( $regEvent['reg_class'] as $rClass ) { // Pull the rate data if ( isset( $rClass['reg_rate'] ) && is_array( $rClass['reg_rate'] ) ) { @@ -203,6 +217,8 @@ $jsonClasses[] = json_encode( $rClass, JSON_NUMERIC_CHECK ); } } + + // Build the regClass JSON for the template. $regClassJSON = '[' . implode( ',', $jsonClasses ) . ']'; $regCartJSON = json_encode( $cart ); @@ -211,6 +227,7 @@ // check to see if there's a user logged in if ( isset( $_SESSION['LoginAccount'] ) && filter_var( $_SESSION['LoginAccount']['id'], FILTER_VALIDATE_INT ) ) { + // Setup JSON for the loginAccount. $loginAccount = json_encode( $_SESSION['LoginAccount'], JSON_NUMERIC_CHECK ); } @@ -222,12 +239,20 @@ // Looping through to grab out registrants from the cart. if ( isset( $cart['events'] ) && is_array( $cart['events'] ) ) { + + // Loop through events array. foreach ( $cart['events'] as $rEvent ) { if ( isset( $rEvent['classes'] ) && is_array( $rEvent['classes'] ) ) { + + // Loop through classes array foreach ( $rEvent['classes'] as $class ) { if ( isset( $class['rates'] ) && is_array( $class['rates'] ) ) { + + // Loop through rates array foreach ( $class['rates'] as $rate ) { if ( isset( $rate['registrants'] ) && is_array( $rate['registrants'] ) ) { + + // Loop through registrants array. foreach ( $rate['registrants'] as $registrant ) { $accountData = array(); // If there's an account id get data for the account. @@ -241,7 +266,6 @@ ), ARRAY_A ); - // echo '
$accountData:  ' . print_r( $accountData , true ) . '
'; } // Need to know the class id for the registrant @@ -273,6 +297,8 @@ ); $registrant['reg_time_text'] = $regTimeText; } + + // Setup the registrant for this level. $registrant['class_id'] = $classId; $registrant['email'] = $email; $registrant['validated'] = $accountData['validated']; @@ -282,19 +308,19 @@ $registrant['state'] = $accountData['state']; $registrant['zip'] = $accountData['zip']; $registrant['country'] = $accountData['country']; - // echo '
$registrant: ' . print_r( $registrant, true ) . '
'; $registrants[] = $registrant; - } + } // - End loop through for registrants array. } - } + + } // - End loop through rates. } - } + + } // - End loop through classes. } - } + + } // - End loop through events. } - // echo '
$registrants: ' . print_r( $registrants, true ) . '
'; -// echo '
$regEvent: ' . print_r( $regEvent, true ) . '
'; // Compile template data $templateData = array( 'haveCart' => $haveCart, @@ -312,7 +338,8 @@ 'regUrl' => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/', 'loggedIn' => ( isset( $_SESSION['LoginAccount'] ) ) ? $_SESSION['LoginAccount']: false, ); - // Return status, any suggested view, and any data to controller + + // Return status, any suggested view, and any data to controller return array( 'status' => true, 'modelRedirect' => false, -- 2.17.1