From: Steve Sutton Date: Tue, 7 Mar 2017 21:31:20 +0000 (-0500) Subject: Setting up the paging for account list page. X-Git-Tag: v1.0.0^2~486 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=4d5e8bd46a9547e89957c6cd5fb759bd93751a9d;p=WP-Plugins%2Fglm-member-db-registrations.git Setting up the paging for account list page. Using the event list as base to add in the paging for accounts. --- diff --git a/models/admin/registrations/accounts.php b/models/admin/registrations/accounts.php index c0b264e..aaceb75 100644 --- a/models/admin/registrations/accounts.php +++ b/models/admin/registrations/accounts.php @@ -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 '
$accountsResult: ' . print_r( $accountsResult, true ) . '
'; + + //$accounts = $this->getList( $where ); + //echo '
$where: ' . print_r( $where, true ) . '
'; + + // 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( diff --git a/views/admin/registrations/account.html b/views/admin/registrations/account.html index 7d51f9b..7d1f84e 100644 --- a/views/admin/registrations/account.html +++ b/views/admin/registrations/account.html @@ -9,6 +9,7 @@ +

@@ -21,7 +22,7 @@

Total found: {$numAccounts}  

- {if $paging} + {if $paging && $numAccounts} {/if} @@ -57,7 +58,7 @@ {/if} - {if $paging} + {if $paging && $numAccounts} {/if}