Updates for the admin registration list page for regEvent
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 28 Dec 2017 21:22:26 +0000 (16:22 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 28 Dec 2017 21:24:50 +0000 (16:24 -0500)
Adding to registration list page:
* Set default sort order last then first name.
* Option to show only completed registrations.
* Add pagination to the registration list.
* Add search form with name search. (Searches first and last name).
* Add link for each registrant to their "Account" dashboard.

classes/data/dataRegRequestRegistrant.php
config/plugin.ini
models/admin/registrations/events.php
views/admin/registrations/eventRegistrants.html

index e5d7d46..933fcd9 100644 (file)
@@ -250,7 +250,7 @@ class GlmDataRegistrationsRequestRegistrant extends GlmDataAbstract
                 'field'     => 'reg_request',
                 'as'        => 'request_status',
                 'type'      => 'pointer',
-                    'p_table'   => GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request',
+                    'p_table'   => GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request R',
                     'p_field'   => 'status',
                     'p_static'  => true,
                 'required'  => true,
@@ -302,7 +302,7 @@ class GlmDataRegistrationsRequestRegistrant extends GlmDataAbstract
      * @return array List of registrants with optional additional data or false if none
      *
      */
-    public function getFullRegistrantsData($eventId = false)
+    public function getFullRegistrantsData($eventId = false, $where = '', $start = false, $limit = false)
     {
 
         // Check Event ID
@@ -311,8 +311,16 @@ class GlmDataRegistrationsRequestRegistrant extends GlmDataAbstract
             return false;
         }
 
+        $whereEvent = "T.reg_event = $eventId ";
+        if ( $where ) {
+            $whereEvent .= " AND $where";
+        }
+
         // Get registrants for this event
-        $registrants = $this->getList("T.reg_event = $eventId");
+        $listResult = $this->getList( $whereEvent, "T.lname, T.fname", true, 'id', $start, $limit );
+        $registrants = $listResult['list'];
+
+        $registrantCount = $this->getStats(str_replace('T.', '', $whereEvent));
 
         // Make sure we received registrants
         if (!is_array($registrants) || count($registrants) == 0) {
@@ -334,8 +342,10 @@ class GlmDataRegistrationsRequestRegistrant extends GlmDataAbstract
 
             // Try to get any per
         }
+        $listResult['list'] = $registrants;
+        $listResult['totalCount'] = $registrantCount;
 
-        return $registrants;
+        return $listResult;
 
 
 
@@ -350,4 +360,4 @@ class GlmDataRegistrationsRequestRegistrant extends GlmDataAbstract
     }
 }
 
-?>
\ No newline at end of file
+?>
index 2e00476..c110be1 100644 (file)
@@ -2,7 +2,7 @@
 ; Main Configuration File
 ; {descrName}
 ;
-; Place any static configuration parameters here.  
+; Place any static configuration parameters here.
 ;
 
 [common]
@@ -34,9 +34,9 @@ payment_method[1]                               = 'No Charge'
 payment_method[2]                               = 'Comp Code'
 payment_method[3]                               = 'Cash'
 payment_method[4]                               = 'Check'
-payment_method[5]                               = 'Call from Merchant' 
-payment_method[6]                               = 'Credit Card' 
-payment_method[7]                               = 'PayPal' 
+payment_method[5]                               = 'Call from Merchant'
+payment_method[6]                               = 'Credit Card'
+payment_method[7]                               = 'PayPal'
 
 payment_method_numb['NoCharge']                 = 1
 payment_method_numb['CompCode']                 = 2
@@ -85,7 +85,7 @@ reg_ref_type[50]                               = 'Registrant'
 
 reg_ref_type_numb['Registration Request']      = 10
 reg_ref_type_numb['Event']                     = 20
-reg_ref_type_numb['Registration CLass']        = 30
+reg_ref_type_numb['Registration Class']        = 30
 reg_ref_type_numb['Registration Rate']         = 40
 reg_ref_type_numb['Registrant']                = 50
 
@@ -180,15 +180,15 @@ billing_field[10]                               = 'Country'
 billing_field[11]                               = 'Phone'
 billing_field[12]                               = 'FAX'
 
-billing_field_numb['First Name']                = 1 
-billing_field_numb['Last Name']                 = 2 
-billing_field_numb['Organization']              = 3 
-billing_field_numb['Title/Department']          = 4 
-billing_field_numb['Address Line 1']            = 5 
-billing_field_numb['Address Line 2']            = 6 
-billing_field_numb['City']                      = 7 
-billing_field_numb['State']                     = 8 
-billing_field_numb['ZIP/Postal Code']           = 9 
+billing_field_numb['First Name']                = 1
+billing_field_numb['Last Name']                 = 2
+billing_field_numb['Organization']              = 3
+billing_field_numb['Title/Department']          = 4
+billing_field_numb['Address Line 1']            = 5
+billing_field_numb['Address Line 2']            = 6
+billing_field_numb['City']                      = 7
+billing_field_numb['State']                     = 8
+billing_field_numb['ZIP/Postal Code']           = 9
 billing_field_numb['Country']                   = 10
 billing_field_numb['Phone']                     = 11
 billing_field_numb['FAX']                       = 12
@@ -227,7 +227,7 @@ added_info_field_type[30]                       = 'Account - Person who submits
 added_info_field_type[40]                       = 'Registrant - Person who registers for events'
 added_info_field_type[50]                       = 'Registration - Registration of a specific registrant to a specific event'
 
-added_info_field_type_numb['Request']           = 10 
+added_info_field_type_numb['Request']           = 10
 added_info_field_type_numb['Event']             = 20
 added_info_field_type_numb['Account']           = 30
 added_info_field_type_numb['Registrant']        = 40
index ba2ef28..a09ae6d 100644 (file)
@@ -87,7 +87,8 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
         $prevStart                 = false;
         $nextStart                 = false;
         $start                     = 1;
-        $limit                     = 20;        // Set to the number of listings per page
+        $limit                     = 5;        // Set to the number of listings per page
+        $registrantCount           = 0;
         $textSearch                = false;
         $where                     = ' TRUE ';
         $alphaList                 = false;
@@ -115,6 +116,8 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
         $classes                   = false;
         $haveRegistrants           = false;
         $registrants               = false;
+        $completed                 = false;
+        $errorMsg                  = false;
 
         // Register the masked input script that we need for input controls
         wp_dequeue_script('glm-members-admin-maskedinput');
@@ -158,16 +161,86 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
 
             case 'registrants':
 
+                $whereParts = array();
+
+                if (isset($_REQUEST['textSearch']) && trim($_REQUEST['textSearch'] != '')) {
+                    $textSearch = trim($_REQUEST['textSearch']);
+                    $whereParts[] = "concat( T.fname, ' ', T.lname) LIKE '%".$textSearch."%'";
+
+                    // Clean up for use in redisplaying search value
+                    $textSearch = stripslashes($textSearch);
+                }
+
                 require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestRegistrant.php';
                 $Registrants = new GlmDataRegistrationsRequestRegistrant($this->wpdb, $this->config);
 
+                // Get the regEvent data
+                $regEvent = $this->getEntry($regEventID);
+                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']})";
+                }
                 // Get list of all registrants for this event
-                $registrants = $Registrants->getFullRegistrantsData($regEventID);
+                $where = implode( ' AND ', $whereParts );
+
+                // Check if we're doing paging
+                if ( isset( $_REQUEST['pageSelect'] ) ) {
+
+                    // If request is for Next
+                    if ( $_REQUEST['pageSelect'][0] == 'N' ) {
+                        $newStart = $_REQUEST['nextStart'] - 0;
+
+                    // Otherwise it must be Previous
+                    } else {
+                        $newStart = $_REQUEST['prevStart'] - 0;
+                    }
+
+                    if ($newStart > 0) {
+                        $start = $newStart;
+                    }
+                }
+
+                $listResult = $Registrants->getFullRegistrantsData($regEventID, $where, $start, $limit);
+
+                // Get count of registrants listed
+                $registrantCount = $listResult['totalCount'];;
+                echo '<pre>$registrantCount: ' . print_r( $registrantCount, true ) . '</pre>';
+
+                // If the number of registrants is less than a page, don't do paging
+                if ($registrantCount <= $limit) {
+                    // $paging = false;
+                }
 
-                if ($registrants) {
-                    $haveRegistrants = true;
+                // Get paging results
+                $numbDisplayed = $listResult['returned'];
+                $lastDisplayed = $listResult['last'];
+                if ($start == 1) {
+                    $prevStart = false;
+                } else {
+                    $prevStart = $start - $limit;
+                    if ($start < 1) {
+                        $start = 1;
+                    }
                 }
+                if ($listResult['returned'] == $limit) {
+                    $nextStart = $start + $limit;
+                }
+                $registrants = $listResult['list'];
+
+                $success = true;
+                $haveRegistrants = false;
+                if ($registrants !== false) {
 
+                    $success = true;
+
+                    // If we have any entries
+                    if (count($registrants) > 0) {
+                        $haveRegistrants = true;
+                    }
+                }
                 // echo "<pre>".print_r($registrants,1)."</pre>";
 
                 $view = 'eventRegistrants';
@@ -555,6 +628,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
             'nextStart'               => $nextStart,
             'start'                   => $start,
             'limit'                   => $limit,
+            'registrantCount'         => $registrantCount,
             'namesList'               => $namesList,
             'textSearch'              => $textSearch,
             'regEventID'              => $regEventID,
@@ -575,7 +649,9 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
             'regTimesJSON'            => $regTimesJSON,
             'classes'                 => $classes,
             'haveRegistrants'         => $haveRegistrants,
-            'registrants'             => $registrants
+            'registrants'             => $registrants,
+            'completed'               => $completed,
+            'errorMsg'                => $errorMsg,
         );
 
         // echo "<pre>".print_r($templateData,1)."</pre>";
index be1c037..7d4a996 100644 (file)
@@ -1,19 +1,48 @@
 {include file='admin/registrations/eventHeader.html'}
 {include file='admin/registrations/eventSubTabs.html'}
-    
+
 {if $errorMsg}
     <h3 class="glm-error">{$errorMsg}</h3>
 {/if}
-    
 <h1>Registrant List</h1>
 
-<div class="glm-admin-table-inner glm-admin-table">
+{* Search form for registrants *}
+<form method="post" action="{$thisUrl}?page={$thisPage}">
+    <input type="hidden" name="page" value="{$thisPage}">
+    <input type="hidden" name="option" value="registrants">
+    <input type="hidden" name="regEventID" value="{$regEvent.id}">
+    <input type="hidden" name="prevStart" value="{$prevStart}">
+    <input type="hidden" name="nextStart" value="{$nextStart}">
+    <input type="hidden" name="limit" value="{$limit}">
+    <div>
+        <p>
+            <span class="glm-nowrap">
+                <b>Show Completed Only:</b>
+                <input type="checkbox" name="complete" value="1"{if $completed} checked{/if}>
+            </span>
+            <span class="glm-nowrap">
+                <b>Text Search:</b>
+                <input type="text" name="textSearch" value="{if $textSearch}{$textSearch}{/if}">
+            </span>
+            <span clas="glm-nowrap">
+                <input type="submit" value="Submit">
+            </span>
+        </p>
+    </div>
+
+    <div class="glm-admin-table-inner glm-admin-table">
+
+        <p><b>Total found:</b> {$registrantCount}&nbsp;&nbsp;</p>
+
+        {if $paging}
+            <input type="Submit" name="pageSelect" value="Previous {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+            <input type="Submit" name="pageSelect" value="Next {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+        {/if}
 
         <table class="wp-list-table striped glm-admin-table" style="width: 100%;">
             <thead>
                 <tr>
-                    <th>First Name</th>
-                    <th>Last Name</th>
+                    <th>Name</th>
                     <th>City</th>
                     <th>State</th>
                     <th>Phone</th>
@@ -28,8 +57,7 @@
     {if $haveRegistrants}
         {foreach $registrants as $r}
                 <tr>
-                    <td>{$r.fname}</td>
-                    <td>{$r.lname}</td>
+                    <td><a href="{$thisUrl}?page=glm-members-admin-menu-registrations-accounts&glm_action=accounts&option=accountDashboard&accountID={$r.account.id}">{$r.fname} {$r.lname}</a></td>
                     <td>{$r.account.city}</td>
                     <td>{$r.account.state.value}</td>
                     <td>{$r.account.phone}</td>
             </tbody>
         </table>
 
-</div>
-    
+
+        {if $paging}
+            <input type="Submit" name="pageSelect" value="Previous {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+            <input type="Submit" name="pageSelect" value="Next {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+        {/if}
+
+    </div>
+
+</form>
 {include file='admin/footer.html'}