Setting up the paging for account list page.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 7 Mar 2017 21:31:20 +0000 (16:31 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 7 Mar 2017 21:31:20 +0000 (16:31 -0500)
Using the event list as base to add in the paging for accounts.

models/admin/registrations/accounts.php
views/admin/registrations/account.html

index c0b264e..aaceb75 100644 (file)
@@ -108,6 +108,8 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
         $accountAdded       = false;
         $accountAddError    = false;
         $namesList          = false;
+        $numbDisplayed      = false;
+        $lastDisplayed      = false;
 
         // Get any provided option
         if (isset($_REQUEST['option'])) {
@@ -174,25 +176,66 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
 
         default:
             $where       = 'true';
-            $accounts    = $this->getList();
-            $hasAccounts = ( $accounts !== false && count( $accounts > 0 ) ) ? true: false;
-            $view        = 'account';
+            // 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;
+                }
+            }
 
             // Check if we have a Text Search string
-            if (isset($_REQUEST['textSearch']) && trim($_REQUEST['textSearch']) != '') {
-                $textSearch = trim($_REQUEST['textSearch']);
+            if ( isset( $_REQUEST['textSearch'] ) && trim( $_REQUEST['textSearch'] ) != '' ) {
+                $textSearch = trim( $_REQUEST['textSearch'] );
                 $where .= " AND ( lname LIKE '%$textSearch%' OR fname LIKE '%$textSearch%' OR CONCAT_WS( ' ', fname, lname) LIKE '%$textSearch%' )";
             }
 
+            $accountsResult = $this->getList( $where, 'lname', true, 'id', $start, $limit  );
+            //echo '<pre>$accountsResult: ' . print_r( $accountsResult, true ) . '</pre>';
+
+            //$accounts    = $this->getList( $where );
+            //echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
+
+            // Get paging results
+            $numbDisplayed = $accountsResult['returned'];
+            $lastDisplayed = $accountsResult['last'];
+            if ($start == 1) {
+                $prevStart = false;
+            } else {
+                $prevStart = $start - $limit;
+                if ($start < 1) {
+                    $start = 1;
+                }
+            }
+            if ( $accountsResult['returned'] == $limit ) {
+                $nextStart = $start + $limit;
+            }
+
+            // since we're doing paging, we have to break out just the accounts data
+            $accounts = $accountsResult['list'];
+
+            $hasAccounts = ( $accounts !== false && count( $accounts > 0 ) ) ? true: false;
+            $view        = 'account';
+
             // Get full list of names matching this where clause for search box
-            $namesList = $this->getIdName($where);
+            $namesList = $this->getIdName( $where );
+            unset( $accountsResult );
             break;
         }
 
         // Compile template data
         $templateData = array(
             'hasAccounts'        => $hasAccounts,
-            'numAccounts'        => count($accounts),
+            'numAccounts'        => ($accounts) ? count($accounts) : 0,
             'accounts'           => $accounts,
             'account'            => $account,
             'limit'              => $limit,
@@ -211,6 +254,8 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
             'accountAdded'       => $accountAdded,
             'accountAddError'    => $accountAddError,
             'namesList'          => $namesList,
+            'numbDisplayed'      => $numbDisplayed,
+            'lastDisplayed'      => $lastDisplayed,
         );
              // Return status, any suggested view, and any data to controller
         return array(
index 7d51f9b..7d1f84e 100644 (file)
@@ -9,6 +9,7 @@
         <input type="hidden" name="prevStart" value="{$prevStart}">
         <input type="hidden" name="nextStart" value="{$nextStart}">
         <input type="hidden" name="limit" value="{$limit}">
+
         <div class="">
             <p>
                 <span class="glm-nowrap">
@@ -21,7 +22,7 @@
         <br clear="all">
     <p><b>Total found:</b> {$numAccounts}&nbsp;&nbsp;</p>
 
-    {if $paging}
+    {if $paging && $numAccounts}
         <input type="Submit" name="pageSelect" value="Previous {$limit} Events" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
         <input type="Submit" name="pageSelect" value="Next {$limit} Events" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
     {/if}
@@ -57,7 +58,7 @@
     </table>
 {/if}
 
-    {if $paging}
+    {if $paging && $numAccounts}
         <input type="Submit" name="pageSelect" value="Previous {$limit} Events" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
         <input type="Submit" name="pageSelect" value="Next {$limit} Events" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
     {/if}