Add pagination and alpha keys to model/view
authorLaury GvR <laury@gaslightmedia.com>
Thu, 13 Sep 2018 21:19:34 +0000 (17:19 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Thu, 13 Sep 2018 21:19:34 +0000 (17:19 -0400)
classes/data/dataStaff.php
css/front.css
models/front/staff/list.php
setup/shortcodes.php
views/front/staff/list.html

index 9510dde..5f26ad6 100644 (file)
@@ -180,6 +180,38 @@ class GlmDataStaff extends GlmDataAbstract
 
          );
 
+    }
+
+     /*
+     * Get Alpha list of first characters in member name
+     * for those members that have active info.
+     *
+     * @param string $where Where clause
+     *     Note the table refernces M and I.
+     * @param string $selected Optional selected alpha character
+     *
+     * @return object Class object
+     *
+     */
+    public function getAlphaList($where = '', $selected = '')
+    {
+
+        $sql = "
+           SELECT DISTINCT LEFT(T.fname, 1) AS alpha
+             FROM ".GLM_MEMBERS_STAFF_PLUGIN_DB_PREFIX. "staff T
+            WHERE true
+                  $where
+            ORDER BY alpha
+        ;";
+        $alphaData = $this->wpdb->get_results($sql, ARRAY_A);
+
+        // Set selected
+        foreach ($alphaData as $k=>$v) {
+            $alphaData[$k]['default'] = ($v['alpha'] == $selected);
+        }
+
+        return $alphaData;
+
     }
 
     /**
index 3634265..ac0a0a9 100644 (file)
@@ -3,9 +3,6 @@
     padding: 10px;
     width: 33%;
 }
-.glm-staff-name {
-    font-weight: bold;
-}
 @media (min-width: 641px) and (max-width: 1024px) {
     .glm-staff-block-wrapper {
         float: left;
 .glm-staff-block {
     /* border: 1px solid grey; */
     /* box-shadow: 1px 1px 1px 1px grey; */
+    margin-bottom: 20px;
     text-align: center;
     width: 100%;
 }
+.glm-staff-name {
+    font-weight: bold;
+}
+
 
 /* Email Modal Styles */
 .required-field{
@@ -41,4 +43,4 @@
 .modal-form-wrapper{
     max-width: 700px;
     display: none;
-}
+}
\ No newline at end of file
index 1db55bc..96449b0 100644 (file)
@@ -107,13 +107,177 @@ class GlmMembersFront_staff_list extends GlmDatastaff
         $success_message = "";
         $option = false;
         $view_file = 'list';
+        $view = 'list';
+
+        $where                = '';
+        $whereSep             = '';
+        $filterPending        = false;
+        $filterArchived       = false;
+        $filterFeatured       = false;
+        $filterName           = false;
+        $haveFilter           = false;
+        $textSearch           = '';
+        $blankStart           = false;
+        $citySearchSelect     = false;
+        $membersFound         = false;
+        $catSearchSelected    = false;
+        $regionSearchSelected = false;
+        $mapItems             = false;
+        $multiSelectCats      = false;
+        $filteredStaffFound = false;
+        $list                 = false;
+        $citySearchSelected   = false;
+
+        // Paging Parameters
+        $textSearch    = '';
+        $paging        = true;//$this->config['settings']['list_pagination']; // Now this is in management
+        $numbDisplayed = false;
+        $lastDisplayed = false;
+        $prevStart     = false;
+        $nextStart     = false;
+        $start         = 1;
+        $limit         = 15;//$this->config['settings']['list_pagination_count']; // Now this is in management
         
         if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') {
             $option = $_REQUEST['option'];
         }
 
-        $staff_data = $this->getList();
-   
+        if (isset($_REQUEST['textSearch'])) {
+            $actionData['request']['text-search'] = $_REQUEST['textSearch'];
+        } else {
+            $actionData['request']['text-search'] = false;
+        }
+        
+        if (isset($_REQUEST['alpha'])) {
+            $actionData['request']['alpha'] = $_REQUEST['alpha'];
+        } else {
+            $actionData['request']['alpha'] = false;
+        }
+
+        // If user clicked a page request then we need to check the savedAlpha value
+        if (isset($_REQUEST['savedAlpha']) && isset($_REQUEST['pageSelect'])) {
+            $actionData['request']['alpha'] = $_REQUEST['savedAlpha'];
+        }
+
+        // Apply any provided text search to name, description, short description, and street address
+        if (trim($actionData['request']['text-search']) != '') {
+            $textSearch = addslashes(filter_var($actionData['request']['text-search'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
+            $where .= $whereSep." (
+                (
+                    SELECT true
+                      FROM ".GLM_MEMBERS_STAFF_PLUGIN_DB_PREFIX."staff
+                     WHERE id = T.id
+                       AND fname LIKE '%$textSearch%'
+                ) OR
+                T.lname LIKE '%$textSearch%' OR
+                T.department LIKE '%$textSearch%' OR
+                T.building LIKE '%$textSearch%'
+            )";
+            $whereSep = ' AND ';
+            $textSearch = stripslashes($textSearch);
+        }
+
+        // Check if we're doing paging
+        if (isset($_REQUEST['pageSelect'])) {
+
+            // If request is for Next
+            if ($_REQUEST['pageSelect'] == 'Next') {
+                $newStart = $_REQUEST['nextStart'] - 0;
+
+            // Otherwise it must be Previous
+            } else {
+                $newStart = $_REQUEST['prevStart'] - 0;
+            }
+
+            if ($newStart > 0) {
+                $start = $newStart;
+            }
+        }
+
+        $whereParts = apply_filters('glm-member-db-front-search-query', array());
+        if ( is_array( $whereParts ) && count( $whereParts ) > 0 ) {
+            $where .= $whereSep.implode(" AND ", $whereParts);
+            $whereSep = ' AND ';
+        }
+
+        // If doing alpha list
+        $alphaList = false;
+        $alphaWhere = '';
+        if ($this->config['settings']['list_show_search_alpha']) {
+
+            $alphaSelected = false;
+
+            // Check for alpha selected
+            if ($actionData['request']['alpha'] && strlen($actionData['request']['alpha']) == 1) {
+                $alphaSelected = strtoupper($actionData['request']['alpha']);
+                $alphaWhere .= " AND T.fname LIKE '$alphaSelected%'";
+                
+            }
+
+            // Get full list for all other filters, but not filtered by alpha (that would be silly)
+            $alphaList = $this->getAlphaList($where, $alphaSelected);
+            
+        }
+
+        // If we're not paging, then force $start and $limit to false to data abstract returns everything.
+        $resultParam = 'listResult';
+        if (!$paging) {
+            $start = false;
+            $limit = false;
+            $resultParam = 'list';
+        }
+        $where .= ' true ';
+        // Get stats for the current selection
+        $staffFound = $this->getStats(str_replace('T.', '', $where));
+
+        // Get stats for number of members found matching current selection criteria (includes alpha selection)
+        $filteredStaffFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere));
+
+        
+        $sortOrder = apply_filters( 'glm-member-db-front-search-query-orderby', 'fname' );
+        $sortOrder = 'fname';
+        ${$resultParam} = $this->getList($where.$alphaWhere, $sortOrder, true, 'id', $start, $limit);
+
+        if ($paging) {
+
+            // Get paging results - With paging getList() returns an array with additional paging data
+            $numbDisplayed = $listResult['returned'];
+            $lastDisplayed = $listResult['last'];
+            if ($start == 1) {
+                $prevStart = false;
+            } else {
+                $prevStart = $start - $limit;
+                if ($start < 1) {
+                    $start = 1;
+                }
+            }
+
+            if ($start + $limit <= $filteredStaffFound) {
+                $nextStart = $start + $limit;
+            }
+
+            // since we're doing paging, we have to break out just the member data
+            $list = $listResult['list'];
+            unset($listResult);
+
+        }
+
+        // If we have list entries - even if it's an empty list
+        $success = true;
+        $haveStaff = false;
+        if (!$blankStart && $list !== false) {
+
+            $success = true;
+
+            // If we have any entries
+            if (count($list) > 0) {
+                $haveStaff = true;
+            }
+        }
+
+
+        //$staff_data = $this->getList();
+           
         switch ($option) {
 
             case "list":
@@ -131,8 +295,36 @@ class GlmMembersFront_staff_list extends GlmDatastaff
         
         // Compile template data
         $templateData = array(
-            'staffData'    => $staff_data,
-            'successLoad'  => $success_load
+            'list'         => $list,
+            'staffData'    => $list,
+            'successLoad'  => $success_load,
+            'haveStaff'          => $haveStaff,
+            'staff'              => $list,
+            'staffFound'         => $staffFound,
+            'mapItems'             => $mapItems,
+            'haveFilter'           => $haveFilter,
+            'filterArchived'       => $filterArchived,
+            'filterFeatured'       => $filterFeatured,
+            'filterPending'        => $filterPending,
+            'filterName'           => stripslashes($filterName),
+            'textSearch'           => $textSearch,
+            'catSearchSelected'    => $catSearchSelected,
+            'citySearchSelected'   => $citySearchSelected,
+            'regionSearchSelected' => $regionSearchSelected,
+            'alphaList'            => $alphaList,
+            'alphaSelected'        => $alphaSelected,
+            'blankStart'           => $blankStart,
+            'view'                 => $view,
+
+            // Paging parameters
+            'filteredStaffFound' => $filteredStaffFound,
+            'numbDisplayed'        => $numbDisplayed,
+            'lastDisplayed'        => $lastDisplayed,
+            'paging'               => $paging,
+            'prevStart'            => $prevStart,
+            'nextStart'            => $nextStart,
+            'start'                => $start,
+            'limit'                => $limit,
         );
 
         // Return status, any suggested view, and any data to controller
index 7721cd1..2648b80 100644 (file)
@@ -88,7 +88,7 @@
  */
 
 
-$glmMembersEventsShortcodes = array(
+$glmMembersStaffShortcodes = array(
     'glm-members-staff-list' => array(
         'plugin'     => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
         'menu'       => 'staff',
@@ -99,8 +99,15 @@ $glmMembersEventsShortcodes = array(
     ),
 );
 
-$glmMembersStaffShortcodes = array(
-);
+$glmMembersStaffShortcodesDescription = '
+<tr><th>Shortcode</th><th>Attribute</th><th>Description</th></tr>
+<tr>
+    <th>[glm-members-staff-list]</th>
+    <td>&nbsp;</td>
+    <td width="50%">
+        Displays a list of staff members.
+    </td>
+</tr>
 
-$glmMembersStaffShortcodesDescription = '';
+';
 
index d960445..8ad2fc0 100644 (file)
@@ -1,37 +1,71 @@
 <div class="glm-staff-container">
     {if $staffData}
-            
-            {foreach $staffData as $staffKey => $staffVal}
-                <div class="glm-staff-block-wrapper">
-                    <div class="glm-staff-block">
-                        <div class="glm-staff-name">
-                            <span class="glm-staff-fname">
-                                {$staffVal.fname}
-                            </span>
-                            <span class="glm-staff-lname">
-                                {$staffVal.lname}
-                            </span>
-                        </div>
-                        
-                        <div class="glm-staff-location">
-                            <span class="glm-staff-extension">
-                                {$staffVal.extension}
-                            </span>
-                            <span class="glm-staff-building">
-                                {$staffVal.building}
-                            </span>
-                            <span class="glm-staff-department">
-                                {$staffVal.department}
-                            </span>
-                        </div>
+        <div class="glm-alpha-links">
+            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}#glm-member-list-filters-button" class="glm-alpha-link{if !$alphaSelected} glm-alpha-link-selected{/if}">All</a>
+            {foreach $alphaList as $a}
+                <a href="{$thisUrl}?glm_action=list&alpha={$a.alpha}&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}#glm-member-list-filters-button" class="glm-alpha-link{if $a.default} glm-alpha-link-selected{/if}">{$a.alpha}</a>
+            {/foreach}
+        </div>
 
-                        <span class="glm-staff-email">
-                            <a data-id="{$staffVal.id}" href="#" data-reveal-id="emailModal">Email</a>
+        <div class="paging-container">
+            {if $paging}
+                {if $prevStart || $nextStart}
+                    <br>
+                    <div class="paging-container">
+                        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}#glm-member-list-filters-button" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>< Previous page</a>
+                        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}#glm-member-list-filters-button" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page ></a>
+                    </div>
+                    <br>
+                {/if}
+                <br>
+                showing {$start} through {$lastDisplayed} of {$filteredMembersFound}
+            {/if}
+        </div>
+        
+        {foreach $staffData as $staffKey => $staffVal}
+            <div class="glm-staff-block-wrapper">
+                <div class="glm-staff-block">
+                    <div class="glm-staff-name">
+                        <span class="glm-staff-fname">
+                            {$staffVal.fname}
+                        </span>
+                        <span class="glm-staff-lname">
+                            {$staffVal.lname}
+                        </span>
+                    </div>
+                    
+                    <div class="glm-staff-location">
+                        <span class="glm-staff-extension">
+                            {$staffVal.extension}
+                        </span>
+                        <span class="glm-staff-building">
+                            {$staffVal.building}
+                        </span>
+                        <span class="glm-staff-department">
+                            {$staffVal.department}
                         </span>
                     </div>
+
+                    <span class="glm-staff-email">
+                        <a data-id="{$staffVal.id}" href="#" data-reveal-id="emailModal">Email</a>
+                    </span>
                 </div>
-            {/foreach}
-        </div>
+            </div>
+        {/foreach}
+        {if $paging}
+            <div class="paging-container"></div>
+                {if $prevStart || $nextStart}
+                    <br>
+                    <div class="paging-container">
+                        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>< Previous page</a>
+                        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page ></a>
+                    </div>
+                    <br>
+                {/if}
+                <br>
+                showing {$start} through {$lastDisplayed} of {$filteredMembersFound}
+            </div>
+        {/if}
     {else}
         Sorry, no staff members found.
     {/if}