From: Steve Sutton Date: Tue, 2 Jan 2018 19:51:30 +0000 (-0500) Subject: Implement event registrants export and print. X-Git-Tag: v1.0.0^2~114 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=70d08c5fa7759b35c10eb087d051d53e8ecb9cd4;p=WP-Plugins%2Fglm-member-db-registrations.git Implement event registrants export and print. Setup the export function like Chuck did on the member list. --- diff --git a/classes/data/dataRegRequestRegistrant.php b/classes/data/dataRegRequestRegistrant.php index 933fcd9..1b9b852 100644 --- a/classes/data/dataRegRequestRegistrant.php +++ b/classes/data/dataRegRequestRegistrant.php @@ -318,6 +318,14 @@ class GlmDataRegistrationsRequestRegistrant extends GlmDataAbstract // Get registrants for this event $listResult = $this->getList( $whereEvent, "T.lname, T.fname", true, 'id', $start, $limit ); + if ( !$limit ) { + $listResult = array( + 'list' => $listResult + ); + } + if ( !isset( $listResult['list'] ) ) { + return false; + } $registrants = $listResult['list']; $registrantCount = $this->getStats(str_replace('T.', '', $whereEvent)); diff --git a/models/admin/ajax/registrantsListExport.php b/models/admin/ajax/registrantsListExport.php new file mode 100644 index 0000000..eccccd6 --- /dev/null +++ b/models/admin/ajax/registrantsListExport.php @@ -0,0 +1,220 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + + +// Load Registrant Info data abstract +require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestRegistrant.php'; + +/** + * + * This class exports the currently selected registrants list + * to a printable HTML file, to a CSV file, or otherwise. + */ +class GlmMembersAdmin_ajax_registrantsListExport extends GlmDataRegistrationsRequestRegistrant +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /** + * Constructor + * + * This constructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + parent::__construct(false, false); + + } + + public function checkFlag($t) {return isset($_REQUEST[$t]) && $_REQUEST[$t] == 'on';} + /** + * Perform Model Action + * + * This modelAction takes an AJAX image upload and stores the image in the + * media/images directory of the plugin. + * + * This model action does not return, it simply does it's work then calls die(); + * + * @param $actionData + * + * Echos JSON string as response and does not return + */ + public function modelAction ($actionData = false) + { + + // When processing registrant info records, also get primary contact data + $this->postProcessPrimaryContact = true; + + $where = ' true '; + $categories = false; + $haveRegistrants = false; + $list = false; + $success = false; + $filterPending = false; + $filterArchived = false; + $haveFilter = false; + $numbDisplayed = false; + $lastDisplayed = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $namesList = false; + + // Check selected fields + $select = array( + 'exportId' => $this->checkFlag('exportId'), + 'exportRegistrant' => $this->checkFlag('exportRegistrant'), + 'exportAddr1' => $this->checkFlag('exportAddr1'), + 'exportAddr2' => $this->checkFlag('exportAddr2'), + 'exportCity' => $this->checkFlag('exportCity'), + 'exportState' => $this->checkFlag('exportState'), + 'exportZip' => $this->checkFlag('exportZip'), + 'exportEmail' => $this->checkFlag('exportEmail'), + 'exportPhone' => $this->checkFlag('exportPhone'), + 'exportCounty' => $this->checkFlag('exportCounty'), + ); + + // Get registration event ID if supplied + if (isset($_REQUEST['regEventID'])) { + + // Make sure it's numeric + $regEventID = ($_REQUEST['regEventID'] - 0); + + } else { + + // Try to get saved + $regEventID = get_option('glmMembersDatabaseRegistrationsRegEventID'); + + } + + if (!$regEventID || $regEventID <= 0) { + $regEventID = false; + } + // Only return information records that are active + + $whereParts = array(); + // Filter for complete if given + if ( isset( $_REQUEST['complete'] ) && filter_var( $_REQUEST['complete'], FILTER_VALIDATE_BOOLEAN) ) { + $completed = true; + $whereParts[] = "T.reg_request in ( + SELECT id + FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request + WHERE status = {$this->config['submission_status_numb']['COMPLETE']})"; + } + + // Check for a text search + if (isset($_REQUEST['text_search']) && trim($_REQUEST['text_search'] != '')) { + $textSearch = trim($_REQUEST['text_search']); + $whereParts[] = "concat( T.fname, ' ', T.lname) LIKE '%".$textSearch."%'"; + + // Clean up for use in redisplaying search value + $textSearch = stripslashes($textSearch); + } + + // Get list of all registrants for this event + $where = implode( ' AND ', $whereParts ); + + // $list = $this->getList($where, "lname"); + $listResult = $this->getFullRegistrantsData($regEventID, $where, 1, false); + $list = $listResult['list']; + + // If we have list entries - even if it's an empty list + $success = true; + $haveRegistrants = false; + if ($list !== false) { + $success = true; + + // If we have any entries + $registrantCount = count($list); + if ($registrantCount > 0) { + $haveRegistrants = true; + } + } + + // Compile template data + $templateData = array( + 'category_data' => $category_data, + 'select' => $select, + 'haveRegistrants' => $haveRegistrants, + 'registrants' => $list, + 'registrantCount' => $registrantCount, + 'categories' => $categories, + 'haveFilter' => $haveFilter, + 'filterArchived' => $filterArchived, + 'filterFeatured' => $filterFeatured, + 'filterPending' => $filterPending, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start, + 'limit' => $limit, + 'namesList' => $namesList + ); + + $view = 'admin/ajax/registrantsListExport.html'; + if ($_REQUEST['type'] == 'csv') { + $view = 'admin/ajax/registrantsListExportCsv.html'; + header("Content-Type: text/csv"); + header("Content-Disposition: attachment; filename=file.csv"); + } else { + header("Content-Type: text/html"); + header("Content-Disposition: attachment; filename=file.html"); + } + + // Disable caching + header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1 + header("Pragma: no-cache"); // HTTP 1.0 + header("Expires: 0"); // Proxies + + // Return status, suggested view, and data to controller + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => $view, + 'data' => $templateData + ); + + } + +} diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index d4cd54f..e399aff 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -176,6 +176,8 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent // Get the regEvent data $regEvent = $this->getEntry($regEventID); + + // Filter for complete if given if ( isset( $_REQUEST['complete'] ) && filter_var( $_REQUEST['complete'], FILTER_VALIDATE_BOOLEAN) ) { $completed = true; $whereParts[] = "T.reg_request in ( @@ -183,6 +185,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request WHERE status = {$this->config['submission_status_numb']['COMPLETE']})"; } + // Get list of all registrants for this event $where = implode( ' AND ', $whereParts ); diff --git a/setup/validActions.php b/setup/validActions.php index d835104..d1296af 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -65,7 +65,8 @@ $glmMembersRegistrationsAddOnValidActions = array( 'regFront' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, 'cartLinkWidget' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, 'summaryContent' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, - 'updateAvailability' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG + 'updateAvailability' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, + 'registrantsListExport' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, ), 'registrations' => array( 'index' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, diff --git a/views/admin/ajax/registrantsListExport.html b/views/admin/ajax/registrantsListExport.html new file mode 100644 index 0000000..b1808b3 --- /dev/null +++ b/views/admin/ajax/registrantsListExport.html @@ -0,0 +1,50 @@ + + + + + + Total found: {$registrantCount}   + List of {$terms.reg_term_attendee_plur_cap} +
+ + + + + + {if $select.exportId}{/if} + {if $select.exportRegistrant}{/if} + {if $select.exportAddr1}{/if} + {if $select.exportAddr2}{/if} + {if $select.exportCity}{/if} + {if $select.exportState}{/if} + {if $select.exportZip}{/if} + {if $select.exportCounty}{/if} + {if $select.exportEmail}{/if} + {if $select.exportPhone}{/if} + + + + {if $haveRegistrants} + {foreach $registrants as $m} + + {if $select.exportId}{/if} + {if $select.exportRegistrant}{/if} + {if $select.exportAddr1}{/if} + {if $select.exportAddr2}{/if} + {if $select.exportCity}{/if} + {if $select.exportState}{/if} + {if $select.exportZip}{/if} + {if $select.exportCounty}{/if} + {if $select.exportEmail}{/if} + {if $select.exportPhone}{/if} + + + {/foreach} + {else} + + {/if} + +
ID{$terms.reg_term_attendee_cap} NameAddressAddr Line #2CityStateZIPCountyEmailPhone
{$m.id}{$m.fname} {$m.lname}{$m.account.addr1}{$m.account.addr2}{$m.account.city}{if $m.account.state}{$m.account.state.value}{/if}{$m.account.zip}{if $m.account.county}{$m.account.county.value}{/if}{$m.account.email}{$m.account.phone}
(no {$terms.reg_term_attendee_plur_cap} listed)
+ + + diff --git a/views/admin/ajax/registrantsListExportCsv.html b/views/admin/ajax/registrantsListExportCsv.html new file mode 100644 index 0000000..311b475 --- /dev/null +++ b/views/admin/ajax/registrantsListExportCsv.html @@ -0,0 +1,27 @@ +{if $haveRegistrants} +{if $select.exportId}"ID",{/if} +{if $select.exportRegistrant}"{$terms.reg_term_attendee_cap} Name",{/if} +{if $select.exportAddr1}"Address",{/if} +{if $select.exportAddr2}"Addr Line #2",{/if} +{if $select.exportCity}"City",{/if} +{if $select.exportState}"State",{/if} +{if $select.exportZip}"ZIP/Postal",{/if} +{if $select.exportCounty}"County",{/if} +{if $select.exportRegion}"Region",{/if} +{if $select.exportEmail}"Email",{/if} +{if $select.exportPhone}"Phone"{/if} + +{foreach $registrants as $m} +{if $select.exportId}"{$m.id}",{/if} +{if $select.exportRegistrant}"{$m.registrant}",{/if} +{if $select.exportAddr1}"{$m.account.addr1}",{/if} +{if $select.exportAddr2}"{$m.account.addr2}",{/if} +{if $select.exportCity}"{$m.account.city}",{/if} +{if $select.exportState}"{if $m.account.state}{$m.account.state.value}{/if}",{/if} +{if $select.exportZip}"{$m.account.zip}",{/if} +{if $select.exportCounty}"{if $m.account.county}{$m.county.account.value}{/if}",{/if} +{if $select.exportEmail}"{$m.account.email}",{/if} +{if $select.exportPhone}"{$m.account.phone}"{/if} + +{/foreach} +{else}No {$terms.reg_term_attendee_plur_cap} Selected{/if} diff --git a/views/admin/registrations/eventRegistrants.html b/views/admin/registrations/eventRegistrants.html index cb188f2..0546dc6 100644 --- a/views/admin/registrations/eventRegistrants.html +++ b/views/admin/registrations/eventRegistrants.html @@ -89,11 +89,12 @@
+ - + @@ -105,12 +106,13 @@ @@ -118,7 +120,16 @@
Show Only Completed:
Name Search:
Fields to export:
{$terms.reg_term_attendee_cap} ID
- {$terms.reg_term_attendee_cap} Name
+ {$terms.reg_term_attendee_cap} Name
Address Line #1
Address Line #2
City
State
ZIP/Postal Code
+ Email
Phone
County
+ + Export to: + + Export for Print
+ Export to Spreadsheet (CSV) + + + Cancel +
@@ -128,22 +139,14 @@ jQuery(document).ready(function($){ autoOpen: false, minWidth: 500, dialogClass: 'glm-dialog-no-close', - buttons: { - 'Export CSV': function(){ - console.log('doing something'); - }, - // 'Print': function() { - // console.log( 'Print something' ); - // }, - Cancel: function(){ - dialog.dialog( 'close' ); - }, - }, }); $('#exportRegistrantsButton').click(function(){ $('#exportRegistrantsDialog').dialog('open'); }); + $('#exportRegistrantsCancel').click(function(){ + $('#exportRegistrantsDialog').dialog('close'); + }); });