Adding Paging
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 25 May 2018 20:51:16 +0000 (16:51 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 25 May 2018 20:51:16 +0000 (16:51 -0400)
Need to work on the search paramaters and passing them to edit page.

models/admin/travel/index.php
views/admin/travel/index.html

index 4a9daf3..53054ce 100644 (file)
@@ -109,6 +109,7 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
         $entry               = false;
         $hasSearch           = false;
         $tab                 = 0;
+        $params              = false;
 
         // Get any provided option
         if ( isset( $_REQUEST['option'] ) ) {
@@ -262,8 +263,46 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
                 }
                 $order = "T.lname, T.fname";
             }
+                // 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;
+                    }
+                }
+            // $entry = $this->getList( $where );
+            $orderBy = 'T.company ASC,T.lname ASC,T.fname ASC,T.updated DESC';
+            $entryResults = $this->getList( $where, $orderBy, true, 'id', $start, $limit );
+
+            // Get paging results
+            $numbDisplayed = $entryResults['returned'];
+            $leadCount     = $numbDisplayed;
+            $lastDisplayed = $entryResults['last'];
+            if ( $start == 1 ) {
+                $prevStart = false;
+            } else {
+                $prevStart = $start - $limit;
+                if ( $start < 1 ) {
+                    $start = 1;
+                }
+            }
+            if ( $entryResults['returned'] == $limit ) {
+                $nextStart = $start + $limit;
+            }
+            $entry = $entryResults['list'];
+            if ( count( $entry ) > 0 ) {
+                $haveLeads = true;
+            }
 
-            $entry = $this->getList( $where );
+            $leadCount = count( $entry );
 
             $view = 'index.html';
 
@@ -277,6 +316,7 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
         // Common things to place into the $templateData array
         $templateData = array(
             'hasSearch'       => $hasSearch,
+            'params'          => $params,
             'lead'            => $entry,
             'haveLeads'       => $haveLeads,
             'leadCount'       => $leadCount,
index aedc873..3a96c1b 100644 (file)
@@ -3,6 +3,19 @@
 {include file='admin/travel/searchForm.html'}
 
 {if $lead}
+    <form action="{$thisUrl}">
+        <input type="hidden" name="page" value="{$thisPage}" />
+        <input type="hidden" name="glm_action" value="index" />
+        <input type="hidden" name="prevStart" value="{$prevStart}">
+        <input type="hidden" name="nextStart" value="{$nextStart}">
+        <input type="hidden" name="limit" value="{$limit}">
+    <br clear="all">
+    <p><b>Total found:</b> {$leadCount}&nbsp;&nbsp;</p>
+    {if $paging}
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Leads" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Leads" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+    {/if}
+
     <table id="dataGrid" class="dataGrid">
         <thead>
             <tr>
@@ -16,8 +29,8 @@
         </thead>
         <tbody>
             {foreach $lead as $e}
-            <tr class="{if $c@iteration is div by 2}even{else}odd{/if}">
-                <td> <a class="company_link" href="{$thisUrl}?page={$thisPage}&glm_action=index&option=edit&id={$e.id}">Edit</a></td>
+            <tr class="{if $e@iteration is div by 2}even{else}odd{/if}">
+                <td> <a class="company_link" href="{$thisUrl}?page={$thisPage}&glm_action=index&option=edit&id={$e.id}&{$params}">Edit</a></td>
                 <td> {$e.company} </td>
                 <td> {$e.fname} </td>
                 <td> {$e.lname} </td>
             {/foreach}
         </tbody>
     </table>
+
+        {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}
+    </form>
 {else}
     No search results!
 {/if}