From 1edeb7cf65226a4632da00e1a0cd7e54def58a4c Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Thu, 13 Sep 2018 17:19:34 -0400 Subject: [PATCH] Add pagination and alpha keys to model/view --- classes/data/dataStaff.php | 32 ++++++ css/front.css | 10 +- models/front/staff/list.php | 200 +++++++++++++++++++++++++++++++++++- setup/shortcodes.php | 15 ++- views/front/staff/list.html | 90 +++++++++++----- 5 files changed, 307 insertions(+), 40 deletions(-) diff --git a/classes/data/dataStaff.php b/classes/data/dataStaff.php index 9510dde..5f26ad6 100644 --- a/classes/data/dataStaff.php +++ b/classes/data/dataStaff.php @@ -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; + } /** diff --git a/css/front.css b/css/front.css index 3634265..ac0a0a9 100644 --- a/css/front.css +++ b/css/front.css @@ -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; @@ -23,9 +20,14 @@ .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 diff --git a/models/front/staff/list.php b/models/front/staff/list.php index 1db55bc..96449b0 100644 --- a/models/front/staff/list.php +++ b/models/front/staff/list.php @@ -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 diff --git a/setup/shortcodes.php b/setup/shortcodes.php index 7721cd1..2648b80 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -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 = ' +ShortcodeAttributeDescription + + [glm-members-staff-list] +   + + Displays a list of staff members. + + -$glmMembersStaffShortcodesDescription = ''; +'; diff --git a/views/front/staff/list.html b/views/front/staff/list.html index d960445..8ad2fc0 100644 --- a/views/front/staff/list.html +++ b/views/front/staff/list.html @@ -1,37 +1,71 @@
{if $staffData} - - {foreach $staffData as $staffKey => $staffVal} -
-
-
- - {$staffVal.fname} - - - {$staffVal.lname} - -
- -
- - {$staffVal.extension} - - - {$staffVal.building} - - - {$staffVal.department} - -
+ - - Email +
+ {if $paging} + {if $prevStart || $nextStart} +
+ +
+ {/if} +
+ showing {$start} through {$lastDisplayed} of {$filteredMembersFound} + {/if} +
+ + {foreach $staffData as $staffKey => $staffVal} +
+
+
+ + {$staffVal.fname} + + + {$staffVal.lname} + +
+ +
+ + {$staffVal.extension} + + + {$staffVal.building} + + + {$staffVal.department}
+ + + Email +
- {/foreach} -
+
+ {/foreach} + {if $paging} +
+ {if $prevStart || $nextStart} +
+ +
+ {/if} +
+ showing {$start} through {$lastDisplayed} of {$filteredMembersFound} +
+ {/if} {else} Sorry, no staff members found. {/if} -- 2.17.1