From 4c4e79b3d273d0a4c8d6d5fb612b8a51e8c112a3 Mon Sep 17 00:00:00 2001
From: Steve Sutton
Date: Mon, 8 Jan 2018 15:46:42 -0500
Subject: [PATCH] Adding ability to update the attendee from admin attendee
list.
Edit attendee shows the custom fields now and it will save out the
attendee (fname,lname) and the custom fields.
---
models/admin/ajax/regAdmin.php | 2 +-
models/admin/ajax/regAdmin/attendee.php | 140 +++++++++++
.../admin/registrations/eventRegistrants.html | 227 ++++++++++++------
views/admin/registrations/eventSubTabs.html | 3 +-
4 files changed, 292 insertions(+), 80 deletions(-)
create mode 100644 models/admin/ajax/regAdmin/attendee.php
diff --git a/models/admin/ajax/regAdmin.php b/models/admin/ajax/regAdmin.php
index 7fbc9e7..acb8e45 100644
--- a/models/admin/ajax/regAdmin.php
+++ b/models/admin/ajax/regAdmin.php
@@ -75,7 +75,7 @@ class GlmMembersAdmin_ajax_regAdmin
$collection = filter_var( $_REQUEST['collection'], FILTER_SANITIZE_STRING );
// If not a valid collection, die quietly
- if (!in_array($collection, array('regClasses', 'regRates'))) {
+ if (!in_array($collection, array('regClasses', 'regRates', 'attendee'))) {
$this->failureResponse('Not a valid desitination (collection?).');
}
diff --git a/models/admin/ajax/regAdmin/attendee.php b/models/admin/ajax/regAdmin/attendee.php
new file mode 100644
index 0000000..289532c
--- /dev/null
+++ b/models/admin/ajax/regAdmin/attendee.php
@@ -0,0 +1,140 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release regRates.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+// Load Registrations data abstract
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRate.php';
+
+class GlmMembersAdmin_registrations_ajax_attendee // extends GlmDataRegistrationsRequestRegistrant
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ /**
+ * Constructor
+ *
+ * This contructor performs the work for this model. This model returns
+ * an array containing the following.
+ *
+ * 'status'
+ *
+ * True if successfull and false if there was a fatal failure.
+ *
+ * 'view'
+ *
+ * A suggested view name that the contoller should use instead of the
+ * default view for this model or false to indicate that the default view
+ * should be used.
+ *
+ * 'data'
+ *
+ * Data that the model is returning for use in merging with the view to
+ * produce output.
+ *
+ * @wpdb object WordPress database object
+ *
+ * @return array Array containing status, suggested view, and any data
+ */
+ public function __construct ($wpdb, $config)
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ /*
+ * Run constructor for the Registrations data class
+ *
+ * Note, the third parameter is a flag that indicates to the Contacts
+ * data class that it should flag a group of fields as 'view_only'.
+ */
+ // parent::__construct(false, false, true);
+
+ }
+
+ public function modelAction($modelData)
+ {
+
+ trigger_error( print_r( $modelData, true ) );
+
+
+ // Perform specified action
+ switch ($modelData['option']) {
+
+ case 'update':
+
+ $this->wpdb->update(
+ GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request_registrant',
+ array(
+ 'fname' => $modelData['fname'],
+ 'lname' => $modelData['lname'],
+ ),
+ array( 'id' => $modelData['reg_id'] ),
+ '%s',
+ array( '%d' )
+ );
+
+ $registrant = array(
+ 'id' => $modelData['reg_id'],
+ 'fname' => $modelData['fname'],
+ 'lname' => $modelData['lname'],
+ );
+
+ parse_str( $modelData['formData'], $queryParams );
+ // Store the custom field data
+ $_REQUEST = $queryParams;
+
+ // Save the custom field data if custom fields plugin is on
+ apply_filters(
+ 'glm-members-customfields-form-submit',
+ '',
+ 'glm_reg_customfields_reg_event_attendee_' . $modelData['reg_event_id'],
+ $modelData['reg_id'],
+ true
+ );
+
+ echo json_encode( $registrant, JSON_NUMERIC_CHECK );
+ wp_die();
+
+ break;
+
+ default:
+ die(); // should never get here
+ break;
+
+ }
+
+ wp_die();
+
+
+
+ }
+
+
+}
diff --git a/views/admin/registrations/eventRegistrants.html b/views/admin/registrations/eventRegistrants.html
index 58abe0f..6f9562c 100644
--- a/views/admin/registrations/eventRegistrants.html
+++ b/views/admin/registrations/eventRegistrants.html
@@ -45,95 +45,113 @@
+
-
+
-
Total found: {$registrantCount}
+
Total found: {$registrantCount}
- {if $paging}
-
-
- {/if}
+ {if $paging}
+
+ {/if}
-
@@ -227,6 +244,25 @@ jQuery(document).ready(function($){
e.preventDefault();
$('.glm-edit-form-' + $(this).data('registrant')).show();
$('.glm-attendee-' + $(this).data('registrant')).hide();
+ var refId = $(this).data('registrant');
+ {if apply_filters('glm-members-customfields-plugin-active', false)}
+ $.ajax({
+ cache: false,
+ type: 'POST',
+ url: '{$ajaxUrl}?action=glm_members_admin_ajax',
+ data: {
+ 'action': 'glm_members_admin_ajax',
+ 'glm_action': 'customFieldsFront',
+ 'option': 'displayForm',
+ 'fid': 'glm_reg_customfields_reg_event_attendee_' + {$regEvent.id},
+ 'recordId': refId,
+ 'parentFormId': '',
+ 'formData': false,
+ },
+ }).done(function( formHtml ){
+ $('.customfields-attendee-' + refId).html( formHtml );
+ }).fail();
+ {/if}
});
$('.glm-cancel').click(function(e){
e.preventDefault();
@@ -239,6 +275,41 @@ jQuery(document).ready(function($){
$('.glm-detail').click(function(e){
e.preventDefault();
});
+ $('.glm-update').click(function(e){
+ e.preventDefault();
+ var refId = $(this).data('registrant');
+
+ // Get possible custom field data
+ var attendeeFormData = $('#glm-attendee-form-' + refId).serialize();
+ console.log(attendeeFormData);
+
+ var accountFname = $('#glm-attendee-' + refId + ' input[name=fname]').val().trim();
+ var accountLname = $('#glm-attendee-' + refId + ' input[name=lname]').val().trim();
+ $.ajax({
+ context: this,
+ url: '{$ajaxUrl}?action=glm_members_admin_ajax',
+ dataType: 'json',
+ data: {
+ glm_action: 'regAdmin',
+ collection: 'attendee',
+ option: 'update',
+ reg_id: refId,
+ fname: accountFname,
+ lname: accountLname,
+ reg_event_id: {$regEvent.id},
+ formData: attendeeFormData,
+ }
+ }).done(function(account){
+ // Have to change the actual td display too.
+ $('.glm-attendee-fullname-' + account.id ).html( account.fname + ' ' + account.lname );
+ // And update the edit form also
+ $('#glm-attendee-form-' + account.id + ' input[name=fname]').val( account.fname );
+ $('#glm-attendee-form-' + account.id + ' input[name=lname]').val( account.lname );
+ $('.glm-edit-form-' + $(this).data('registrant')).hide();
+ $('.glm-attendee-' + $(this).data('registrant')).show();
+ }).fail(function(msg){
+ });
+ });
});
diff --git a/views/admin/registrations/eventSubTabs.html b/views/admin/registrations/eventSubTabs.html
index 95224e1..9a36e8a 100644
--- a/views/admin/registrations/eventSubTabs.html
+++ b/views/admin/registrations/eventSubTabs.html
@@ -15,7 +15,8 @@
{/if}
Attendee Notification
Payment Codes
-
{$terms.reg_term_attendee_plur_cap}
+
+
{$terms.reg_term_attendee_plur_cap}
{if $haveMessages}
--
2.17.1