<?php
-
/**
* Gaslight Media Associate
* Registrations Plugin support class
}
// If there's a new reg request id, declare success
- $requestID = $this->wpdb->insert_id;
- if ($requestID) {
- return $requestID;
+ $requestId = $this->wpdb->insert_id;
+ if ($requestId) {
+ return $requestId;
}
return false;
// Clear cart data
$this->cart = array(
'status' => false, // Return status, default to false, true if valid request returned
- 'errorMsg' => '', // Any applicable error message
- 'notes' => array(), // System generated notes regarding status of request
+ 'validated' => false, // Flag indicating that the cart has been validated - see checkRegistrationRequest(0)
+ 'messages' => array(), // System generated notes regarding status of request
'accounts' => array(), // Accounts associated with this request - both requesting and attending (might be the same)
// Index in this array is the account ID as used in data below
'times' => array(), // reg_time records associated with this request - Index is the reg_time ID
}
// Try to get the base registration request data
- $this->cart['request'] = $RegRequest->getEntry($requestId);
+ $this->cart['request'] = $RegRequest->getEntry($requestId);
if (!$this->cart['request']) {
$this->cart['errorMsg'] = 'Unable to retrieve the requested registration request.';
return $this->cart;
$this->addAccountToCart($this->cart['request']['account']);
// Get list of events being requested
- $this->cart['events'] = $RequestEvent->getList("T.reg_request = $requestId");
-
+ $this->cart['events'] = $RequestEvent->getList("T.reg_request = $requestId");
+
// For each event
if ($this->cart['events']) {
foreach ($this->cart['events'] as $eventKey => $event) {
- // Get reg_event record for this event
- $this->cart['events'][$eventKey]['reg_event'] = $RegEvent->getEntry($event['reg_event']);
-
// Get list of event classes requested for this event
- $this->cart['events'][$eventKey]['classes'] = $RequestClass->getList("T.reg_request = $requestId");
+ $this->cart['events'][$eventKey]['classes'] = $RequestClass->getList("T.reg_request_event = ".$event['id']);
// For each class selected for this event
if ($this->cart['events'][$eventKey]['classes']) {
foreach ($this->cart['events'][$eventKey]['classes'] as $classKey => $class) {
// Get list of rates requested for this class
- $this->cart['events'][$eventKey]['classes'][$classKey]['rates'] = $RequestRate->getList("T.reg_request = $requestId");
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'] = $RequestRate->getList("T.reg_request_class = ".$class['id']);
// For each rate selected for this class
if ($this->cart['events'][$eventKey]['classes'][$classKey]['rates']) {
foreach ($this->cart['events'][$eventKey]['classes'][$classKey]['rates'] as $rateKey => $rate) {
// Get list of registrants requested for this rate
- $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'] = $RequestRegistrant->getList("T.reg_request = $requestId");
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'] = $RequestRegistrant->getList("T.reg_request_rate = ".$rate['id']);
// For each rate selected for this class
if ($this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants']) {
}
$this->cart['status'] = true;
+ $this->cart['validated'] = false;
+
+// echo "<br>getRegistrationCart() Results:<pre>".print_r($this->cart,1)."</pre>"; exit;
+
if ($json) {
return json_encode($this->cart);
}
- return $this->cart;
+ return;
}
* Updates all totals
* Updates request last accessed time
*
+ * @param integer $requestId
+ *
* @return array Array of request and all associated information or false
* @access public
*/
- public function checkRegistrationRequest()
+ public function checkRegistrationRequest($requestId = false)
{
- $messages[] = '';
- $totalCharges = 0;
- $totalRegistrants = 0;
- $totalDiscounts = 0;
- $grandTotal = 0;
+ // Try to get the cart data
+ $this->getRegistrationCart($requestId);
-
- // If request ID is not false, get the cart first
- if ($requestId !== false) {
-
- // If we didn't get a cart using this ID or there was some failure getting it, then return false
- if (!$this->getRegistrationCart($requestId) || !$this->cart['status']) {
- return false;
- }
- }
-
- // If a submission account is specified (otherwise it should be a guest user prior to checkout)
- if ($this->cart['request']['account'] && !isset($this->cart['accounts'][$this->cart['request']['account']])) {
- $messages[] .= 'Account for person submitting the request is missing.';
+ if (!$this->cart) {
+ return false;
}
+
+ $RegEvent = new GlmDataRegistrationsRegEvent($this->wpdb, $this->config);
+ $RegTime = new GlmDataRegistrationsRegTime($this->wpdb, $this->config);
+ $RegRequest = new GlmDataRegistrationsRegRequest($this->wpdb, $this->config);
+ $RequestEvent = new GlmDataRegistrationsRequestEvent($this->wpdb, $this->config);
+ $RequestClass = new GlmDataRegistrationsRequestClass($this->wpdb, $this->config);
+ $RequestRate = new GlmDataRegistrationsRegRequestRate($this->wpdb, $this->config);
+ $RequestRegistrant = new GlmDataRegistrationsRequestRegistrant($this->wpdb, $this->config);
+
+ $this->cart['messages'] = array();
+
+ $totalRegistrants = 0;
+ $totalCharges = 0;
+ $totalDiscounts = 0;
+ $grandTotal = 0;
+
+ // If we have a cart (request)
+ if ($this->cart) {
- // Check if there's no events listed
- if (is_array($this->cart['events']) && count($this->cart['events']) > 0) {
- $messages[] = 'Cart is empty.';
- } else {
-
- // Loop through all events in the cart
- foreach ($this->cart['events'] as $eventKey => $event) {
-
- $this->cart['events'][$eventKey]['charges'] = 0;
- $this->cart['events'][$eventKey]['credits'] = 0;
- $this->cart['events'][$eventKey]['discounts'] = 0;
- $this->cart['events'][$eventKey]['total'] = 0;
- $this->cart['events'][$eventKey]['numbRegistrants'] = 0;
-
- // Check if Event exists in Events add-on and is active in registrations or if doing admin (admin_active)
- $regEvent = $RegEvent->getEntry($event['reg_event']);
- if (!$regEvent) {
- $messages[] = 'Event in cart is not currently available for registratiosn.';
- }
-
- // Check if the event is time-specific and if there's a list of times for this event - If not, should be a default
-
- // Check if there's a list of classes (levels) for this event - If not, add as a problem
-
- // Loop though all classes - Might be multiple classes (levels) that are the same but for different reg_times.
-
- // [this class]['charges'] = 0;
- // [this class]['credits'] = 0;
- // [this class]['discounts'] = 0;
- // [this class]['total'] = 0;
- // [this class]['numbRegistrants'] = 0;
-
-
- // Check if there's a list of rates - if not, add as a problem
-
- // loop through all rates
+ // If a submission account is specified (otherwise it should be a guest user prior to checkout)
+ if ($this->cart['request']['account'] && !isset($this->cart['accounts'][$this->cart['request']['account']])) {
+ $this->cart['messages'][] .= 'Account for person submitting the request is missing.';
+ }
- // [this rate]['charges'] = 0;
- // [this rate]['credits'] = 0;
- // [this rate]['discounts'] = 0;
- // [this rate]['total'] = 0;
- // [this rate]['numbRegistrants'] = 0;
+ /*
+ * Events Processing
+ */
+
+ // If we don't have events for this cart
+ if (!is_array($this->cart['events']) || count($this->cart['events']) == 0) {
+ $this->cart['messages'][] = 'Cart is empty.';
+ } else {
+
+ // Loop through all events in the cart
+ foreach ($this->cart['events'] as $eventKey => $event) {
+
+ $eventRegistrants = 0;
+ $eventCharges = 0;
+ $eventDiscounts = 0;
+ $eventTotal = 0;
+
+ // Do event Checks
+
+
+
+ // Check if Event exists in Events add-on and is active in registrations or if doing admin (admin_active)
+ $regEvent = $RegEvent->getEntry($event['reg_event']);
+ if (!$regEvent) {
+ $this->cart['messages'][] = 'Event in cart is not currently available for registration.';
+ }
+
+ // Check if the event is time-specific and if there's a list of times for this event - If not, should be a default
+
+ /*
+ * Classes (levels) Processing
+ */
+
+ // If we don't have classes for this event
+ if (!is_array($event['classes']) || count($event['classes']) == 0 ) {
+ $this->cart['messages'][] = 'Event '.$event['event_name'].' has no levels.';
+ } else {
+
+ // Loop through all classes (levels) for this event
+ foreach ($event['classes'] as $classKey => $class) {
+
+ $classRegistrants = 0;
+ $classCharges = 0;
+ $classDiscounts = 0;
+ $classTotal = 0;
- // Check if listed rate is currently available - If not, add as a problem
+ // Do class (level) checks
- // Check if there's a list of registrants for this class (level) - If not, add as a problem
- // Loop through all registrants
+ /*
+ * Rates Processing
+ */
- // [this registrant]['charges'] = 0;
- // [this registrant]['credits'] = 0;
- // [this registrant]['discounts'] = 0;
- // [this registrant]['total'] = 0;
+ // If we don't have rates for this class
+ if (!is_array($class['rates']) || count($class['rates']) == 0 ) {
+ $this->cart['messages'][] = 'Class '.$class['class_name'].' has no rates.';
+ } else {
- // Check that registrant has an account that's active - If not, add as a problem
-
- // Check if limited registration
-
- // Check for a current hold - If expired or not listed
+ // loop through all rates
+ foreach ($class['rates'] as $rateKey => $rate) {
- // If no current hold, try to get new hold - If not, add as a problem
-
- // If no problems, then calculate charges
-
- // If there's not already a charge for this class (level) - Add base rate to charges
+ $rateRegistrants = 0;
+ $rateCharges = 0;
+ $rateDiscounts = 0;
+ $rateTotal = 0;
- // If the number of registrants is less than the registrant credits - Add the per-registrant rate
+ // Do rate Checks
+
- // Check if there's a comp or discount code - if so add add discount
+ // Check if listed rate is currently available - If not, add as a problem
- // Calculate net charge for this registrant and put it in registrant data
+ /*
+ * Registrants Processing
+ */
- // Add charges, credits, discounts, totals to the current rate
-
- // Add charges, credits, discounts, totals for this rate to the current class (level)
-
- // Add charges, credits, discounts, totals for class (level) to the current event
+ // If we don't have registrants for this class
+ if (!is_array($rate['registrants']) || count($rate['registrants']) == 0 ) {
+ $this->cart['messages'][] = 'Rate '.$rate['rate_name'].' has no registrants.';
+ } else {
+
+ // loop through all Registrants
+ foreach ($rate['registrants'] as $registrantKey => $registrant) {
+
+ $registrantCharges = 0;
+ $registrantDiscounts = 0;
+ $registrantTotal = 0;
+
+ // Do registrant checks
+
+
+
+ // Save totals for this registrant
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['totalCharges'] = $registrantCharges;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['totalDiscounts'] = $registrantDiscounts;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['rateTotal'] = $registrantTotal;
+
+ // Add totals to rate
+ $rateRegistrants++;
+ $rateCharges += $registrantCharges;
+ $rateDiscounts += $registrantDiscounts;
+ $rateTotal += $registrantTotal;
+
+ } // Each registrant
+
+ } // Have registrants
+
+ // Save totals for this rate
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['totalRegistrants'] = $rateRegistrants;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['totalCharges'] = $rateCharges;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['totalDiscounts'] = $rateDiscounts;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['rateTotal'] = $rateTotal;
+
+ // Add totals to class
+ $classRegistrants += $rateRegistrants;
+ $classCharges += $rateCharges;
+ $classDiscounts += $rateDiscounts;
+ $classTotal += $rateTotal;
+
+ } // Each Rate
+
+ } // Have rates
+
+ // Save totals for this class (level)
+ $this->cart['events'][$eventKey]['classes'][$classKey]['totalRegistrants'] = $classRegistrants;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['totalCharges'] = $classCharges;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['totalDiscounts'] = $classDiscounts;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['classTotal'] = $classTotal;
+
+ // Add totals to event
+ $eventRegistrants += $classRegistrants;
+ $eventCharges += $classCharges;
+ $eventDiscounts += $classDiscounts;
+ $eventTotal += $classTotal;
+
+
+ } // Each class
+
+ } // Have Classes
+
+ // Save totals for this event
+ $this->cart['events'][$eventKey]['totalRegistrants'] = $eventRegistrants;
+ $this->cart['events'][$eventKey]['totalCharges'] = $eventCharges;
+ $this->cart['events'][$eventKey]['totalDiscounts'] = $eventDiscounts;
+ $this->cart['events'][$eventKey]['eventTotal'] = $eventTotal;
- // Add charges, credits, discounts, totals for this event to the grand totals
+ // Add totals to request
+ $totalCharges += $eventCharges;
+ $totalRegistrants += $eventRegistrants;
+ $totalDiscounts += $eventDiscounts;
+ $totalTotal += $eventTotal;
+
+ } // Each event
-
- }
+ } // Have events
+
+ // Update request last_update timestamp
+
+ } // have request
+
+ // Check if Event Time exists in Events add-on
+
+// echo "<pre>".print_r($this->cart,1)."</pre>";
- } // have events
+ // Check if no messages then cart validated
+ if (count($this->cart['messages']) == 0) {
+ $this->cart['validated'] = true;
+ }
- // Check if Event Time exists in Events add-on
+ return;
}
----
-- Registration for a specific event
--- Has one or more reg_selected_rate records associated with it - *** Need to remove the account entry in this table ****
+-- Has one or more reg_selected_rate records associated with it - *** Need to remove from this table: account, total_charge ****
CREATE TABLE {prefix}reg_request_event (
id INT NOT NULL AUTO_INCREMENT,
reg_request INT NULL, -- Pointer to reg_request table
event_name TINYTEXT NULL, -- Name of Event so it will always be in the cart data
reg_time INT NULL, -- Pointer to times table entry in Events add-on
event_datetime DATETIME NULL, -- Date and time of event time selected so it will always be in the cart
- total_charge FLOAT, -- Last calculated total of all charges for registration to this event for all registrants
mf_data TEXT NULL, -- Any MagicForm data associated with requested event
notes TEXT NULL, -- System operator's notes for this registration request
PRIMARY KEY (id),
----
-- A particular reg_class selected
--- Has one or more reg_request_rate records associated with it - *** Need to remove the account entry in this table ****
+-- Has one or more reg_request_rate records associated with it - *** Need to remove from this table: account, total_class_charge ****
CREATE TABLE {prefix}reg_request_class (
id INT NOT NULL AUTO_INCREMENT,
reg_event INT NULL, -- Pointer to reg_event entry
reg_request_event INT NULL, -- Pointer to reg_request_event table entry
class INT NULL, -- Pointer to event reg_class table - False (0) if registration class no longer exits
class_name TINYTEXT NULL, -- Name of event class at the time selected
- total_class_charge FLOAT, -- Last calculated total of all charges for this registration class for this request
mf_data TEXT NULL, -- Any MagicForm data associated with registrant
notes TEXT NULL, -- System operator's notes for this registration request
PRIMARY KEY (id),
----
-- A particular reg_rate selected
--- Has one or more reg_request_registrant records associated with it - *** Need to remove the account entry in this table ****
+-- Has one or more reg_request_registrant records associated with it - *** Need to remove from this table: account, numb_registrants, total_registrant_charges ****
CREATE TABLE {prefix}reg_request_rate (
id INT NOT NULL AUTO_INCREMENT,
reg_event INT NULL, -- Pointer to reg_event entry
rate_name TINYTEXT NULL, -- Name of event class rate at the time selected
base_rate FLOAT, -- Base rate at time of registration
per_registrant FLOAT, -- Per Registrant Rate at time of registration
- registrant_credits TINYINT NULL, -- Number of registrant credits in base rate at time of registration
- numb_registrants TINYINT NULL, -- Last calculated number of registrants with this rate
- total_registrant_charges FLOAT, -- Last calculation registrant charges assoicated with this selected rate
+ registrant_credits TINYINT NULL, -- Number of registrants included in base rate at time of registration
mf_data TEXT NULL, -- Any MagicForm data associated with registrant
notes TEXT NULL, -- System operator's notes for this registration request
PRIMARY KEY (id),
----
--- A specific registrant for a selected registration rate - *** Need to remove the reg_request_registrant entry in this table ****
+-- A specific registrant for a selected registration rate - *** Need to remove from this table: reg_request_registrant, reg_request_hold, reg_request_hold_not_available ****
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_request_event INT NULL, -- Pointer to reg_request_event table entry
reg_request_class INT NULL, -- Pointer to reg_request_class table entry
reg_request_rate INT NULL, -- Pointer to reg_request_rate table entry
- reg_request_hold BOOLEAN NULL, -- Registrant hold active - Registrant slots held certain time since last cart access - After this the slot needs to be updated if available
- reg_request_hold_not_available BOOLEAN NULL, -- No registrant slot available for this registrant - Unable to get hold
fname TINYTEXT NULL, -- First name of registrant at the time of selection
lname TINYTEXT NULL, -- Last name of registrant at the time of selection
mf_data TEXT NULL, -- Any MagicForm data associated with registrant