From: Chuck Scott Date: Tue, 19 Sep 2017 19:21:56 +0000 (-0400) Subject: More work on adding reg classes and rates to a reg event (admin). X-Git-Tag: v1.0.0^2~404 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=99fd6dcc275ea1d229f4dd48c22effb134821fe2;p=WP-Plugins%2Fglm-member-db-registrations.git More work on adding reg classes and rates to a reg event (admin). Added createRegistrationCart() function to regCartSupport.php --- diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index 756852d..eb45eb9 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -79,6 +79,48 @@ class GlmRegCartSupport } + + + /* + * Create a new cart + * + * A new cart consists of only one reg_request record + * + * @return array Array of request and all associated information or false + * @access public + */ + public function createRegistrationCart() + { + + $res = $this->wpdb->insert( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request', + array( + 'account' => 0, + 'validated' => false, + 'user_trace_info' => $_SERVER["REMOTE_ADDR"]." - ".date("m/d/Y H:i:s") + ), + array( + '%d', + '%d', + '%s' + ) + ); + + if ($res != 1) { + return false; + } + + // If there's a new reg request id, declare success + $requestID = $this->wpdb->insert_id; + if ($requestID) { + return $requestID; + } + + return false; + + } + + /* * Retrieve a complete cart * diff --git a/js/adminRegApp.js b/js/adminRegApp.js index 4692337..3a42b32 100644 --- a/js/adminRegApp.js +++ b/js/adminRegApp.js @@ -139,28 +139,39 @@ app.Views.Admin.RegClass = Backbone.View.extend({ add: function(){ console.log('add called'); + // Get data from form var cName = this.$('.class-name').val().trim(); var cDescr = this.$('.class-descr').val().trim(); + // Check for required data if (cName == '') { alert('The Level Name is Required!'); return; } - this.$('.class-display-template').show(); - this.$('.class-edit-template').hide(); - this.$('.class-update').hide(); - this.$('.class-add').hide(); + // ??? this.model.set({ name: cName, descr: cDescr }); // Get parent for id to send to backend for new class var parentEvent = this.model.get( 'parent' ); - if (!this.model.save({ option: 'add', parent: parentEvent.id, name: cName, descr: cDescr })) { + // Try to save the registration class + $newID = this.model.save({ option: 'add', parent: parentEvent.id, name: cName, descr: cDescr }); + + if (!$newID){ console.log('AJAX Save Error'); } else { console.log('AJAX Save Successful'); } + + this.model.set( 'id', $newID ); + + this.$('.class-display-template').show(); + this.$('.class-edit-template').hide(); + this.$('.class-update').hide(); + this.$('.class-add').hide(); + this.$('.class-edit').show(); + // Add this new model to the collection. var parentEvent = this.model.get( 'parent' ); // ???????? // parentEvent.classes.create( this.model ); @@ -187,6 +198,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({ this.$('.class-display-template').hide(); this.$('.class-edit-template').show(); this.$('.class-name').focus(); + this.$('.class-update').show(); glmSubmitRequired += 1; }, diff --git a/js/views/admin/regClass.js b/js/views/admin/regClass.js index e881dd9..a012745 100644 --- a/js/views/admin/regClass.js +++ b/js/views/admin/regClass.js @@ -24,28 +24,39 @@ app.Views.Admin.RegClass = Backbone.View.extend({ add: function(){ console.log('add called'); + // Get data from form var cName = this.$('.class-name').val().trim(); var cDescr = this.$('.class-descr').val().trim(); + // Check for required data if (cName == '') { alert('The Level Name is Required!'); return; } - this.$('.class-display-template').show(); - this.$('.class-edit-template').hide(); - this.$('.class-update').hide(); - this.$('.class-add').hide(); + // ??? this.model.set({ name: cName, descr: cDescr }); // Get parent for id to send to backend for new class var parentEvent = this.model.get( 'parent' ); - if (!this.model.save({ option: 'add', parent: parentEvent.id, name: cName, descr: cDescr })) { + // Try to save the registration class + $newID = this.model.save({ option: 'add', parent: parentEvent.id, name: cName, descr: cDescr }); + + if (!$newID){ console.log('AJAX Save Error'); } else { console.log('AJAX Save Successful'); } + + this.model.set( 'id', $newID ); + + this.$('.class-display-template').show(); + this.$('.class-edit-template').hide(); + this.$('.class-update').hide(); + this.$('.class-add').hide(); + this.$('.class-edit').show(); + // Add this new model to the collection. var parentEvent = this.model.get( 'parent' ); // ???????? // parentEvent.classes.create( this.model ); @@ -72,6 +83,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({ this.$('.class-display-template').hide(); this.$('.class-edit-template').show(); this.$('.class-name').focus(); + this.$('.class-update').show(); glmSubmitRequired += 1; }, diff --git a/models/admin/ajax/regAdmin.php b/models/admin/ajax/regAdmin.php index 1f5b19e..40f797d 100644 --- a/models/admin/ajax/regAdmin.php +++ b/models/admin/ajax/regAdmin.php @@ -73,7 +73,7 @@ class GlmMembersAdmin_ajax_regAdmin // Get Backbone collection we're talking with $collection = filter_var( $_REQUEST['collection'], FILTER_SANITIZE_STRING ); - + // If not a valid collection, die quietly if (!in_array($collection, array('regClasses', 'regRates'))) { wp_die(); @@ -92,6 +92,9 @@ class GlmMembersAdmin_ajax_regAdmin wp_die(); } + ini_set('display_errors', 1); + error_reporting(E_ALL); + // Load the model file require_once $modelName; @@ -104,6 +107,8 @@ class GlmMembersAdmin_ajax_regAdmin // Instantiate the model and ask it to perform the work $model = new $className($this->wpdb, $this->config); +trigger_error(print_r($modelData,1)); + $results = $model->modelAction($modelData); diff --git a/models/admin/ajax/regAdmin/regClasses.php b/models/admin/ajax/regAdmin/regClasses.php index 53b096b..f690f2b 100644 --- a/models/admin/ajax/regAdmin/regClasses.php +++ b/models/admin/ajax/regAdmin/regClasses.php @@ -81,12 +81,42 @@ class GlmMembersAdmin_registrations_ajax_regClasses extends GlmDataRegistrations public function modelAction($modelData) { -trigger_error(print_r($modelData,1)); - // Perform specified action switch ($modelData['option']) { case 'add': + + // Make sure we got a parent ID with the data + if (isset($modelData['parent']) || (modelData['parent']-0) > 0) { + + // Try to insert the class (level) data + $res = $this->wpdb->insert( + $this->table, + array( + 'reg_event' => $modelData['parent'], + 'name' => $modelData['name'], + 'descr' => $modelData['descr'] + ), + array( + '%d', + '%s', + '%s' + ) + ); + + if ($res != 1) { + trigger_error('Registration Class Insert failed'); + return false; + } + + // If there's a new classID, declare success + $classID = $this->wpdb->insert_id; + if ($classID) { + return $classID; + } + + } + break; case 'get': @@ -94,7 +124,7 @@ trigger_error(print_r($modelData,1)); case 'update': - // If we have a numeric class (level) ID + // We must have a numeric class (level) ID $classID = ($modelData['id'] - 0); if ($classID > 0) { diff --git a/setup/databaseScripts/create_database_V0.0.12.sql b/setup/databaseScripts/create_database_V0.0.12.sql index 7e30a9d..ca19343 100644 --- a/setup/databaseScripts/create_database_V0.0.12.sql +++ b/setup/databaseScripts/create_database_V0.0.12.sql @@ -489,7 +489,7 @@ CREATE TABLE {prefix}account ( -- Has one or more reg_detail records associated with it CREATE TABLE {prefix}reg_request ( id INT NOT NULL AUTO_INCREMENT, - account INT NULL, -- Pointer to user account (reg_account) who submitted the registrations. If false then guest request (prior to checkout) + account INT NULL, -- Pointer to user account (reg_account) who submitted the registrations. If 0 then guest request (prior to checkout) validated BOOLEAN NULL, -- Flag that indicates if request passed last validation with checkRegistrationRequest() validation_message TEXT NULL, -- Reasons that request did not pass validation with checkRegistrationRequest() - Serialized array bill_fname TINYTEXT NULL, -- Billing information used for this registration submission - Updates account billing address - Kept here for each request